本文整理汇总了C++中AudioBuffer::getChannelData方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioBuffer::getChannelData方法的具体用法?C++ AudioBuffer::getChannelData怎么用?C++ AudioBuffer::getChannelData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioBuffer
的用法示例。
在下文中一共展示了AudioBuffer::getChannelData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void JavaScriptAudioNode::process(size_t framesToProcess)
{
// Discussion about inputs and outputs:
// As in other AudioNodes, JavaScriptAudioNode uses an AudioBus for its input and output (see inputBus and outputBus below).
// Additionally, there is a double-buffering for input and output which is exposed directly to JavaScript (see inputBuffer and outputBuffer below).
// This node is the producer for inputBuffer and the consumer for outputBuffer.
// The JavaScript code is the consumer of inputBuffer and the producer for outputBuffer.
// Get input and output busses.
AudioBus* inputBus = this->input(0)->bus();
AudioBus* outputBus = this->output(0)->bus();
// Get input and output buffers. We double-buffer both the input and output sides.
unsigned doubleBufferIndex = this->doubleBufferIndex();
bool isDoubleBufferIndexGood = doubleBufferIndex < 2 && doubleBufferIndex < m_inputBuffers.size() && doubleBufferIndex < m_outputBuffers.size();
ASSERT(isDoubleBufferIndexGood);
if (!isDoubleBufferIndexGood)
return;
AudioBuffer* inputBuffer = m_inputBuffers[doubleBufferIndex].get();
AudioBuffer* outputBuffer = m_outputBuffers[doubleBufferIndex].get();
// Check the consistency of input and output buffers.
unsigned numberOfInputChannels = m_internalInputBus.numberOfChannels();
bool buffersAreGood = outputBuffer && bufferSize() == outputBuffer->length() && m_bufferReadWriteIndex + framesToProcess <= bufferSize();
// If the number of input channels is zero, it's ok to have inputBuffer = 0.
if (m_internalInputBus.numberOfChannels())
buffersAreGood = buffersAreGood && inputBuffer && bufferSize() == inputBuffer->length();
ASSERT(buffersAreGood);
if (!buffersAreGood)
return;
// We assume that bufferSize() is evenly divisible by framesToProcess - should always be true, but we should still check.
bool isFramesToProcessGood = framesToProcess && bufferSize() >= framesToProcess && !(bufferSize() % framesToProcess);
ASSERT(isFramesToProcessGood);
if (!isFramesToProcessGood)
return;
unsigned numberOfOutputChannels = outputBus->numberOfChannels();
bool channelsAreGood = (numberOfInputChannels == m_numberOfInputChannels) && (numberOfOutputChannels == m_numberOfOutputChannels);
ASSERT(channelsAreGood);
if (!channelsAreGood)
return;
for (unsigned i = 0; i < numberOfInputChannels; i++)
m_internalInputBus.setChannelMemory(i, inputBuffer->getChannelData(i)->data() + m_bufferReadWriteIndex, framesToProcess);
if (numberOfInputChannels)
m_internalInputBus.copyFrom(*inputBus);
// Copy from the output buffer to the output.
for (unsigned i = 0; i < numberOfOutputChannels; ++i)
memcpy(outputBus->channel(i)->mutableData(), outputBuffer->getChannelData(i)->data() + m_bufferReadWriteIndex, sizeof(float) * framesToProcess);
// Update the buffering index.
m_bufferReadWriteIndex = (m_bufferReadWriteIndex + framesToProcess) % bufferSize();
// m_bufferReadWriteIndex will wrap back around to 0 when the current input and output buffers are full.
// When this happens, fire an event and swap buffers.
if (!m_bufferReadWriteIndex) {
// Avoid building up requests on the main thread to fire process events when they're not being handled.
// This could be a problem if the main thread is very busy doing other things and is being held up handling previous requests.
if (m_isRequestOutstanding) {
// We're late in handling the previous request. The main thread must be very busy.
// The best we can do is clear out the buffer ourself here.
outputBuffer->zero();
} else {
// Reference ourself so we don't accidentally get deleted before fireProcessEvent() gets called.
ref();
// Fire the event on the main thread, not this one (which is the realtime audio thread).
m_doubleBufferIndexForEvent = m_doubleBufferIndex;
m_isRequestOutstanding = true;
callOnMainThread(fireProcessEventDispatch, this);
}
swapBuffers();
}
}
示例2: process
void ScriptProcessorHandler::process(size_t framesToProcess)
{
// Discussion about inputs and outputs:
// As in other AudioNodes, ScriptProcessorNode uses an AudioBus for its input and output (see inputBus and outputBus below).
// Additionally, there is a double-buffering for input and output which is exposed directly to JavaScript (see inputBuffer and outputBuffer below).
// This node is the producer for inputBuffer and the consumer for outputBuffer.
// The JavaScript code is the consumer of inputBuffer and the producer for outputBuffer.
// Get input and output busses.
AudioBus* inputBus = input(0).bus();
AudioBus* outputBus = output(0).bus();
// Get input and output buffers. We double-buffer both the input and output sides.
unsigned doubleBufferIndex = this->doubleBufferIndex();
bool isDoubleBufferIndexGood = doubleBufferIndex < 2 && doubleBufferIndex < m_inputBuffers.size() && doubleBufferIndex < m_outputBuffers.size();
ASSERT(isDoubleBufferIndexGood);
if (!isDoubleBufferIndexGood)
return;
AudioBuffer* inputBuffer = m_inputBuffers[doubleBufferIndex].get();
AudioBuffer* outputBuffer = m_outputBuffers[doubleBufferIndex].get();
// Check the consistency of input and output buffers.
unsigned numberOfInputChannels = m_internalInputBus->numberOfChannels();
bool buffersAreGood = outputBuffer && bufferSize() == outputBuffer->length() && m_bufferReadWriteIndex + framesToProcess <= bufferSize();
// If the number of input channels is zero, it's ok to have inputBuffer = 0.
if (m_internalInputBus->numberOfChannels())
buffersAreGood = buffersAreGood && inputBuffer && bufferSize() == inputBuffer->length();
ASSERT(buffersAreGood);
if (!buffersAreGood)
return;
// We assume that bufferSize() is evenly divisible by framesToProcess - should always be true, but we should still check.
bool isFramesToProcessGood = framesToProcess && bufferSize() >= framesToProcess && !(bufferSize() % framesToProcess);
ASSERT(isFramesToProcessGood);
if (!isFramesToProcessGood)
return;
unsigned numberOfOutputChannels = outputBus->numberOfChannels();
bool channelsAreGood = (numberOfInputChannels == m_numberOfInputChannels) && (numberOfOutputChannels == m_numberOfOutputChannels);
ASSERT(channelsAreGood);
if (!channelsAreGood)
return;
for (unsigned i = 0; i < numberOfInputChannels; ++i)
m_internalInputBus->setChannelMemory(i, inputBuffer->getChannelData(i)->data() + m_bufferReadWriteIndex, framesToProcess);
if (numberOfInputChannels)
m_internalInputBus->copyFrom(*inputBus);
// Copy from the output buffer to the output.
for (unsigned i = 0; i < numberOfOutputChannels; ++i)
memcpy(outputBus->channel(i)->mutableData(), outputBuffer->getChannelData(i)->data() + m_bufferReadWriteIndex, sizeof(float) * framesToProcess);
// Update the buffering index.
m_bufferReadWriteIndex = (m_bufferReadWriteIndex + framesToProcess) % bufferSize();
// m_bufferReadWriteIndex will wrap back around to 0 when the current input and output buffers are full.
// When this happens, fire an event and swap buffers.
if (!m_bufferReadWriteIndex) {
// Avoid building up requests on the main thread to fire process events when they're not being handled.
// This could be a problem if the main thread is very busy doing other things and is being held up handling previous requests.
// The audio thread can't block on this lock, so we call tryLock() instead.
MutexTryLocker tryLocker(m_processEventLock);
if (!tryLocker.locked()) {
// We're late in handling the previous request. The main thread must be very busy.
// The best we can do is clear out the buffer ourself here.
outputBuffer->zero();
} else if (context()->executionContext()) {
// Fire the event on the main thread, not this one (which is the realtime audio thread).
m_doubleBufferIndexForEvent = m_doubleBufferIndex;
context()->executionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&ScriptProcessorHandler::fireProcessEvent, PassRefPtr<ScriptProcessorHandler>(this)));
}
swapBuffers();
}
}
示例3: process
void ScriptProcessorHandler::process(size_t framesToProcess) {
// Discussion about inputs and outputs:
// As in other AudioNodes, ScriptProcessorNode uses an AudioBus for its input
// and output (see inputBus and outputBus below). Additionally, there is a
// double-buffering for input and output which is exposed directly to
// JavaScript (see inputBuffer and outputBuffer below). This node is the
// producer for inputBuffer and the consumer for outputBuffer. The JavaScript
// code is the consumer of inputBuffer and the producer for outputBuffer.
// Get input and output busses.
AudioBus* inputBus = input(0).bus();
AudioBus* outputBus = output(0).bus();
// Get input and output buffers. We double-buffer both the input and output
// sides.
unsigned doubleBufferIndex = this->doubleBufferIndex();
bool isDoubleBufferIndexGood = doubleBufferIndex < 2 &&
doubleBufferIndex < m_inputBuffers.size() &&
doubleBufferIndex < m_outputBuffers.size();
DCHECK(isDoubleBufferIndexGood);
if (!isDoubleBufferIndexGood)
return;
AudioBuffer* inputBuffer = m_inputBuffers[doubleBufferIndex].get();
AudioBuffer* outputBuffer = m_outputBuffers[doubleBufferIndex].get();
// Check the consistency of input and output buffers.
unsigned numberOfInputChannels = m_internalInputBus->numberOfChannels();
bool buffersAreGood =
outputBuffer && bufferSize() == outputBuffer->length() &&
m_bufferReadWriteIndex + framesToProcess <= bufferSize();
// If the number of input channels is zero, it's ok to have inputBuffer = 0.
if (m_internalInputBus->numberOfChannels())
buffersAreGood =
buffersAreGood && inputBuffer && bufferSize() == inputBuffer->length();
DCHECK(buffersAreGood);
if (!buffersAreGood)
return;
// We assume that bufferSize() is evenly divisible by framesToProcess - should
// always be true, but we should still check.
bool isFramesToProcessGood = framesToProcess &&
bufferSize() >= framesToProcess &&
!(bufferSize() % framesToProcess);
DCHECK(isFramesToProcessGood);
if (!isFramesToProcessGood)
return;
unsigned numberOfOutputChannels = outputBus->numberOfChannels();
bool channelsAreGood = (numberOfInputChannels == m_numberOfInputChannels) &&
(numberOfOutputChannels == m_numberOfOutputChannels);
DCHECK(channelsAreGood);
if (!channelsAreGood)
return;
for (unsigned i = 0; i < numberOfInputChannels; ++i)
m_internalInputBus->setChannelMemory(
i, inputBuffer->getChannelData(i)->data() + m_bufferReadWriteIndex,
framesToProcess);
if (numberOfInputChannels)
m_internalInputBus->copyFrom(*inputBus);
// Copy from the output buffer to the output.
for (unsigned i = 0; i < numberOfOutputChannels; ++i)
memcpy(outputBus->channel(i)->mutableData(),
outputBuffer->getChannelData(i)->data() + m_bufferReadWriteIndex,
sizeof(float) * framesToProcess);
// Update the buffering index.
m_bufferReadWriteIndex =
(m_bufferReadWriteIndex + framesToProcess) % bufferSize();
// m_bufferReadWriteIndex will wrap back around to 0 when the current input
// and output buffers are full.
// When this happens, fire an event and swap buffers.
if (!m_bufferReadWriteIndex) {
// Avoid building up requests on the main thread to fire process events when
// they're not being handled. This could be a problem if the main thread is
// very busy doing other things and is being held up handling previous
// requests. The audio thread can't block on this lock, so we call
// tryLock() instead.
MutexTryLocker tryLocker(m_processEventLock);
if (!tryLocker.locked()) {
// We're late in handling the previous request. The main thread must be
// very busy. The best we can do is clear out the buffer ourself here.
outputBuffer->zero();
} else if (context()->getExecutionContext()) {
// With the realtime context, execute the script code asynchronously
// and do not wait.
if (context()->hasRealtimeConstraint()) {
// Fire the event on the main thread with the appropriate buffer
// index.
context()->getExecutionContext()->postTask(
BLINK_FROM_HERE,
createCrossThreadTask(&ScriptProcessorHandler::fireProcessEvent,
crossThreadUnretained(this),
//.........这里部分代码省略.........