| 51 | |
| 52 | |
| 53 | void RecorderNode::process(ContextRenderLock & r, int bufferSize) |
| 54 | { |
| 55 | AudioBus * outputBus = output(0)->bus(r); |
| 56 | AudioBus * inputBus = input(0)->bus(r); |
| 57 | |
| 58 | bool has_input = inputBus != nullptr && input(0)->isConnected() && inputBus->numberOfChannels() > 0; |
| 59 | if ((!isInitialized() || !has_input) && outputBus) |
| 60 | { |
| 61 | outputBus->zero(); |
| 62 | } |
| 63 | |
| 64 | if (!has_input) |
| 65 | { |
| 66 | // nothing to record. |
| 67 | if (outputBus) |
| 68 | outputBus->zero(); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // the recorder will conform the number of output channels to the number of input |
| 73 | // in order that it can function as a pass-through node. |
| 74 | const int inputBusNumChannels = inputBus->numberOfChannels(); |
| 75 | int outputBusNumChannels = inputBusNumChannels; |
| 76 | if (outputBus) |
| 77 | { |
| 78 | outputBusNumChannels = outputBus->numberOfChannels(); |
| 79 | |
| 80 | if (inputBusNumChannels != outputBusNumChannels) |
| 81 | { |
| 82 | output(0)->setNumberOfChannels(r, inputBusNumChannels); |
| 83 | outputBusNumChannels = inputBusNumChannels; |
| 84 | outputBus = output(0)->bus(r); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (m_recording) |
| 89 | { |
| 90 | const int numChannels = std::min(inputBusNumChannels, outputBusNumChannels); |
| 91 | |
| 92 | std::vector<const float*> channels; |
| 93 | for (int i = 0; i < numChannels; ++i) |
| 94 | { |
| 95 | channels.push_back(inputBus->channel(i)->data()); |
| 96 | } |
| 97 | |
| 98 | if (m_data.size() < numChannels) |
| 99 | { |
| 100 | // allocate the recording buffers lazily when the number of input channels is finally known |
| 101 | for (int i = 0; i < numChannels; ++i) |
| 102 | { |
| 103 | m_data.emplace_back(std::vector<float>()); |
| 104 | m_data[i].reserve(1024 * 1024); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // copy the output. @TODO this should be a memcpy |
| 109 | std::lock_guard<std::recursive_mutex> lock(m_mutex); |
| 110 | for (int c = 0; c < numChannels; ++c) |
nothing calls this directly
no test coverage detected