| 193 | } |
| 194 | |
| 195 | std::unique_ptr<AudioBus> RecorderNode::createBusFromRecording(bool mixToMono) |
| 196 | { |
| 197 | std::lock_guard<std::recursive_mutex> lock(m_mutex); |
| 198 | |
| 199 | int numSamples = static_cast<int>(m_data[0].size()); |
| 200 | if (!numSamples) return {}; |
| 201 | |
| 202 | const int result_channel_count = mixToMono ? 1 : m_channelCount; |
| 203 | |
| 204 | // Create AudioBus where we'll put the PCM audio data |
| 205 | std::unique_ptr<lab::AudioBus> result_audioBus(new lab::AudioBus(result_channel_count, numSamples)); |
| 206 | result_audioBus->setSampleRate(m_sampleRate); |
| 207 | |
| 208 | // Mix channels to mono if requested, and there's more than one input channel. |
| 209 | if (m_channelCount > 1 && mixToMono) |
| 210 | { |
| 211 | float* destinationMono = result_audioBus->channel(0)->mutableData(); |
| 212 | |
| 213 | for (int i = 0; i < numSamples; i++) |
| 214 | { |
| 215 | destinationMono[i] = 0; |
| 216 | for (size_t j = 0; j < m_channelCount; ++j) |
| 217 | destinationMono[i] += m_data[j][i]; |
| 218 | destinationMono[i] *= 1.f / static_cast<float>(m_channelCount); |
| 219 | } |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | for (int i = 0; i < result_channel_count; ++i) |
| 224 | { |
| 225 | memcpy(result_audioBus->channel(i)->mutableData(), m_data[0].data(), numSamples * sizeof(float)); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | for (int i = 0; i < m_data.size(); ++i) |
| 230 | m_data[i].clear(); |
| 231 | |
| 232 | return result_audioBus; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | void RecorderNode::reset(ContextRenderLock & r) |
nothing calls this directly
no test coverage detected