本文整理汇总了C++中AudioSampleBuffer::getArrayOfChannels方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioSampleBuffer::getArrayOfChannels方法的具体用法?C++ AudioSampleBuffer::getArrayOfChannels怎么用?C++ AudioSampleBuffer::getArrayOfChannels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioSampleBuffer
的用法示例。
在下文中一共展示了AudioSampleBuffer::getArrayOfChannels方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run()
{
const int bufferSize = currentBufferSizeSamples;
HANDLE events[2];
int numEvents = 0;
if (inputDevice != 0)
events [numEvents++] = inputDevice->clientEvent;
if (outputDevice != 0)
events [numEvents++] = outputDevice->clientEvent;
const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
float** const inputBuffers = ins.getArrayOfChannels();
float** const outputBuffers = outs.getArrayOfChannels();
ins.clear();
while (! threadShouldExit())
{
const DWORD result = WaitForMultipleObjects (numEvents, events, true, 1000);
if (result == WAIT_TIMEOUT)
continue;
if (threadShouldExit())
break;
if (inputDevice != 0)
inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
// Make the callback..
{
const ScopedLock sl (startStopLock);
if (isStarted)
{
JUCE_TRY
{
callback->audioDeviceIOCallback ((const float**) inputBuffers,
numInputBuffers,
outputBuffers,
numOutputBuffers,
bufferSize);
}
JUCE_CATCH_EXCEPTION
}
else
{
outs.clear();
}
}
if (outputDevice != 0)
outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
}
示例2: writeFromAudioSampleBuffer
bool AudioFormatWriter::writeFromAudioSampleBuffer (const AudioSampleBuffer& source, int startSample, int numSamples)
{
const int numSourceChannels = source.getNumChannels();
jassert (startSample >= 0 && startSample + numSamples <= source.getNumSamples() && numSourceChannels > 0);
if (startSample == 0)
return writeFromFloatArrays ((const float**) source.getArrayOfChannels(), numSourceChannels, numSamples);
const float* chans [256];
jassert ((int) numChannels < numElementsInArray (chans));
for (int i = 0; i < numSourceChannels; ++i)
chans[i] = source.getSampleData (i, startSample);
chans[numSourceChannels] = nullptr;
return writeFromFloatArrays (chans, numSourceChannels, numSamples);
}
示例3: process
void FilterNode::process(AudioSampleBuffer &buffer,
MidiBuffer &midiMessages,
int& nSamples)
{
//std::cout << "Filter node processing." << std::endl;
//std::cout << buffer.getNumChannels() << std::endl;
//::cout << buffer.getNumSamples() << std::endl;
//int nSamps = getNumSamples(midiMessages);
//std::cout << nSamples << std::endl;
filter->process (nSamples, buffer.getArrayOfChannels());
//std::cout << "Filter node:" << *buffer.getSampleData(0,0);
//int ts = checkForMidiEvents(midiMessages);
//std::cout << "Timestamp = " << ts << std::endl;
}
示例4: processBlock
void DemoJuceFilter::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
assert(mpDSP->getNumInputs()<= buffer.getNumChannels());
assert(mpDSP->getNumOutputs()<= buffer.getNumChannels());
if(mpDSP && mpDSP->getNumInputs()<= buffer.getNumChannels()
&& mpDSP->getNumOutputs() <= buffer.getNumChannels() )
{
mpDSP->compute(buffer.getNumSamples(),
buffer.getArrayOfChannels(),
buffer.getArrayOfChannels());
}
// in case we have more outputs than inputs, we'll clear any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
{
buffer.clear (i, 0, buffer.getNumSamples());
}
}
示例5: readFromInputDevice
bool readFromInputDevice (AudioSampleBuffer& inputChannelBuffer, const int numSamples)
{
jassert (numChannelsRunning <= inputChannelBuffer.getNumChannels());
float** const data = inputChannelBuffer.getArrayOfChannels();
if (isInterleaved)
{
scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
scratch.fillWith (0); // (not clearing this data causes warnings in valgrind)
snd_pcm_sframes_t num = snd_pcm_readi (handle, scratch.getData(), numSamples);
if (failed (num))
{
if (num == -EPIPE)
{
if (failed (snd_pcm_prepare (handle)))
return false;
}
else if (num != -ESTRPIPE)
return false;
}
for (int i = 0; i < numChannelsRunning; ++i)
converter->convertSamples (data[i], 0, scratch.getData(), i, numSamples);
}
else
{
snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
return false;
for (int i = 0; i < numChannelsRunning; ++i)
converter->convertSamples (data[i], data[i], numSamples);
}
return true;
}
示例6: writeToOutputDevice
//==============================================================================
bool writeToOutputDevice (AudioSampleBuffer& outputChannelBuffer, const int numSamples)
{
jassert (numChannelsRunning <= outputChannelBuffer.getNumChannels());
float** const data = outputChannelBuffer.getArrayOfChannels();
snd_pcm_sframes_t numDone = 0;
if (isInterleaved)
{
scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
for (int i = 0; i < numChannelsRunning; ++i)
converter->convertSamples (scratch.getData(), i, data[i], 0, numSamples);
numDone = snd_pcm_writei (handle, scratch.getData(), numSamples);
}
else
{
for (int i = 0; i < numChannelsRunning; ++i)
converter->convertSamples (data[i], data[i], numSamples);
numDone = snd_pcm_writen (handle, (void**) data, numSamples);
}
if (failed (numDone))
{
if (numDone == -EPIPE)
{
if (failed (snd_pcm_prepare (handle)))
return false;
}
else if (numDone != -ESTRPIPE)
return false;
}
return true;
}
示例7: readMaxLevels
void AudioFormatReader::readMaxLevels (int64 startSampleInFile, int64 numSamples,
float& lowestLeft, float& highestLeft,
float& lowestRight, float& highestRight)
{
if (numSamples <= 0)
{
lowestLeft = 0;
lowestRight = 0;
highestLeft = 0;
highestRight = 0;
return;
}
const int bufferSize = (int) jmin (numSamples, (int64) 4096);
AudioSampleBuffer tempSampleBuffer (numChannels, bufferSize);
float** const floatBuffer = tempSampleBuffer.getArrayOfChannels();
int* const* intBuffer = reinterpret_cast<int* const*> (floatBuffer);
if (usesFloatingPointData)
{
float lmin = 1.0e6f;
float lmax = -lmin;
float rmin = lmin;
float rmax = lmax;
while (numSamples > 0)
{
const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
if (! read (intBuffer, 2, startSampleInFile, numToDo, false))
break;
numSamples -= numToDo;
startSampleInFile += numToDo;
getStereoMinAndMax (floatBuffer, numChannels, numToDo, lmin, lmax, rmin, rmax);
}
lowestLeft = lmin;
highestLeft = lmax;
lowestRight = rmin;
highestRight = rmax;
}
else
{
int lmax = std::numeric_limits<int>::min();
int lmin = std::numeric_limits<int>::max();
int rmax = std::numeric_limits<int>::min();
int rmin = std::numeric_limits<int>::max();
while (numSamples > 0)
{
const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
if (! read (intBuffer, 2, startSampleInFile, numToDo, false))
break;
numSamples -= numToDo;
startSampleInFile += numToDo;
getStereoMinAndMax (intBuffer, numChannels, numToDo, lmin, lmax, rmin, rmax);
}
lowestLeft = lmin / (float) std::numeric_limits<int>::max();
highestLeft = lmax / (float) std::numeric_limits<int>::max();
lowestRight = rmin / (float) std::numeric_limits<int>::max();
highestRight = rmax / (float) std::numeric_limits<int>::max();
}
}