bool CIwGameAudio::PlayMusic(void* buffer, uint32 buffer_length, uint32 repeat_count) { if (s3eAudioPlayFromBuffer(buffer, buffer_length, repeat_count) != S3E_RESULT_SUCCESS) return false; return true; }
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) { s3eResult result; result = s3eAudioPlayFromBuffer(g_AudioBuffer, g_AudioFileSize, bLoop ? 0 : 1); if ( result == S3E_RESULT_ERROR) { result = s3eAudioPlay(pszFilePath, bLoop ? 0 : 1); } if ( result == S3E_RESULT_ERROR) { IwAssert(GAME, ("Play music %s Failed. Error Code : %s", pszFilePath, s3eAudioGetErrorString())); } }
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) { // Changing file path to full path std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath); s3eResult result; result = s3eAudioPlayFromBuffer(g_AudioBuffer, g_AudioFileSize, bLoop ? 0 : 1); if ( result == S3E_RESULT_ERROR) { result = s3eAudioPlay(fullPath.c_str(), bLoop ? 0 : 1); } if ( result == S3E_RESULT_ERROR) { IwAssert(GAME, ("Play music %s Failed. Error Code : %s", fullPath.c_str(), s3eAudioGetErrorString())); } }
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; }