Changeset 330 for trunk/src/sdl/sdl_audio.cc
- Timestamp:
- 09/02/14 08:45:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sdl/sdl_audio.cc
r329 r330 7 7 #include "nv/sdl/sdl_audio.hh" 8 8 9 #include <glm/gtx/vector_angle.hpp> 9 10 #include "nv/lib/sdl.hh" 10 11 #include "nv/lib/sdl_mixer.hh" … … 31 32 } 32 33 33 34 nv::channel sdl::audio::play_sound( sound a_sound ) 34 nv::channel nv::sdl::audio::play_sound( sound a_sound, float volume, float pan /*= 0.0f */ ) 35 35 { 36 36 sound_info* info = m_sounds.get( a_sound ); 37 37 if ( info ) 38 38 { 39 if ( Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0) == -1 ) 39 int channel = Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0); 40 if ( channel == -1 ) 40 41 { 41 42 NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() ); 43 } 44 else 45 { 46 Mix_Volume( channel, int( volume * 128.0f ) ); 47 if ( pan != 0.0f) 48 { 49 uint8 right = (uint8)( (pan + 1.0f) * 127.0f ); 50 Mix_SetPanning( channel, 254-right, right ); 51 } 52 else 53 { 54 Mix_SetPanning( channel, 255, 255 ); 55 } 56 } 57 } 58 return channel(); 59 } 60 61 nv::channel nv::sdl::audio::play_sound( sound a_sound, vec3 position ) 62 { 63 sound_info* info = m_sounds.get( a_sound ); 64 if ( info ) 65 { 66 int channel = Mix_PlayChannel(-1, (Mix_Chunk*)( info->sdl_sound), 0); 67 if ( channel == -1 ) 68 { 69 NV_LOG( LOG_WARNING, "SDL_mixer failed to play -- " << Mix_GetError() ); 70 } 71 else 72 { 73 vec3 relative = position - m_position; 74 float angle = 0; 75 float distance = 0; 76 if ( relative != vec3() ) 77 { 78 angle = -glm::orientedAngle( m_forward, glm::normalize( relative ), m_up ); 79 distance = glm::clamp( 20.0f * glm::length( relative ), 0.0f, 255.0f ); 80 } 81 if ( angle < 0.0f ) angle += 360.0f; 82 Mix_SetPosition( channel, sint16(angle), uint8(distance) ); 42 83 } 43 84 } … … 47 88 nv::sound nv::sdl::audio::load_sound( const std::string& a_path ) 48 89 { 49 // TODO: this is a really w ierd error - if we remove this check, all hell gets loose90 // TODO: this is a really weird error - if we remove this check, all hell gets loose 50 91 if ( Mix_LoadWAV_RW == nullptr || SDL_RWFromFile == nullptr ) 51 92 { … … 64 105 } 65 106 66 void nv::sdl::audio::update( )107 void nv::sdl::audio::update( vec3 position ) 67 108 { 68 // no-op109 m_position = position; 69 110 } 70 111 … … 88 129 } 89 130 131 void nv::sdl::audio::set_orientation( vec3 forward, vec3 up ) 132 { 133 m_forward = forward; 134 m_up = up; 135 } 136
Note: See TracChangeset
for help on using the changeset viewer.