MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / AddAudio

Method AddAudio

src/Frame.cpp:830–858  ·  view source on GitHub ↗

Add audio samples to a specific channel

Source from the content-addressed store, hash-verified

828
829// Add audio samples to a specific channel
830void 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)
861void Frame::ApplyGainRamp(int destChannel, int destStartSample, int numSamples, float initial_gain = 0.0f, float final_gain = 1.0f)

Callers 10

apply_timemappingMethod · 0.80
ProcessAudioPacketMethod · 0.80
GetFrameMethod · 0.80
add_layerMethod · 0.80
GetFrameMethod · 0.80
ResampleMappedAudioMethod · 0.80
Clip.cppFile · 0.80
GetFrameMethod · 0.80
DummyReader.cppFile · 0.80
FrameMapper.cppFile · 0.80

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected