| 334 | } |
| 335 | |
| 336 | void n3ds_audio_thread(void* userdata) { |
| 337 | CtrAudio* audio = static_cast<CtrAudio*>(userdata); |
| 338 | float mix[12] = {0}; |
| 339 | |
| 340 | while (!term_stream) { |
| 341 | LightEvent_Wait(&audio_event); |
| 342 | |
| 343 | int target_block = fill_block; |
| 344 | ++fill_block; |
| 345 | fill_block %= bgm.num_bufs; |
| 346 | |
| 347 | audio->LockMutex(); |
| 348 | if (bgm.decoder) { |
| 349 | bgm.decoder->Decode( |
| 350 | reinterpret_cast<uint8_t*>(bgm.buf[target_block].data_pcm16), |
| 351 | bgm.buf_size); |
| 352 | DSP_FlushDataCache(bgm.buf[target_block].data_pcm16, bgm.buf_size); |
| 353 | mix[0] = mix[1] = bgm.decoder->GetVolume() / 100.0f * audio->GetConfig().music_volume.Get() / 100.0f; |
| 354 | ndspChnSetMix(bgm.channel, mix); |
| 355 | ndspChnWaveBufAdd(bgm.channel, &bgm.buf[target_block]); |
| 356 | } else { |
| 357 | bgm.buf[target_block].status = NDSP_WBUF_DONE; |
| 358 | } |
| 359 | audio->UnlockMutex(); |
| 360 | } |
| 361 | threadExit(0); |
| 362 | } |
| 363 | |
| 364 | CtrAudio::CtrAudio(const Game_ConfigAudio& cfg) : AudioInterface(cfg) { |
| 365 | LightLock_Init(&audio_mutex); |