Plays a 2d sound
| 272 | |
| 273 | // Plays a 2d sound |
| 274 | int lnxsound::PlaySound2d(play_information *play_info, int sound_index, float f_volume, float f_pan, bool f_looped) { |
| 275 | sound_buffer_info *sb; |
| 276 | int16_t sound_slot; |
| 277 | |
| 278 | if (sound_device == 0) { |
| 279 | return -1; |
| 280 | } |
| 281 | |
| 282 | // calculate volume and pan |
| 283 | f_volume = (f_volume < 0.0f) ? 0.0f : (f_volume > 1.0f) ? 1.0f : f_volume; |
| 284 | play_info->left_volume = play_info->right_volume = f_volume; |
| 285 | |
| 286 | f_pan = (f_pan < -1.0f) ? -1.0f : (f_pan > 1.0f) ? 1.0f : f_pan; |
| 287 | if (f_pan < 0.0) { |
| 288 | play_info->right_volume += f_volume * f_pan; |
| 289 | } else { |
| 290 | play_info->left_volume -= f_volume * f_pan; |
| 291 | } |
| 292 | |
| 293 | // do common processing. |
| 294 | if (SoundFiles[Sounds[sound_index].sample_index].used == 0) { |
| 295 | mprintf(0, "Tryed to play %d sound, it DNE.\n", sound_index); |
| 296 | return -1; |
| 297 | } |
| 298 | #ifdef _DEBUG |
| 299 | sound_slot = FindFreeSoundSlot(sound_index, f_volume, play_info->priority); |
| 300 | #else |
| 301 | sound_slot = FindFreeSoundSlot(f_volume, play_info->priority); |
| 302 | #endif |
| 303 | if (sound_slot < 0) { |
| 304 | // do prioritization code here. |
| 305 | return -1; |
| 306 | } |
| 307 | sb = &sound_cache[sound_slot]; |
| 308 | m_total_sounds_played++; |
| 309 | sb->play_info = play_info; |
| 310 | sb->m_unique_id = MakeUniqueId(sound_slot); |
| 311 | sb->m_buffer_type = SBT_2D; |
| 312 | sb->m_sound_index = sound_index; |
| 313 | sb->m_status = SSF_UNUSED; |
| 314 | |
| 315 | ASSERT(sb->m_unique_id != -1); |
| 316 | |
| 317 | // play 2d sound |
| 318 | sb->m_status = (f_looped) ? SSF_PLAY_LOOPING : SSF_PLAY_NORMAL; |
| 319 | return sb->m_unique_id; |
| 320 | } |
| 321 | |
| 322 | // This function limits the number of sounds cached to 255(8bits) and 256 bit is for invalid channel |
| 323 | // The purpose is to create unique signatures for each sound played (and allow for |