コード例 #1
0
ファイル: jacklayer.cpp プロジェクト: alexzah/ring-daemon
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
0
ファイル: jacklayer.cpp プロジェクト: alexzah/ring-daemon
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);
    }
}