long cubeb_client::user_data_cb()

in tools/cubeb-test.cpp [302:342]


long cubeb_client::user_data_cb(cubeb_stream* stm, void* user,
                                const void* input_buffer, void* output_buffer,
                                long nframes) {
  if (input_buffer && output_buffer) {
    const float* in = static_cast<const float*>(input_buffer);
    float* out = static_cast<float*>(output_buffer);
    if (_latency_testing) {
      for (int32_t i = 0; i < nframes; i++) {
        // Impulses every second, mixed with the input signal fed back at half
        // gain, to measure the input-to-output latency via feedback.
        uint32_t clock = ((_total_frames + i) % _rate);
        if (!clock) {
          for (uint32_t j = 0; j < _channels; j++) {
            out[i * _channels + j] = 1.0 + in[i] * 0.5;
          }
        } else {
          for (uint32_t j = 0; j < _channels; j++) {
            out[i * _channels + j] = 0.0 + in[i] * 0.5;
          }
        }
      }
    } else {
      for (int32_t i = 0; i < nframes; i++) {
        for (uint32_t j = 0; j < _channels; j++) {
          out[i * _channels + j] = in[i];
        }
      }
    }
  } else if (output_buffer && !input_buffer) {
    fill_with_sine_tone(static_cast<float*>(output_buffer), nframes, _channels,
                       _rate, _total_frames);
  }

  _total_frames += nframes;

  if (_force_drain) {
    return nframes - 1;
  }

  return nframes;
}