コード例 #1
0
ファイル: SimpleAudioEngine.cpp プロジェクト: Prios/panda2
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		// Changing file path to full path
    	std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);

		EffectsMap::iterator iter = s_effects.find(fullPath);

		if (iter == s_effects.end())
		{
			preloadEffect(fullPath.c_str());

			// let's try again
			iter = s_effects.find(fullPath);
			if (iter == s_effects.end())
			{
				fprintf(stderr, "could not find play sound %s\n", fullPath.c_str());
				return -1;
			}
		}

		checkALError("playEffect");
		iter->second->isLooped = bLoop;
		alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
		alSourcePlay(iter->second->source);
		checkALError("playEffect");

		return iter->second->source;
	}
コード例 #2
0
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		EffectsMap::iterator iter = s_effects.find(pszFilePath);

		if (iter == s_effects.end())
		{
			preloadEffect(pszFilePath);

			// let's try again
			iter = s_effects.find(pszFilePath);
			if (iter == s_effects.end())
			{
				fprintf(stderr, "could not find play sound %s\n", pszFilePath);
				return -1;
			}
		}

		checkALError("playEffect");
		iter->second->isLooped = bLoop;
		alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
		alSourcePlay(iter->second->source);
		checkALError("playEffect");

		return iter->second->source;
	}
コード例 #3
0
static void stopBackground(bool bReleaseData)
{
    // The background music might have been already stopped
    // Stop request can come from
    //   - stopBackgroundMusic(..)
    //   - end(..)
    if (s_backgroundSource != AL_NONE)
        alSourceStop(s_backgroundSource);

    if (bReleaseData)
    {
        for (auto it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
        {
            if (it->second->source == s_backgroundSource)
            {
                alDeleteSources(1, &it->second->source);
                checkALError("stopBackground:alDeleteSources");
                alDeleteBuffers(1, &it->second->buffer);
                checkALError("stopBackground:alDeleteBuffers");
                delete it->second;
                s_backgroundMusics.erase(it);
                break;
            }
        }
    }

    s_backgroundSource = AL_NONE;
}
コード例 #4
0
void LLAudioEngine_OpenAL::initWind()
{

	if (true)
		return;

	llinfos << "initWind() start" << llendl;

	alGenBuffers(mNumWindBuffers,mWindBuffers);
	alGenSources(1,&mWindSource);
	checkALError();

	// ok lets make a wind buffer now
	for(int counter=0;counter<mNumWindBuffers;counter++)
	{

		alBufferData(mWindBuffers[counter],AL_FORMAT_STEREO16,windDSP((void*)mWindData,mWindDataSize/mBytesPerSample),mWindDataSize,mSampleRate);
		checkALError();
	}

	alSourceQueueBuffers(mWindSource, mNumWindBuffers, mWindBuffers);
	checkALError();

	alSourcePlay(mWindSource);
	checkALError();

	llinfos << "LLAudioEngine_OpenAL::initWind() done" << llendl;

}
コード例 #5
0
ファイル: libOpenAl.cpp プロジェクト: xuyunhan/Dancing
OPAL_SOUND_MGR bool SoundManager::setSoundPosition( unsigned int audioID, Vector3 position,
												   Vector3 velocity, Vector3 direction )
{
	if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[ audioID ] )
		return false;

	// Set the position
	ALfloat pos[] = { position.x, position.y, position.z };

	alSourcefv( mAudioSources[ audioID ], AL_POSITION, pos );

	if ( checkALError( "setSound::alSourcefv:AL_POSITION" ) )
		return false;

	// Set the veclocity
	ALfloat vel[] = { velocity.x, velocity.y, velocity.z };

	alSourcefv( mAudioSources[ audioID ], AL_VELOCITY, vel );

	if ( checkALError( "setSound::alSourcefv:AL_VELOCITY" ) )
		return false;

	// Set the direction
	ALfloat dir[] = { velocity.x, velocity.y, velocity.z };

	alSourcefv( mAudioSources[ audioID ], AL_DIRECTION, dir );

	if ( checkALError( "setSound::alSourcefv:AL_DIRECTION" ) )
		return false;

	return true;
}
コード例 #6
0
void SimpleAudioEngine::stopAllEffects()
{
    EffectsMap::iterator iter = s_effects.begin();

    if (iter != s_effects.end())
    {
        checkALError("stopAllEffects:init");
        alSourceStop(iter->second->source);
        checkALError("stopAllEffects:alSourceStop");
    }
}
コード例 #7
0
	void SimpleAudioEngine::resumeAllEffects()
	{
		EffectsMap::iterator iter = s_effects.begin();

		if (iter != s_effects.end())
	    {
			checkALError("resumeAllEffects");
			alSourcePlay(iter->second->source);
			checkALError("resumeAllEffects");
	    }
	}
コード例 #8
0
ファイル: SimpleAudioEngine.cpp プロジェクト: Prios/panda2
	void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
	{
		// Changing file path to full path
    	std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);

		EffectsMap::iterator iter = s_effects.find(fullPath);

		// check if we have this already
		if (iter == s_effects.end())
		{
			ALuint 		buffer;
			ALuint 		source;
			soundData  *data = new soundData;
			string 	    path = fullPath;

			checkALError("preloadEffect");

			if (isOGGFile(path.data()))
			{
				buffer = createBufferFromOGG(path.data());
			}
			else
			{
				buffer = alutCreateBufferFromFile(path.data());
				checkALError("preloadEffect");
			}

			if (buffer == AL_NONE)
			{
				fprintf(stderr, "Error loading file: '%s'\n", path.data());
				alDeleteBuffers(1, &buffer);
				return;
			}

			alGenSources(1, &source);

			if (checkALError("preloadEffect") != AL_NO_ERROR)
			{
				alDeleteBuffers(1, &buffer);
				return;
			}

			alSourcei(source, AL_BUFFER, buffer);
			checkALError("preloadEffect");

			data->isLooped = false;
			data->buffer = buffer;
			data->source = source;

			s_effects.insert(EffectsMap::value_type(fullPath, data));
		}
	}
コード例 #9
0
void SimpleAudioEngine::preloadEffect(const char* pszFilePath)
{
    // Changing file path to full path
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);

    EffectsMap::iterator iter = s_effects.find(fullPath);

    // check if we have this already
    if (iter == s_effects.end())
    {
        ALuint      buffer = AL_NONE;
        ALuint      source = AL_NONE;
        

        checkALError("preloadEffect:init");
        OpenALFile file;
        file.debugName = pszFilePath;
        file.file = fopen(fullPath.c_str(), "rb");
        if (!file.file) {
            fprintf(stderr, "Cannot read file: '%s'\n", fullPath.data());
            return;
        }
        
        bool success = false;
        const std::vector<OpenALDecoder *> &decoders = OpenALDecoder::getDecoders();
        for (size_t i = 0, n = decoders.size(); !success && i < n; ++i)
            success = decoders[i]->decode(file, buffer);
        file.clear();

        alGenSources(1, &source);

        if (checkALError("preloadEffect:alGenSources") != AL_NO_ERROR)
        {
            alDeleteBuffers(1, &buffer);
            return;
        }

        alSourcei(source, AL_BUFFER, buffer);
        checkALError("preloadEffect:alSourcei");
        
        soundData  *data = new soundData;
        data->isLooped = false;
        data->buffer = buffer;
        data->source = source;
        data->pitch = 1.0;
        data->pan = 0.0;
        data->gain = 1.0;

        s_effects.insert(EffectsMap::value_type(fullPath, data));
    }
}
コード例 #10
0
    static void stopBackground(bool bReleaseData)
    {
    	alSourceStop(s_backgroundSource);

		if (bReleaseData)
		{
			s_currentBackgroundStr = "";
			s_isBackgroundInitialized = false;

			alDeleteBuffers(1, &s_backgroundBuffer);
			checkALError("stopBackground");
			alDeleteSources(1, &s_backgroundSource);
			checkALError("stopBackground");
		}
    }
コード例 #11
0
ファイル: libOpenAl.cpp プロジェクト: xuyunhan/Dancing
OPAL_SOUND_MGR bool SoundManager::setSound( unsigned int audioID, Vector3 position,
										   Vector3 velocity, Vector3 direction, float maxDistance,
										   bool playNow, bool forceRestart, float minGain )
{
	if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[ audioID ] )
		return false;

	// Set the position
	ALfloat pos[] = { position.x, position.y, position.z };

	alSourcefv( mAudioSources[ audioID ], AL_POSITION, pos );

	if ( checkALError( "setSound::alSourcefv:AL_POSITION" ) )
		return false;

	// Set the veclocity
	ALfloat vel[] = { velocity.x, velocity.y, velocity.z };

	alSourcefv( mAudioSources[ audioID ], AL_VELOCITY, vel );

	if ( checkALError( "setSound::alSourcefv:AL_VELOCITY" ) )
		return false;

	// Set the direction
	ALfloat dir[] = { velocity.x, velocity.y, velocity.z };

	alSourcefv( mAudioSources[ audioID ], AL_DIRECTION, dir );

	if ( checkALError( "setSound::alSourcefv:AL_DIRECTION" ) )
		return false;

	// Set the max audible distance
	alSourcef( mAudioSources[ audioID ], AL_MAX_DISTANCE, maxDistance );

	// Set the MIN_GAIN ( IMPORTANT - if not set, nothing audible! )
	alSourcef( mAudioSources[ audioID ], AL_MIN_GAIN, minGain );

	// Set the max gain
	alSourcef( mAudioSources[ audioID ], AL_MAX_GAIN, 1.0f ); // TODO as parameter ? global ?

	// Set the rollof factor
	alSourcef( mAudioSources[ audioID ], AL_ROLLOFF_FACTOR, 1.0f ); // TODO as parameter ?

	// Do we play the sound now ?
	if ( playNow ) return playAudio( audioID, forceRestart ); // TODO bof... not in this fct

	return true;
}
コード例 #12
0
static gboolean
gst_openal_sink_unprepare (GstAudioSink * asink)
{
    GstOpenALSink *openal = GST_OPENAL_SINK (asink);
    ALCcontext *old;

    if (!openal->context)
        return TRUE;

    old = pushContext (openal->context);

    alSourceStop (openal->sID);
    alSourcei (openal->sID, AL_BUFFER, 0);

    if (!openal->custom_sID)
        alDeleteSources (1, &openal->sID);
    openal->sID = 0;

    alDeleteBuffers (openal->bID_count, openal->bIDs);
    g_free (openal->bIDs);
    openal->bIDs = NULL;
    openal->bID_idx = 0;
    openal->bID_count = 0;
    openal->bID_length = 0;

    checkALError ();
    popContext (old, openal->context);
    if (!openal->custom_ctx)
        alcDestroyContext (openal->context);
    openal->context = NULL;

    return TRUE;
}
コード例 #13
0
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
    // If there is already a background music source we stop it first
    if (s_backgroundSource != AL_NONE)
        stopBackgroundMusic(false);

    // Changing file path to full path
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);

    BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
    if (it == s_backgroundMusics.end())
    {
        preloadBackgroundMusic(fullPath.c_str());
        it = s_backgroundMusics.find(fullPath);
    }

    if (it != s_backgroundMusics.end())
    {
        s_backgroundSource = it->second->source;
        alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
        setBackgroundVolume(s_volume);
        alSourcePlay(s_backgroundSource);
        checkALError("playBackgroundMusic:alSourcePlay");
    }
}
コード例 #14
0
ファイル: libOpenAl.cpp プロジェクト: xuyunhan/Dancing
OPAL_SOUND_MGR bool SoundManager::resumeAllAudio( void )
{
	if ( mAudioSourcesInUseCount >= MAX_AUDIO_SOURCES )
		return false;

	alGetError();

	int sourceAudioState = 0;

	for ( int i=0; i<mAudioSourcesInUseCount; i++ )
	{
		// Are we currently playing the audio source?
		alGetSourcei( mAudioSources[i], AL_SOURCE_STATE, &sourceAudioState );

		if ( sourceAudioState == AL_PAUSED )
		{
			resumeAudio( i );
		}
	}

	if ( checkALError( "resumeAllAudio::alSourceStop ") )
		return false;

	return true;
}
コード例 #15
0
ファイル: libOpenAl.cpp プロジェクト: xuyunhan/Dancing
OPAL_SOUND_MGR bool SoundManager::playAudio( unsigned int audioID, bool forceRestart )
{ 
	// Make sure the audio source ident is valid and usable
	if ( audioID >= MAX_AUDIO_SOURCES || !mAudioSourceInUse[audioID])
		return false;

	int sourceAudioState = 0;

	alGetError();

	// Are we currently playing the audio source?
	alGetSourcei( mAudioSources[audioID], AL_SOURCE_STATE, &sourceAudioState );

	if ( sourceAudioState == AL_PLAYING )
	{
		if ( forceRestart )
			stopAudio( audioID );
		else
			return false; // Not forced, so we don't do anything
	}

	alSourcePlay( mAudioSources[ audioID ] );
	if ( checkALError( "playAudio::alSourcePlay: ") )
		return false;

	return true;
}
コード例 #16
0
static guint
gst_openal_sink_delay (GstAudioSink * asink)
{
    GstOpenALSink *openal = GST_OPENAL_SINK (asink);
    ALint queued, state, offset, delay;
    ALCcontext *old;

    if (!openal->context)
        return 0;

    GST_OPENAL_SINK_LOCK (openal);
    old = pushContext (openal->context);

    delay = 0;
    alGetSourcei (openal->sID, AL_BUFFERS_QUEUED, &queued);
    /* Order here is important. If the offset is queried after the state and an
     * underrun occurs in between the two calls, it can end up with a 0 offset
     * in a playing state, incorrectly reporting a len*queued/bps delay. */
    alGetSourcei (openal->sID, AL_BYTE_OFFSET, &offset);
    alGetSourcei (openal->sID, AL_SOURCE_STATE, &state);

    /* Note: state=stopped is an underrun, meaning all buffers are processed
     * and there's no delay when writing the next buffer. Pre-buffering is
     * state=initial, which will introduce a delay while writing. */
    if (checkALError () == AL_NO_ERROR && state != AL_STOPPED)
        delay = ((queued * openal->bID_length) - offset) / openal->bytes_per_sample;

    popContext (old, openal->context);
    GST_OPENAL_SINK_UNLOCK (openal);

    return delay;
}
コード例 #17
0
static gboolean
gst_openal_sink_unprepare (GstAudioSink * audiosink)
{
  GstOpenALSink *sink = GST_OPENAL_SINK (audiosink);
  ALCcontext *old;

  if (!sink->default_context)
    return TRUE;

  old = pushContext (sink->default_context);

  alSourceStop (sink->default_source);
  alSourcei (sink->default_source, AL_BUFFER, 0);

  if (!sink->user_source)
    alDeleteSources (1, &sink->default_source);
  sink->default_source = 0;

  alDeleteBuffers (sink->buffer_count, sink->buffers);
  g_free (sink->buffers);
  sink->buffers = NULL;
  sink->buffer_idx = 0;
  sink->buffer_count = 0;
  sink->buffer_length = 0;

  checkALError ();
  popContext (old, sink->default_context);
  if (!sink->user_context)
    alcDestroyContext (sink->default_context);
  sink->default_context = NULL;

  return TRUE;
}
コード例 #18
0
ファイル: SimpleAudioEngine.cpp プロジェクト: Prios/panda2
	void SimpleAudioEngine::pauseBackgroundMusic()
	{
		ALint state;
		alGetSourcei(s_backgroundSource, AL_SOURCE_STATE, &state);
		if (state == AL_PLAYING)
			alSourcePause(s_backgroundSource);
		checkALError("pauseBackgroundMusic");
	}
コード例 #19
0
ファイル: SimpleAudioEngine.cpp プロジェクト: Prios/panda2
	void SimpleAudioEngine::resumeBackgroundMusic()
	{
		ALint state;
		alGetSourcei(s_backgroundSource, AL_SOURCE_STATE, &state);
		if (state == AL_PAUSED)
			alSourcePlay(s_backgroundSource);
		checkALError("resumeBackgroundMusic");
	} 
コード例 #20
0
ファイル: OpenALCommon.cpp プロジェクト: selony/libdf3d
void checkAndPrintALError(const char *file, int line)
{
#ifdef _DEBUG
    auto err = checkALError();
    if (!err.empty())
        base::glog << "OpenAL error:" << err << ". File:" << file << ". Line:" << line << base::logwarn;
#endif
}
コード例 #21
0
void SimpleAudioEngine::pauseEffect(unsigned int nSoundId)
{
    ALint state;
    alGetSourcei(nSoundId, AL_SOURCE_STATE, &state);
    if (state == AL_PLAYING)
        alSourcePause(nSoundId);
    checkALError("pauseEffect:alSourcePause");
}
コード例 #22
0
void SimpleAudioEngine::resumeEffect(unsigned int nSoundId)
{
    ALint state;
    alGetSourcei(nSoundId, AL_SOURCE_STATE, &state);
    if (state == AL_PAUSED)
        alSourcePlay(nSoundId);
    checkALError("resumeEffect:alSourcePlay");
}
コード例 #23
0
	void SimpleAudioEngine::end()
	{
		checkALError("end");

		// clear all the sounds
	    EffectsMap::const_iterator end = s_effects.end();
	    for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
	    {
	        alSourceStop(it->second->source);
	        checkALError("end");
			alDeleteBuffers(1, &it->second->buffer);
			checkALError("end");
			alDeleteSources(1, &it->second->source);
			checkALError("end");
			delete it->second;
	    }
	    s_effects.clear();

		// and the background too
		stopBackground(true);

		for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
		{
			alSourceStop(it->second->source);
			checkALError("end");
			alDeleteBuffers(1, &it->second->buffer);
			checkALError("end");
			alDeleteSources(1, &it->second->source);
			checkALError("end");
			delete it->second;
		}
		s_backgroundMusics.clear();
	}
コード例 #24
0
ファイル: openal.c プロジェクト: DAOWAce/pcsxr
void RemoveSound()
{
    alSourceStop(source);
    checkALError();
    alDeleteSources(1, &source);
    checkALError();
    alDeleteBuffers(BUFFER_QUANTITY, buffers);
    checkALError();
    
    // Reset the current context to NULL.
    alcMakeContextCurrent(NULL);
    checkALCError();
    
    // RELEASE the context and the device.
    alcDestroyContext(pContext);
    checkALCError();
    alcCloseDevice(pDevice);
}
コード例 #25
0
	void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
	{
		if (!s_isBackgroundInitialized)
			preloadBackgroundMusic(pszFilePath);

		alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
		alSourcePlay(s_backgroundSource);
		checkALError("playBackgroundMusic");
	}
コード例 #26
0
SimpleAudioEngine::SimpleAudioEngine()
{
    alutInit(0, 0);
#ifdef ENABLE_MPG123
    mpg123_init();
#endif
    checkALError("SimpleAudioEngine:alutInit");
    OpenALDecoder::installDecoders();
}
コード例 #27
0
void LLAudioEngine_OpenAL::cleanupWind()
{
	llinfos << "LLAudioEngine_OpenAL::cleanupWind()" << llendl;

	alDeleteBuffers(mNumWindBuffers,mWindBuffers);
	alDeleteSources(1, &mWindSource);

	checkALError();
}
コード例 #28
0
	void SimpleAudioEngine::pauseAllEffects()
	{
		EffectsMap::iterator iter = s_effects.begin();

		if (iter != s_effects.end())
	    {
			alSourcePause(iter->second->source);
			checkALError("pauseAllEffects");
	    }
	}
コード例 #29
0
ファイル: libOpenAl.cpp プロジェクト: xuyunhan/Dancing
OPAL_SOUND_MGR bool SoundManager::setListenerPosition( Vector3 position, Vector3 velocity,
													  Quaternion orientation )
{
	Vector3 axis;

	// Set the position
	ALfloat pos[] = { position.x, position.y, position.z };

	alListenerfv( AL_POSITION, pos );

	if ( checkALError( "setListenerPosition::alListenerfv:AL_POSITION" ) )
		return false;

	// Set the veclocity
	ALfloat vel[] = { velocity.x, velocity.y, velocity.z };

	alListenerfv( AL_VELOCITY, vel );

	if ( checkALError( "setListenerPosition::alListenerfv:AL_VELOCITY" ) )
		return false;

	// Orientation of the listener : look at then look up
	axis = Vector3::ZERO;
	axis.x = orientation.getYaw().valueRadians();
	axis.y = orientation.getPitch().valueRadians();
	axis.z = orientation.getRoll().valueRadians();

	// Set the direction
	ALfloat dir[] = { axis.x, axis.y, axis.z };

	alListenerfv( AL_ORIENTATION, dir );

	if ( checkALError( "setListenerPosition::alListenerfv:AL_DIRECTION" ) )
		return false;

	// TODO as parameters ?
	alListenerf( AL_MAX_DISTANCE, 10000.0f );
	alListenerf( AL_MIN_GAIN, 0.0f );
	alListenerf( AL_MAX_GAIN, 1.0f );
	alListenerf( AL_GAIN, 1.0f );

	return true;
}
コード例 #30
0
bool SimpleAudioEngine::isBackgroundMusicPlaying()
{
    // If there is no source, then there is nothing that is playing
    if (s_backgroundSource == AL_NONE)
        return false;

    ALint play_status;
    alGetSourcei(s_backgroundSource, AL_SOURCE_STATE, &play_status);
    checkALError("isBackgroundMusicPlaying:alGetSourcei");

    return (play_status == AL_PLAYING);
}