| 73 | } |
| 74 | |
| 75 | void RealtimeAnalyser::writeInput(ContextRenderLock & r, AudioBus * bus, int framesToProcess) |
| 76 | { |
| 77 | bool isBusGood = bus && bus->numberOfChannels() > 0 && bus->channel(0)->length() >= framesToProcess && r.context(); |
| 78 | if (!isBusGood) |
| 79 | return; |
| 80 | |
| 81 | // FIXME : allow to work with non-FFTSize divisible chunking |
| 82 | bool isDestinationGood = m_writeIndex < m_inputBuffer.size() && m_writeIndex + framesToProcess <= m_inputBuffer.size(); |
| 83 | ASSERT(isDestinationGood); |
| 84 | if (!isDestinationGood) |
| 85 | return; |
| 86 | |
| 87 | // copy data for analysis |
| 88 | const float * source = bus->channel(0)->data(); |
| 89 | float * dest = m_inputBuffer.data() + m_writeIndex; |
| 90 | |
| 91 | // The source has already been sanity checked with isBusGood above. |
| 92 | memcpy(dest, source, sizeof(float) * framesToProcess); |
| 93 | |
| 94 | // Sum all channels in one if numberOfChannels > 1. |
| 95 | const size_t numberOfChannels = bus->numberOfChannels(); |
| 96 | if (numberOfChannels > 1) |
| 97 | { |
| 98 | for (int i = 1; i < numberOfChannels; i++) |
| 99 | { |
| 100 | source = bus->channel(i)->data(); |
| 101 | VectorMath::vadd(dest, 1, source, 1, dest, 1, framesToProcess); |
| 102 | } |
| 103 | const float scale = 1.f / numberOfChannels; |
| 104 | VectorMath::vsmul(dest, 1, &scale, dest, 1, framesToProcess); |
| 105 | } |
| 106 | |
| 107 | m_writeIndex += framesToProcess; |
| 108 | if (m_writeIndex >= InputBufferSize) |
| 109 | m_writeIndex = 0; |
| 110 | } |
| 111 | |
| 112 | void RealtimeAnalyser::doFFTAnalysis() |
| 113 | { |