本文整理汇总了C++中AudioSampleBuffer::getMagnitude方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioSampleBuffer::getMagnitude方法的具体用法?C++ AudioSampleBuffer::getMagnitude怎么用?C++ AudioSampleBuffer::getMagnitude使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioSampleBuffer
的用法示例。
在下文中一共展示了AudioSampleBuffer::getMagnitude方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processBlock
void ZenAutoTrimAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
if (isEnabled())
{
aPlayHead = getPlayHead();
AudioPlayHead::CurrentPositionInfo posInfo;
aPlayHead->getCurrentPosition(posInfo);
//float* leftData = buffer.getWritePointer(0); //leftData references left channel now
//float* rightData = buffer.getWritePointer(1); //right data references right channel now
//unsigned int numSamples = buffer.getNumSamples();
if (prevSampleRate != this->getSampleRate())
{
prevSampleRate = this->getSampleRate();
levelAnalysisManager.sampleRateChanged(prevSampleRate);
}
//don't process if all samples are 0 or if autogain button is off
if (buffer.getMagnitude(0, buffer.getNumSamples()) > 0.0f && autoGainEnableParam->isOn())
levelAnalysisManager.processSamples(&buffer, posInfo);
// Calibrate gain param based on which value is target
double peakToHit;
int targetType = targetTypeParam->getValueAsInt();
if (targetType == Peak)
{
peakToHit = levelAnalysisManager.getMaxChannelPeak();
}
else if (targetType == MaxRMS)
{
peakToHit = levelAnalysisManager.getMaxChannelRMS();
}
else if (targetType == AverageRMS)
{
peakToHit = levelAnalysisManager.getMaxCurrentRunningRMS();
}
else
{
peakToHit = levelAnalysisManager.getMaxChannelPeak();
jassertfalse;
}
//double targParamGain = params->getDecibelParameter(targetGainParamID)->getValueInGain();
//division in log equiv to subtract in base
double gainValueToAdd = targetGainParam->getValueInGain() / peakToHit;
if (!almostEqual(gainValueToAdd, gainParam->getValueInGain())) // gain value changed
{
gainParam->setValueFromGain(gainValueToAdd);
//gainParam->setNeedsUIUpdate(true); // removed because done in setValueFromGain
}
//in gain, multiply in log equivalent to add in base
buffer.applyGain(gainParam->getValueInGain());
}
}
示例2: processBlock
void IAAEffectProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer&)
{
const float gain = *parameters.getRawParameterValue ("gain");
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();
const int numSamples = buffer.getNumSamples();
for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
// Apply the gain to the samples using a ramp to avoid discontinuities in
// the audio between processed buffers.
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
buffer.applyGainRamp (channel, 0, numSamples, previousGain, gain);
meterListeners.call (&IAAEffectProcessor::MeterListener::handleNewMeterValue,
channel,
buffer.getMagnitude (channel, 0, numSamples));
}
previousGain = gain;
// Now ask the host for the current time so we can store it to be displayed later.
updateCurrentTimeInfoFromHost (lastPosInfo);
}
示例3: renderWholeBuffer
void RouteEffect::renderWholeBuffer(AudioSampleBuffer &b)
{
const int numSamples = b.getNumSamples();
if (getMatrix().isEditorShown())
{
float gainValues[NUM_MAX_CHANNELS];
jassert(getMatrix().getNumSourceChannels() == b.getNumChannels());
for (int i = 0; i < b.getNumChannels(); i++)
{
gainValues[i] = b.getMagnitude(i, 0, b.getNumSamples());
}
getMatrix().setGainValues(gainValues, true);
}
for (int i = 0; i < b.getNumChannels(); i++)
{
const int j = getMatrix().getSendForSourceChannel(i);
if (j != -1)
{
FloatVectorOperations::add(b.getWritePointer(j), b.getReadPointer(i), numSamples);
}
}
if (getMatrix().isEditorShown())
{
float gainValues[NUM_MAX_CHANNELS];
jassert(getMatrix().getNumDestinationChannels() == b.getNumChannels());
for (int i = 0; i < b.getNumChannels(); i++)
{
gainValues[i] = b.getMagnitude(i, 0, b.getNumSamples());
}
getMatrix().setGainValues(gainValues, false);
}
}
示例4: processBlock
void GateTrigger::processBlock (AudioSampleBuffer& buffer,
MidiBuffer& midiMessages)
{
float threshold = library->getThreshold();
int64 releaseTicks = library->getReleaseTicks();
float velocityScale = library->getVelocityScale();
int windowSize = buffer.getNumSamples();
for (int i = 0; i < buffer.getNumSamples(); i += windowSize) {
float rms = 0;
for (int chan = 0; chan < buffer.getNumChannels(); chan++) {
rms += buffer.getMagnitude (chan, i, jmin(windowSize, buffer.getNumSamples() - i));
}
rms = rms / buffer.getNumChannels() * 100;
if (rms - lastRms > threshold) {
if (Time::getHighResolutionTicks() - lastTriggerTick > releaseTicks) {
Pattern* pattern = sequencer->getPattern();
Instrument* instrument = pattern->getActiveInstrument();
// play note
float velocity = (rms - lastRms) / velocityScale;
DBG("RMS: " + String(rms) + " lastRMS: " + String(lastRms) + " velocity: " + String(velocity));
int noteNumber = instrument->getNoteNumber();
MidiMessage m = MidiMessage::noteOn (1, noteNumber, velocity);
midiMessages.addEvent (m, i);
// insert into sequencer pattern
int step = round(sequencer->getPreciseStep());
step = step % pattern->getNumSteps();
Cell* cell = pattern->getCellAt (0, step);
delayedInserterThread->insertNote (cell, velocity, instrument);
// Retrigger the reset timer
resetTimer->retrigger();
lastTriggerTick = Time::getHighResolutionTicks();
}
}
lastRms = rms;
}
}