| 433 | |
| 434 | |
| 435 | void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, ALCcontext *context, |
| 436 | ALCdevice *device) |
| 437 | { |
| 438 | voice->mLoopBuffer.store(source->Looping ? &source->mQueue.front() : nullptr, |
| 439 | std::memory_order_relaxed); |
| 440 | |
| 441 | ALbuffer *buffer{BufferList->mBuffer}; |
| 442 | ALuint num_channels{buffer->channelsFromFmt()}; |
| 443 | voice->mFrequency = buffer->mSampleRate; |
| 444 | voice->mFmtChannels = buffer->mChannels; |
| 445 | voice->mFmtType = buffer->mType; |
| 446 | voice->mSampleSize = buffer->bytesFromFmt(); |
| 447 | voice->mAmbiLayout = buffer->mAmbiLayout; |
| 448 | voice->mAmbiScaling = buffer->mAmbiScaling; |
| 449 | voice->mAmbiOrder = buffer->mAmbiOrder; |
| 450 | |
| 451 | if(buffer->mCallback) voice->mFlags |= VoiceIsCallback; |
| 452 | else if(source->SourceType == AL_STATIC) voice->mFlags |= VoiceIsStatic; |
| 453 | voice->mNumCallbackSamples = 0; |
| 454 | |
| 455 | /* Clear the stepping value explicitly so the mixer knows not to mix this |
| 456 | * until the update gets applied. |
| 457 | */ |
| 458 | voice->mStep = 0; |
| 459 | |
| 460 | if(voice->mChans.capacity() > 2 && num_channels < voice->mChans.capacity()) |
| 461 | al::vector<Voice::ChannelData>{}.swap(voice->mChans); |
| 462 | voice->mChans.reserve(maxu(2, num_channels)); |
| 463 | voice->mChans.resize(num_channels); |
| 464 | |
| 465 | /* Don't need to set the VOICE_IS_AMBISONIC flag if the device is not |
| 466 | * higher order than the voice. No HF scaling is necessary to mix it. |
| 467 | */ |
| 468 | if(voice->mAmbiOrder && device->mAmbiOrder > voice->mAmbiOrder) |
| 469 | { |
| 470 | const uint8_t *OrderFromChan{(voice->mFmtChannels == FmtBFormat2D) ? |
| 471 | AmbiIndex::OrderFrom2DChannel().data() : |
| 472 | AmbiIndex::OrderFromChannel().data()}; |
| 473 | const auto scales = BFormatDec::GetHFOrderScales(voice->mAmbiOrder, device->mAmbiOrder); |
| 474 | |
| 475 | const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)}; |
| 476 | |
| 477 | for(auto &chandata : voice->mChans) |
| 478 | { |
| 479 | chandata.mPrevSamples.fill(0.0f); |
| 480 | chandata.mAmbiScale = scales[*(OrderFromChan++)]; |
| 481 | chandata.mAmbiSplitter = splitter; |
| 482 | chandata.mDryParams = DirectParams{}; |
| 483 | std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{}); |
| 484 | } |
| 485 | |
| 486 | voice->mFlags |= VoiceIsAmbisonic; |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | /* Clear previous samples. */ |
| 491 | for(auto &chandata : voice->mChans) |
| 492 | { |
no test coverage detected