Changeset 329 for trunk/src/sdl/sdl_audio.cc
- Timestamp:
- 09/02/14 06:16:30 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.