Пример #1
0
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
{
	if(type == "SoundEmitter") {
		ALuint source = CreateSource();
		m_Sources[component.get()] = source;
	}
}
Пример #2
0
void CSound::Play()
{
	if ( m_iSource == 0 )
		CreateSource();
    ALenum state;
    alGetSourcei(m_iSource, AL_SOURCE_STATE, &state);

	if ( !(state == AL_PLAYING) )
		alSourcePlay( m_iSource );
}
Пример #3
0
iAudioSource* clAudioSubSystem_OpenAL::CreateSourceFromFile( const LString& FileName ) const
{
	iAudioSource* Source = CreateSource();

#if L_AUDIO_USE_OPENAL
	Source->BindWaveform( Env->Resources->LoadWaveform( FileName ) );
#endif

	return Source;
}
Пример #4
0
void CreateDefaultNotify() {
	if (alIsSource(DefaultNotify.source)) {
		return;
	}

	DefaultNotify.source = CreateSource();
	DefaultNotify.buffer = CreateBuffer();

	alBufferData(DefaultNotify.buffer, DefaultNotify.alFormat, DefaultNotify.data.constData(), DefaultNotify.data.size(), DefaultNotify.sampleRate);
	alSourcei(DefaultNotify.source, AL_BUFFER, DefaultNotify.buffer);
}
Пример #5
0
HRESULT CTedMediaFileRenderer::CreatePartialTopology(IMFTopology** ppPartialTopology)
{
    HRESULT hr;
    IMFTopology* pPartialTopology;
    CComPtr<IMFMediaSource> spSource;
    
    IFC( MFCreateTopology(&pPartialTopology) );
    
    IFC( CreateSource(&spSource) );
    IFC( BuildTopologyFromSource(pPartialTopology, spSource) );
    
    *ppPartialTopology = pPartialTopology;
    
Cleanup:
    return hr;
}
Пример #6
0
/*! Call this to unload a sound object from memory
 *
 *  @param          szFile          The file to unload
 *  @returns        ICRESULT        Success/failure of unloading the resource
**/
ICRESULT icSoundDeviceAL::LoadSource(const char* szFile)
{
    icSoundBuffer pBuf;

    if (ICEFAIL(CreateSource(szFile, pBuf)))
        return IC_FAIL_GEN;

    ALenum err = AL_NO_ERROR;

    err = alGetError();

    ALenum al_format;

    switch (pBuf.format)
    {
    case ICSND_FMT_WAV_MONO16: al_format = AL_FORMAT_MONO16; break;
    case ICSND_FMT_WAV_STEREO16: al_format = AL_FORMAT_STEREO16; break;
    case ICSND_FMT_WAV_MONO8: al_format = AL_FORMAT_MONO8; break;
    case ICSND_FMT_WAV_STEREO8: al_format = AL_FORMAT_STEREO8; break;
    default: return IC_FAIL_GEN;
    }


    ALsizei al_freq = (ALsizei)pBuf.freq;
    ALsizei al_size = (ALsizei)pBuf.size;


    //put the data into an openAL buffer
    alBufferData(pBuf.buffID, al_format, pBuf.data, al_size, al_freq);

    err = alGetError();
    if (err != AL_NO_ERROR)
        return IC_FAIL_GEN;

    return IC_OK;
}// END FUNCTION LoadSource(const char* szFile)
Пример #7
0
 void SoundChannel::QueueBuffers()
 {
     // See that we do have waiting sounds and they're ready to play
     if (!pending_sounds_.size())
         return;
     if ((*pending_sounds_.begin())->GetHandle() == 0)
         return;
     
     // Create source now if did not exist already
     if (!CreateSource())
     {
         state_ = Foundation::SoundServiceInterface::Stopped;
         pending_sounds_.clear();
         return;
     }
     
     bool queued = false;
     
     // Buffer pending sounds, move them to playing vector
     while (pending_sounds_.size())
     {
         SoundPtr sound = *pending_sounds_.begin();
         ALuint buffer = sound->GetHandle();
         // If no valid handle yet, cannot play this one, break out
         if (!buffer)
             return;
         
         alGetError();
         alSourceQueueBuffers(handle_, 1, &buffer);
         ALenum error = alGetError();
         
         if (error != AL_NONE)
         {
             // If queuing fails, we may have changed sound format. Stop, flush queue & retry
             alSourceStop(handle_);
             alSourcei(handle_, AL_BUFFER, 0);
             alSourceQueueBuffers(handle_, 1, &buffer);
             ALenum error = alGetError();
             if (error != AL_NONE)
                 OpenALAudioModule::LogError("Could not queue OpenAL sound buffer: " + ToString<int>(error));
             else
             {
                 playing_sounds_.push_back(sound);
                 queued = true;
             }
         }
         else
         {
             playing_sounds_.push_back(sound);
             queued = true;
         }
         
         pending_sounds_.pop_front();
     }
     
     // If at least one sound queued, start playback if not already playing
     if (queued)
     {
         ALint playing;
         alGetSourcei(handle_, AL_SOURCE_STATE, &playing);
         if (playing != AL_PLAYING)
             alSourcePlay(handle_);
         state_ = Foundation::SoundServiceInterface::Playing;
     }
 }
Пример #8
0
/**
 * @brief Initialize a module for reading fixed file
 *
 * Process flow
 *	 -# Acquire a list of valid column numbers
 *	 -# Compute a record length
 *	 -# Allocate ((record length) * READ_LINE_NUM + 1) bytes for record buffer
 * @param rd [in] Control information
 * @return void
 * @note Return to caller by ereport() if the number of fields in the table
 * definition is not correspond to the number of fields in input file.
 * @note Caller must release the resource by calling BinaryParserTerm() after calling this
 * function.
 */
static void
BinaryParserInit(BinaryParser *self, Checker *checker, const char *infile, TupleDesc desc, bool multi_process, Oid collation)
{
	int					i;
	size_t				maxlen;
	TupleCheckStatus	status;

	/*
	 * set default values
	 */
	self->need_offset = self->offset = self->offset > 0 ? self->offset : 0;

	/*
	 * checking necessary setting items for fixed length file
	 */
	if (self->nfield == 0)
		ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
						errmsg("no COL specified")));

	self->source = CreateSource(infile, desc, multi_process);

	status = FilterInit(&self->filter, desc, collation);
	if (checker->tchecker)
		checker->tchecker->status = status;

	TupleFormerInit(&self->former, &self->filter, desc);

	/*
	 * Error if the number of input data fields is out of range to the number of
	 * fields
	 */
	if (self->former.minfields > self->nfield ||
		self->former.maxfields < self->nfield)
		ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
						errmsg("invalid field count (%d)", self->nfield)));

	/* set function default value */
	for (i = self->nfield; i < self->former.maxfields; i++)
	{
		int		index;

		index = i - self->former.minfields;
		self->former.isnull[i] = self->filter.defaultIsnull[index];
		self->former.values[i] = self->filter.defaultValues[index];
	}

	/*
	 * Acquire record buffer as much as input file record length
	 */
	maxlen = 0;
	for (i = 0; i < self->nfield; i++)
	{
		int		len = self->fields[i].offset + self->fields[i].len;
		maxlen = Max(maxlen, len);
	}
	if (self->rec_len <= 0)
		self->rec_len = maxlen;
	else if (self->rec_len < maxlen)
		ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
			errmsg("STRIDE should be %ld or greater (%ld given)",
				(long) maxlen, (long) self->rec_len)));
	self->buffer = palloc(self->rec_len * READ_LINE_NUM + 1);
}
Пример #9
0
void SoundChannel::QueueBuffers()
{
    // See that we do have waiting sounds and they're ready to play
    AudioAssetPtr pending = pending_sounds_.size() > 0 ? pending_sounds_.front() : AudioAssetPtr();

    if (!pending)
        return;
    
    // Create source now if did not exist already
    if (!CreateSource())
    {
        state_ = Stopped;
        pending_sounds_.clear();
        return;
    }
    
    bool queued = false;
    
    // Buffer pending sounds, move them to playing vector
    while(pending_sounds_.size() > 0)
    {
        AudioAssetPtr sound = pending_sounds_.front();
        if (!sound)
        {
            pending_sounds_.pop_front();
            continue;
        }
        ALuint buffer = sound->GetHandle();
        // If no valid handle yet, cannot play this one, break out
        if (!buffer)
            return;
        
        alGetError();
        alSourceQueueBuffers(handle_, 1, &buffer);
        ALenum error = alGetError();
        
        if (error != AL_NONE)
        {
            // If queuing fails, we may have changed sound format. Stop, flush queue & retry
            alSourceStop(handle_);
            alSourcei(handle_, AL_BUFFER, 0);
            alSourceQueueBuffers(handle_, 1, &buffer);
            ALenum error = alGetError();
            if (error != AL_NONE)
                LogError("Could not queue OpenAL sound buffer: " + QString::number(error));
            else
            {
                playing_sounds_.push_back(sound);
                queued = true;
            }
        }
        else
        {
            playing_sounds_.push_back(sound);
            queued = true;
        }
        
        pending_sounds_.pop_front();
    }
    
    // If at least one sound queued, start playback if not already playing
    if (queued)
    {
        ALint playing;
        alGetSourcei(handle_, AL_SOURCE_STATE, &playing);
        if (playing != AL_PLAYING)
            alSourcePlay(handle_);
        state_ = Playing;
    }
}