void MarmaladeAmplifier::onSoundChangeVolume( float _sound, float _music, float _voice ) { int32 s3e_volume = (int32)(m_volume * _music * float( S3E_AUDIO_MAX_VOLUME )); s3eResult result = s3eAudioSetInt( S3E_AUDIO_VOLUME, s3e_volume ); if( result == S3E_RESULT_ERROR ) { s3eAudioError s3eAudio_error = s3eAudioGetError(); const char * s3eAudio_string = s3eAudioGetErrorString(); LOGGER_ERROR(m_serviceProvider)("Amplifier::onSoundChangeVolume invalid set S3E_AUDIO_VOLUME %d error %d [%s]" , s3e_volume , s3eAudio_error , s3eAudio_string ); } }
void MarmaladeAmplifier::setPosMs( float _posMs ) { int32 s3e_pos = (int32)_posMs; s3eResult result = s3eAudioSetInt( S3E_AUDIO_POSITION, s3e_pos ); if( result == S3E_RESULT_ERROR ) { s3eAudioError s3eAudio_error = s3eAudioGetError(); const char * s3eAudio_string = s3eAudioGetErrorString(); LOGGER_ERROR(m_serviceProvider)("Amplifier::setPosMs invalid set S3E_AUDIO_POSITION %d error %d [%s]" , s3e_pos , s3eAudio_error , s3eAudio_string ); } }
Sounds::Sounds() { IGLog("Sounds init"); soundKeyMove = NULL; soundOpenChest = NULL; soundRestartLevel = NULL; soundDoor = NULL; soundClick = NULL; soundMapLocked = NULL; soundUnlockAchievement = NULL; if(AIRPLAY_DEVICE == AIRPLAY_DEVICE_IPHONE) { // for iphone, if there's background music playing, keep it playing if(s3eIOSBackgroundMusicAvailable() == S3E_TRUE) { if(s3eIOSBackgroundMusicGetInt(S3E_IOSBACKGROUNDMUSIC_PLAYBACK_STATE) == S3E_IOSBACKGROUNDMUSIC_PLAYBACK_INTERRUPTED) s3eIOSBackgroundMusicPlay(); if(s3eIOSBackgroundAudioIsPlaying() == S3E_TRUE) s3eIOSBackgroundAudioSetMix(S3E_TRUE); } } // set default frequency at which all channels will play at, in Hz. s3eSoundSetInt(S3E_SOUND_DEFAULT_FREQ, 44100); // turn down the volume s3eSoundSetInt(S3E_SOUND_VOLUME, 96); s3eAudioSetInt(S3E_AUDIO_VOLUME, 96); // if sounds are enabled, load the sounds if(Settings::getInstance()->soundEnabled) loadSounds(); // start playing music? gameplayStart = 0; gameplayPlaying = false; if(Settings::getInstance()->musicEnabled) { if(GameData::getInstance()->isSavedGame()) startMusicGameplay(); else startMusicMenu(); } }
bool MarmaladeAmplifier::playMusic( const ConstString & _resourceMusic, float _pos, bool _looped ) { if( m_play == true ) { this->stop(); } m_loop = _looped; ResourceMusicPtr resourceMusic = RESOURCE_SERVICE( m_serviceProvider ) ->getResourceReferenceT<ResourceMusicPtr>( _resourceMusic ); if( resourceMusic == nullptr ) { LOGGER_ERROR( m_serviceProvider )("Amplifier::playMusic can't found resource '%s'" , _resourceMusic.c_str() ); return false; } const ConstString & category = resourceMusic->getCategory(); const FilePath & path = resourceMusic->getPath(); const ConstString & codec = resourceMusic->getCodec(); bool external = resourceMusic->isExternal(); float volume = resourceMusic->getVolume(); m_volume = volume; if( external == false ) { InputStreamInterfacePtr stream = FILE_SERVICE(m_serviceProvider) ->openInputFile( category, path, false ); if( stream == nullptr ) { LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: invalid open sound '%s:%s'" , category.c_str() , path.c_str() ); return false; } m_audioMemory = Helper::createMemoryStream( m_serviceProvider, stream ); if( m_audioMemory == nullptr ) { LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: invalid create memory '%s:%s'" , category.c_str() , path.c_str() ); return false; } void * buffer_memory = m_audioMemory->getMemory(); size_t buffer_size = m_audioMemory->getSize(); s3eResult result_play = s3eAudioPlayFromBuffer( const_cast<void *>(buffer_memory), buffer_size, 1 ); if( result_play == S3E_RESULT_ERROR ) { s3eAudioError s3eAudio_error = s3eAudioGetError(); const char * s3eAudio_string = s3eAudioGetErrorString(); LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: can't play internal audio '%s:%s' error %d [%s]" , category.c_str() , path.c_str() , s3eAudio_error , s3eAudio_string ); return false; } } else { const Char * str_path = path.c_str(); s3eResult result_play = s3eAudioPlay( str_path, 1 ); if( result_play == S3E_RESULT_ERROR ) { s3eAudioError s3eAudio_error = s3eAudioGetError(); const char * s3eAudio_string = s3eAudioGetErrorString(); LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: can't play external audio '%s' error %d [%s]" , path.c_str() , s3eAudio_error , s3eAudio_string ); return false; } } int32 s3e_pos = (int32)_pos; if( s3e_pos != 0 ) { // W/o this, there is sound bugs during playback on iOS. s3eDeviceYield( 0 ); s3eResult result_position = s3eAudioSetInt( S3E_AUDIO_POSITION, s3e_pos ); if( result_position == S3E_RESULT_ERROR ) { s3eAudioError s3eAudio_error = s3eAudioGetError(); const char * s3eAudio_string = s3eAudioGetErrorString(); LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: can't '%s:%s' set pos %d error %d [%s]" , category.c_str() , path.c_str() , s3e_pos , s3eAudio_error , s3eAudio_string ); } } float commonVolume = SOUND_SERVICE( m_serviceProvider ) ->mixCommonVolume(); float musicVolume = SOUND_SERVICE( m_serviceProvider ) ->mixMusicVolume(); int32 s3e_volume = (int32)(m_volume * commonVolume * musicVolume * float( S3E_AUDIO_MAX_VOLUME )); s3eResult result = s3eAudioSetInt( S3E_AUDIO_VOLUME, s3e_volume ); if( result == S3E_RESULT_ERROR ) { s3eAudioError s3eAudio_error = s3eAudioGetError(); const char * s3eAudio_string = s3eAudioGetErrorString(); LOGGER_ERROR( m_serviceProvider )("Amplifier::onSoundChangeVolume invalid set S3E_AUDIO_VOLUME %d error %d [%s]" , s3e_volume , s3eAudio_error , s3eAudio_string ); } return true; }
void SimpleAudioEngine::setBackgroundMusicVolume(float volume) { s3eAudioSetInt(S3E_AUDIO_VOLUME, (int32)(volume * (float)GEOM_ONE_FP8)); }
void CIwGameAudio::setMusicVolume(float vol) { MusicVolume = vol; s3eAudioSetInt(S3E_AUDIO_VOLUME, (int)(MusicVolume * S3E_AUDIO_MAX_VOLUME)); }
void SimpleAudioEngine::setBackgroundMusicVolume(float volume) { s3eAudioSetInt(S3E_AUDIO_VOLUME, volume); }
void MusicPlayer::decreaseVolume() { int vol = s3eAudioGetInt(S3E_AUDIO_VOLUME); s3eAudioSetInt(S3E_AUDIO_VOLUME, vol-10); }