Add audio samples to a specific channel
| 828 | |
| 829 | // Add audio samples to a specific channel |
| 830 | void Frame::AddAudio(bool replaceSamples, int destChannel, int destStartSample, const float* source, int numSamples, float gainToApplyToSource = 1.0f) { |
| 831 | const std::lock_guard<std::recursive_mutex> lock(addingAudioMutex); |
| 832 | |
| 833 | // Clamp starting sample to 0 |
| 834 | int destStartSampleAdjusted = max(destStartSample, 0); |
| 835 | |
| 836 | // Extend audio container to hold more (or less) samples and channels.. if needed |
| 837 | int new_length = destStartSampleAdjusted + numSamples; |
| 838 | int new_channel_length = audio->getNumChannels(); |
| 839 | if (destChannel >= new_channel_length) |
| 840 | new_channel_length = destChannel + 1; |
| 841 | if (new_length > audio->getNumSamples() || new_channel_length > audio->getNumChannels()) |
| 842 | audio->setSize(new_channel_length, new_length, true, true, false); |
| 843 | |
| 844 | // Clear the range of samples first (if needed) |
| 845 | if (replaceSamples) |
| 846 | audio->clear(destChannel, destStartSampleAdjusted, numSamples); |
| 847 | |
| 848 | // Add samples to frame's audio buffer |
| 849 | audio->addFrom(destChannel, destStartSampleAdjusted, source, numSamples, gainToApplyToSource); |
| 850 | has_audio_data = true; |
| 851 | |
| 852 | // Calculate max audio sample added |
| 853 | if (new_length > max_audio_sample) |
| 854 | max_audio_sample = new_length; |
| 855 | |
| 856 | // Reset audio direction |
| 857 | audio_is_increasing = true; |
| 858 | } |
| 859 | |
| 860 | // Apply gain ramp (i.e. fading volume) |
| 861 | void Frame::ApplyGainRamp(int destChannel, int destStartSample, int numSamples, float initial_gain = 0.0f, float final_gain = 1.0f) |
no test coverage detected