- Timestamp:
- 09/02/14 06:16:30 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/fmod/fmod_audio.cc
r319 r329 37 37 38 38 39 nv::channel * fmod::audio::play_sound( nv::sound*a_sound )39 nv::channel fmod::audio::play_sound( nv::sound a_sound ) 40 40 { 41 FMOD_SYSTEM* system = (FMOD_SYSTEM*)m_system; 42 FMOD_SOUND* sample = (FMOD_SOUND*)( down_cast< fmod::sound >( a_sound )->m_sound ); 43 FMOD_RESULT result = FMOD_System_PlaySound( system, FMOD_CHANNEL_FREE, sample, false, 0 ); 44 if ( result != FMOD_OK ) 41 sound_info* info = m_sounds.get( a_sound ); 42 if ( info ) 45 43 { 46 NV_LOG( LOG_WARNING, "FMOD failed to play sound -- " << FMOD_ErrorString( result ) ); 44 FMOD_SYSTEM* system = (FMOD_SYSTEM*)m_system; 45 FMOD_SOUND* sample = (FMOD_SOUND*)( info->fmod_sound ); 46 FMOD_RESULT result = FMOD_System_PlaySound( system, FMOD_CHANNEL_FREE, sample, false, 0 ); 47 if ( result != FMOD_OK ) 48 { 49 NV_LOG( LOG_WARNING, "FMOD failed to play sound -- " << FMOD_ErrorString( result ) ); 50 } 47 51 } 48 return nullptr;52 return channel(); 49 53 } 50 54 51 nv::sound *fmod::audio::load_sound( const std::string& a_path )55 nv::sound fmod::audio::load_sound( const std::string& a_path ) 52 56 { 53 57 FMOD_SYSTEM* system = (FMOD_SYSTEM*)m_system; 54 58 FMOD_SOUND* sample; 55 FMOD_RESULT result = FMOD_System_CreateSound( system, a_path.c_str(), FMOD_DEFAULT, 0, &sample );56 if ( result != FMOD_OK )59 FMOD_RESULT fm_result = FMOD_System_CreateSound( system, a_path.c_str(), FMOD_DEFAULT, 0, &sample ); 60 if ( fm_result != FMOD_OK ) 57 61 { 58 NV_LOG( LOG_ERROR, "FMOD failed to load sample '" << a_path << "' -- " << FMOD_ErrorString( result ) );59 return nullptr;62 NV_LOG( LOG_ERROR, "FMOD failed to load sample '" << a_path << "' -- " << FMOD_ErrorString( fm_result ) ); 63 return sound(); 60 64 } 61 return new fmod::sound( sample ); 65 sound result = m_sounds.create(); 66 sound_info* info = m_sounds.get( result ); 67 info->fmod_sound = sample; 68 return result; 69 } 70 71 void nv::fmod::audio::release( sound a_sound ) 72 { 73 sound_info* info = m_sounds.get( a_sound ); 74 if ( info ) 75 { 76 FMOD_Sound_Release( (FMOD_SOUND*)info->fmod_sound ); 77 m_sounds.destroy( a_sound ); 78 } 62 79 } 63 80 … … 70 87 fmod::audio::~audio() 71 88 { 89 while ( m_sounds.size() > 0 ) 90 release( m_sounds.get_handle(0) ); 72 91 FMOD_System_Release( (FMOD_SYSTEM*)m_system ); 73 92 } 74 93 75 fmod::sound::~sound()76 {77 FMOD_Sound_Release( (FMOD_SOUND*)m_sound );78 } -
trunk/src/sdl/sdl_audio.cc
r322 r329 32 32 33 33 34 nv::channel * sdl::audio::play_sound( nv::sound*a_sound )34 nv::channel sdl::audio::play_sound( sound a_sound ) 35 35 { 36 if ( Mix_PlayChannel(-1, (Mix_Chunk*)( down_cast< sdl::sound >( a_sound )->m_sound), 0) == -1 ) 36 sound_info* info = m_sounds.get( a_sound ); 37 if ( info ) 37 38 { 38 NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() ); 39 if ( Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0) == -1 ) 40 { 41 NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() ); 42 } 39 43 } 40 return nullptr;44 return channel(); 41 45 } 42 46 43 nv::sound *nv::sdl::audio::load_sound( const std::string& a_path )47 nv::sound nv::sdl::audio::load_sound( const std::string& a_path ) 44 48 { 45 49 // TODO: this is a really wierd error - if we remove this check, all hell gets loose … … 52 56 { 53 57 NV_LOG( LOG_ERROR, "SDL_mixer failed to load sample '" << a_path << "' -- " << Mix_GetError() ); 54 return nullptr;58 return sound(); 55 59 } 56 return new sdl::sound( sample ); 60 sound result = m_sounds.create(); 61 sound_info* info = m_sounds.get( result ); 62 info->sdl_sound = sample; 63 return result; 57 64 } 58 65 … … 64 71 nv::sdl::audio::~audio() 65 72 { 73 while ( m_sounds.size() > 0 ) 74 release( m_sounds.get_handle(0) ); 66 75 Mix_CloseAudio(); 67 76 // TODO: should we do it here? … … 69 78 } 70 79 71 nv::sdl::sound::~sound()80 void nv::sdl::audio::release( sound a_sound ) 72 81 { 73 Mix_FreeChunk( (Mix_Chunk*)m_sound ); 82 sound_info* info = m_sounds.get( a_sound ); 83 if ( info ) 84 { 85 Mix_FreeChunk( (Mix_Chunk*)info->sdl_sound ); 86 m_sounds.destroy( a_sound ); 87 } 74 88 } 89
Note: See TracChangeset
for help on using the changeset viewer.