Changeset 329 for trunk/src/sdl


Ignore:
Timestamp:
09/02/14 06:16:30 (11 years ago)
Author:
epyon
Message:
  • audio now based on handles
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sdl/sdl_audio.cc

    r322 r329  
    3232
    3333
    34 nv::channel* sdl::audio::play_sound( nv::sound* a_sound )
     34nv::channel sdl::audio::play_sound( sound a_sound )
    3535{
    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 )
    3738        {
    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                }
    3943        }
    40         return nullptr;
     44        return channel();
    4145}
    4246
    43 nv::sound* nv::sdl::audio::load_sound( const std::string& a_path )
     47nv::sound nv::sdl::audio::load_sound( const std::string& a_path )
    4448{
    4549        // TODO: this is a really wierd error - if we remove this check, all hell gets loose
     
    5256        {
    5357                NV_LOG( LOG_ERROR, "SDL_mixer failed to load sample '" << a_path << "' -- " << Mix_GetError() );
    54                 return nullptr;
     58                return sound();
    5559        }
    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;
    5764}
    5865
     
    6471nv::sdl::audio::~audio()
    6572{
     73        while ( m_sounds.size() > 0 )
     74                release( m_sounds.get_handle(0) );
    6675        Mix_CloseAudio();
    6776        // TODO: should we do it here?
     
    6978}
    7079
    71 nv::sdl::sound::~sound()
     80void nv::sdl::audio::release( sound a_sound )
    7281{
    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        }
    7488}
     89
Note: See TracChangeset for help on using the changeset viewer.