本文整理汇总了C++中AudioBuffer::getChannel方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioBuffer::getChannel方法的具体用法?C++ AudioBuffer::getChannel怎么用?C++ AudioBuffer::getChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioBuffer
的用法示例。
在下文中一共展示了AudioBuffer::getChannel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
void
JackLayer::read(AudioBuffer &buffer)
{
for (unsigned i = 0; i < in_ringbuffers_.size(); ++i) {
const size_t incomingSamples = jack_ringbuffer_read_space(in_ringbuffers_[i]) / sizeof(captureFloatBuffer_[0]);
if (!incomingSamples)
continue;
captureFloatBuffer_.resize(incomingSamples);
buffer.resize(incomingSamples);
// write to output
const size_t from_ringbuffer = jack_ringbuffer_read_space(in_ringbuffers_[i]);
const size_t expected_bytes = std::min(incomingSamples * sizeof(captureFloatBuffer_[0]), from_ringbuffer);
// FIXME: while we have samples to write AND while we have space to write them
const size_t read_bytes = jack_ringbuffer_read(in_ringbuffers_[i],
(char *) captureFloatBuffer_.data(), expected_bytes);
if (read_bytes < expected_bytes) {
RING_WARN("Dropped %zu bytes", expected_bytes - read_bytes);
break;
}
/* Write the data one frame at a time. This is
* inefficient, but makes things simpler. */
// FIXME: this is braindead, we should write blocks of samples at a time
// convert a vector of samples from 1 channel to a float vector
convertFromFloat(captureFloatBuffer_, *buffer.getChannel(i));
}
}
示例2: convertToFloat
void
JackLayer::write(AudioBuffer &buffer, std::vector<float> &floatBuffer)
{
for (unsigned i = 0; i < out_ringbuffers_.size(); ++i) {
const unsigned inChannel = std::min(i, buffer.channels() - 1);
convertToFloat(*buffer.getChannel(inChannel), floatBuffer);
// write to output
const size_t to_ringbuffer = jack_ringbuffer_write_space(out_ringbuffers_[i]);
const size_t write_bytes = std::min(buffer.frames() * sizeof(floatBuffer[0]), to_ringbuffer);
// FIXME: while we have samples to write AND while we have space to write them
const size_t written_bytes = jack_ringbuffer_write(out_ringbuffers_[i],
(const char *) floatBuffer.data(), write_bytes);
if (written_bytes < write_bytes)
RING_WARN("Dropped %zu bytes for channel %u", write_bytes - written_bytes, i);
}
}