Index: trunk/src/sdl/sdl_audio.cc
===================================================================
--- trunk/src/sdl/sdl_audio.cc	(revision 322)
+++ trunk/src/sdl/sdl_audio.cc	(revision 329)
@@ -32,14 +32,18 @@
 
 
-nv::channel* sdl::audio::play_sound( nv::sound* a_sound )
+nv::channel sdl::audio::play_sound( sound a_sound )
 {
-	if ( Mix_PlayChannel(-1, (Mix_Chunk*)( down_cast< sdl::sound >( a_sound )->m_sound), 0) == -1 )
+	sound_info* info = m_sounds.get( a_sound );
+	if ( info )
 	{
-		NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() );
+		if ( Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0) == -1 )
+		{
+			NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() );
+		}
 	}
-	return nullptr;
+	return channel();
 }
 
-nv::sound* nv::sdl::audio::load_sound( const std::string& a_path )
+nv::sound nv::sdl::audio::load_sound( const std::string& a_path )
 {
 	// TODO: this is a really wierd error - if we remove this check, all hell gets loose
@@ -52,7 +56,10 @@
 	{
 		NV_LOG( LOG_ERROR, "SDL_mixer failed to load sample '" << a_path << "' -- " << Mix_GetError() );
-		return nullptr;
+		return sound();
 	}
-	return new sdl::sound( sample );
+	sound result = m_sounds.create();
+	sound_info* info = m_sounds.get( result );
+	info->sdl_sound = sample;
+	return result;
 }
 
@@ -64,4 +71,6 @@
 nv::sdl::audio::~audio()
 {
+	while ( m_sounds.size() > 0 )
+		release( m_sounds.get_handle(0) );
 	Mix_CloseAudio();
 	// TODO: should we do it here?
@@ -69,6 +78,12 @@
 }
 
-nv::sdl::sound::~sound()
+void nv::sdl::audio::release( sound a_sound )
 {
-	Mix_FreeChunk( (Mix_Chunk*)m_sound );
+	sound_info* info = m_sounds.get( a_sound );
+	if ( info )
+	{
+		Mix_FreeChunk( (Mix_Chunk*)info->sdl_sound );
+		m_sounds.destroy( a_sound );
+	}
 }
+
