///////////////////////////////////////////////////////
| 140 | |
| 141 | //////////////////////////////////////////////////////////// |
| 142 | void MiniaudioUtils::SoundBase::initialize(ma_sound_end_proc endCallback) |
| 143 | { |
| 144 | // Initialize the sound |
| 145 | auto* engine = AudioDevice::getEngine(); |
| 146 | |
| 147 | if (engine == nullptr) |
| 148 | { |
| 149 | err() << "Failed to initialize sound: No engine available" << std::endl; |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | ma_sound_config soundConfig; |
| 154 | |
| 155 | soundConfig = ma_sound_config_init(); |
| 156 | soundConfig.pDataSource = this; |
| 157 | soundConfig.pEndCallbackUserData = this; |
| 158 | soundConfig.endCallback = endCallback; |
| 159 | |
| 160 | if (const ma_result result = ma_sound_init_ex(engine, &soundConfig, &sound); result != MA_SUCCESS) |
| 161 | { |
| 162 | err() << "Failed to initialize sound: " << ma_result_description(result) << std::endl; |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | // Initialize the custom effect node |
| 167 | effectNodeVTable.onProcess = |
| 168 | [](ma_node* node, const float** framesIn, std::uint32_t* frameCountIn, float** framesOut, std::uint32_t* frameCountOut) |
| 169 | { static_cast<EffectNode*>(node)->impl->processEffect(framesIn, *frameCountIn, framesOut, *frameCountOut); }; |
| 170 | effectNodeVTable.onGetRequiredInputFrameCount = nullptr; |
| 171 | effectNodeVTable.inputBusCount = 1; |
| 172 | effectNodeVTable.outputBusCount = 1; |
| 173 | effectNodeVTable.flags = MA_NODE_FLAG_CONTINUOUS_PROCESSING | MA_NODE_FLAG_ALLOW_NULL_INPUT; |
| 174 | |
| 175 | const auto nodeChannelCount = ma_engine_get_channels(engine); |
| 176 | ma_node_config nodeConfig = ma_node_config_init(); |
| 177 | nodeConfig.vtable = &effectNodeVTable; |
| 178 | nodeConfig.pInputChannels = &nodeChannelCount; |
| 179 | nodeConfig.pOutputChannels = &nodeChannelCount; |
| 180 | |
| 181 | if (const ma_result result = ma_node_init(ma_engine_get_node_graph(engine), &nodeConfig, nullptr, &effectNode); |
| 182 | result != MA_SUCCESS) |
| 183 | { |
| 184 | err() << "Failed to initialize effect node: " << ma_result_description(result) << std::endl; |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | effectNode.impl = this; |
| 189 | effectNode.channelCount = nodeChannelCount; |
| 190 | |
| 191 | // Route the sound through the effect node depending on whether an effect processor is set |
| 192 | connectEffect(bool{effectProcessor}); |
| 193 | |
| 194 | applySettings(sound, savedSettings); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | //////////////////////////////////////////////////////////// |
nothing calls this directly
no test coverage detected