Changeset 330 for trunk/src/fmod
- Timestamp:
- 09/02/14 08:45:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/fmod/fmod_audio.cc
r329 r330 27 27 return; 28 28 } 29 result = FMOD_System_Init( system, 64, FMOD_ INIT_NORMAL, 0 );29 result = FMOD_System_Init( system, 64, FMOD_3D | FMOD_INIT_3D_RIGHTHANDED, 0 ); 30 30 if ( result != FMOD_OK ) 31 31 { … … 36 36 } 37 37 38 39 nv::channel fmod::audio::play_sound( nv::sound a_sound ) 38 nv::channel nv::fmod::audio::play_sound( sound a_sound, float volume, float pan /*= 0.0f */ ) 40 39 { 41 40 sound_info* info = m_sounds.get( a_sound ); 42 41 if ( info ) 43 42 { 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 ); 43 FMOD_SYSTEM* system = (FMOD_SYSTEM*)m_system; 44 FMOD_SOUND* sample = (FMOD_SOUND*)( info->fmod_sound ); 45 FMOD_CHANNEL* channel = nullptr; 46 FMOD_RESULT result = FMOD_System_PlaySound( system, FMOD_CHANNEL_FREE, sample, true, &channel ); 47 47 if ( result != FMOD_OK ) 48 48 { 49 49 NV_LOG( LOG_WARNING, "FMOD failed to play sound -- " << FMOD_ErrorString( result ) ); 50 } 51 else 52 { 53 FMOD_Channel_SetVolume( channel, volume ); 54 FMOD_Channel_SetPan( channel, pan ); 55 FMOD_Channel_SetPaused( channel, false ); 50 56 } 51 57 } … … 53 59 } 54 60 61 nv::channel nv::fmod::audio::play_sound( sound a_sound, vec3 position ) 62 { 63 sound_info* info = m_sounds.get( a_sound ); 64 if ( info ) 65 { 66 FMOD_SYSTEM* system = (FMOD_SYSTEM*)m_system; 67 FMOD_SOUND* sample = (FMOD_SOUND*)( info->fmod_sound ); 68 FMOD_CHANNEL* channel = nullptr; 69 FMOD_RESULT result = FMOD_System_PlaySound( system, FMOD_CHANNEL_FREE, sample, true, &channel ); 70 if ( result != FMOD_OK ) 71 { 72 NV_LOG( LOG_WARNING, "FMOD failed to play sound -- " << FMOD_ErrorString( result ) ); 73 } 74 else 75 { 76 FMOD_VECTOR fmod_position; 77 fmod_position.x = position.x; 78 fmod_position.y = position.y; 79 fmod_position.z = position.z; 80 FMOD_Channel_Set3DMinMaxDistance( channel, 1, 100000 ); 81 FMOD_Channel_Set3DAttributes( channel, &fmod_position, 0 ); 82 FMOD_Channel_SetPaused( channel, false ); 83 } 84 } 85 return channel(); 86 } 87 88 89 55 90 nv::sound fmod::audio::load_sound( const std::string& a_path ) 56 91 { 57 92 FMOD_SYSTEM* system = (FMOD_SYSTEM*)m_system; 58 93 FMOD_SOUND* sample; 59 FMOD_RESULT fm_result = FMOD_System_CreateSound( system, a_path.c_str(), FMOD_ DEFAULT, 0, &sample );94 FMOD_RESULT fm_result = FMOD_System_CreateSound( system, a_path.c_str(), FMOD_3D, 0, &sample ); 60 95 if ( fm_result != FMOD_OK ) 61 96 { … … 79 114 } 80 115 81 void fmod::audio::update()116 void nv::fmod::audio::set_orientation( vec3 forward, vec3 up ) 82 117 { 118 FMOD_VECTOR fmod_forward; 119 fmod_forward.x = forward.x; 120 fmod_forward.y = forward.y; 121 fmod_forward.z = forward.z; 122 FMOD_VECTOR fmod_up; 123 fmod_up.x = up.x; 124 fmod_up.y = up.y; 125 fmod_up.z = up.z; 126 // TODO: we also need to setup orientation! 127 FMOD_System_Set3DListenerAttributes( (FMOD_SYSTEM*)m_system, 0, 0, 0, &fmod_forward, &fmod_up ); 128 } 129 130 void fmod::audio::update( vec3 position ) 131 { 132 m_position = position; 133 FMOD_VECTOR fmod_position; 134 fmod_position.x = position.x; 135 fmod_position.y = position.y; 136 fmod_position.z = position.z; 137 // FMOD_VECTOR fmod_up; 138 // fmod_up.x = 0.0f; 139 // fmod_up.y = 0.0f; 140 // fmod_up.z = 0.0f; 141 // TODO: we also need to setup orientation! 142 FMOD_System_Set3DListenerAttributes( (FMOD_SYSTEM*)m_system, 0, &fmod_position, 0, 0, 0 ); 83 143 FMOD_System_Update( (FMOD_SYSTEM*)m_system ); 84 // no-op85 144 } 86 145
Note: See TracChangeset
for help on using the changeset viewer.