本文整理汇总了C++中AudioBuffer::addFrom方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioBuffer::addFrom方法的具体用法?C++ AudioBuffer::addFrom怎么用?C++ AudioBuffer::addFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioBuffer
的用法示例。
在下文中一共展示了AudioBuffer::addFrom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFromDelayBuffer
void DaalDelAudioProcessor::getFromDelayBuffer(AudioBuffer<float>& buffer, const int channel, const int bufferLength, const int delayBufferLength, const float* bufferData, const float* delayBufferData) {
// Set delay time
int curDelayTime = _curDelayTime;
// Randomize delay time (half vs. full)
// int dice = rand() % 100;
// if (dice > 50) {
// curDelayTime = static_cast<int>(_delayTimeMax / 2);
// }
// Randomize delay time (within min to max range)
curDelayTime = rand() % (std::max(_delayTimeMax - _delayTimeMin, 1));
curDelayTime += _delayTimeMin;
// Just set it to min
// curDelayTime = _delayTimeMin;
// ====
// Poor man's oscillator (just for testing real quick)
// TODO: Use a real oscillator
if (_curDelayTimeDirectionIsUp) { // Up
curDelayTime++;
if (curDelayTime >= _delayTimeMax) _curDelayTimeDirectionIsUp = false;
}
else { // Down
curDelayTime--;
if (curDelayTime <= _delayTimeMin) _curDelayTimeDirectionIsUp = true;
}
// ====
// Update delay time
_curDelayTime = curDelayTime;
DBG("curDelayTime=" + String(curDelayTime));
// Get
const int readPosition = static_cast<int> (delayBufferLength + _writePosition - (_sampleRate * curDelayTime / 1000)) % delayBufferLength;
if (delayBufferLength > bufferLength + readPosition) { // Straight copy
buffer.addFrom(channel, 0, delayBufferData + readPosition, bufferLength, 1 - _delayDryWetGain);
}
else { // Copy with wrap-around
const int bufferRemaining = delayBufferLength - readPosition;
buffer.addFrom(channel, 0, delayBufferData + readPosition, bufferRemaining, 1 - _delayDryWetGain);
buffer.addFrom(channel, bufferRemaining, delayBufferData, bufferLength - bufferRemaining, 1 - _delayDryWetGain);
}
}
示例2: processBlock
void PolyWavegeneratorProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiBuffer)
{
// clear all the midibuffers of the voices because they still contain the events from the last process Block
for(int index = 0; index < voices.size(); index++)
{
voices[index]->clearMidiBuffer();
}
// Midi and Voice Handler this is not correct yet i need to watch out for different note ons of the same note in one buffer and other stuff
if(takesMidi && !midiBuffer.isEmpty())
{
MidiMessage& message1 = *new MidiMessage();
ScopedPointer<MidiBuffer::Iterator> iterator = new MidiBuffer::Iterator(midiBuffer);
int sampleInBuffer = 0;
while(iterator->getNextEvent(message1, sampleInBuffer))
{
if(message1.isNoteOn())
{
// always take the first one and move it to the back => the oldest voice will be "overwritten"
voices[0]->setIsOn(true);
voices[0]->setMidiNote(message1.getNoteNumber());
voices[0]->addMidiEvent(message1, sampleInBuffer);
voices.move(0, voices.size()-1);
}
else if(message1.isNoteOff())
{
for(int index = 0; index < voices.size(); index++)
{
if(voices[index]->getMidiNote() == message1.getNoteNumber())
{
ScopedPointer<Voice> tempVoice = voices[index];
tempVoice->setIsOn(false);
tempVoice->addMidiEvent(message1, sampleInBuffer);
tempVoice->setMidiNote(-1); // this should be removed but just in case for now
break;
}
}
}
}
}
// Audio Handling of the voices
AudioBuffer<float> outBuffer = getBusBuffer(buffer, false, 0);
int numActive = 0; // eventually this could be a member variable
for(int index = 0; index < voices.size(); index++)
{
if(voices[index]->getIsOn())
{
numActive++;
voices[index]->clearAudioBuffer();
voices[index]->fillBufferEnvelope();
voices[index]->fillBufferAudio();
outBuffer.addFrom(0, 0, voices[index]->getOutBuffer(), 0, 0, outBuffer.getNumSamples());
}
}
outBuffer.applyGain(1.0f/numActive);
}