This example shows how to create a duplex stream that pipes the microphone to the speakers, with minimal latency and the proper sample-rate for the platform.
cubeb_init(&app_ctx,
"Example Application", NULL);
int rv;
uint32_t rate;
uint32_t latency_frames;
uint64_t ts;
fprintf(stderr, "Could not get preferred sample-rate");
return rv;
}
output_params.
format = CUBEB_SAMPLE_FLOAT32NE;
output_params.
rate = rate;
output_params.
layout = CUBEB_LAYOUT_UNDEFINED;
fprintf(stderr, "Could not get minimum latency");
return rv;
}
input_params.
format = CUBEB_SAMPLE_FLOAT32NE;
input_params.
rate = rate;
input_params.
layout = CUBEB_LAYOUT_UNDEFINED;
NULL, &input_params,
NULL, &output_params,
latency_frames,
data_cb, state_cb,
NULL);
fprintf(stderr, "Could not open the stream");
return rv;
}
fprintf(stderr, "Could not start the stream");
return rv;
}
for (;;) {
printf("time=%llu\n", ts);
sleep(1);
}
fprintf(stderr, "Could not stop the stream");
return rv;
}
CUBEB_EXPORT int cubeb_get_preferred_sample_rate(cubeb *context, uint32_t *rate)
Get the preferred sample rate for this backend: this is hardware and platform dependent,...
struct cubeb cubeb
Opaque handle referencing the application state.
Definition cubeb.h:125
CUBEB_EXPORT int cubeb_stream_start(cubeb_stream *stream)
Start playback.
CUBEB_EXPORT int cubeb_stream_init(cubeb *context, cubeb_stream **stream, char const *stream_name, cubeb_devid input_device, cubeb_stream_params *input_stream_params, cubeb_devid output_device, cubeb_stream_params *output_stream_params, uint32_t latency_frames, cubeb_data_callback data_callback, cubeb_state_callback state_callback, void *user_ptr)
Initialize a stream associated with the supplied application context.
@ CUBEB_STREAM_PREF_NONE
No stream preferences are requested.
Definition cubeb.h:233
CUBEB_EXPORT int cubeb_init(cubeb **context, char const *context_name, char const *backend_name)
Initialize an application context.
struct cubeb_stream cubeb_stream
Opaque handle referencing the stream state.
Definition cubeb.h:127
CUBEB_EXPORT int cubeb_stream_stop(cubeb_stream *stream)
Stop playback.
CUBEB_EXPORT int cubeb_stream_get_position(cubeb_stream *stream, uint64_t *position)
Get the current stream playback position.
CUBEB_EXPORT void cubeb_stream_destroy(cubeb_stream *stream)
Destroy a stream.
@ CUBEB_OK
Success.
Definition cubeb.h:304
CUBEB_EXPORT void cubeb_destroy(cubeb *context)
Destroy an application context.
CUBEB_EXPORT int cubeb_get_min_latency(cubeb *context, cubeb_stream_params *params, uint32_t *latency_frames)
Get the minimal latency value, in frames, that is guaranteed to work when creating a stream for the s...
Stream format initialization parameters.
Definition cubeb.h:274
cubeb_sample_format format
Requested sample format.
Definition cubeb.h:275
cubeb_channel_layout layout
Requested channel layout.
Definition cubeb.h:280
cubeb_stream_prefs prefs
Requested preferences.
Definition cubeb.h:282
uint32_t rate
Requested sample rate.
Definition cubeb.h:277
uint32_t channels
Requested channel count.
Definition cubeb.h:278
const void * input_buffer, void * output_buffer, long nframes)
{
const float * in = input_buffer;
float * out = output_buffer;
for (int i = 0; i < nframes; ++i) {
for (int c = 0; c < 2; ++c) {
out[2 * i + c] = in[i];
}
}
return nframes;
}