aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--test/common.h70
-rw-r--r--test/test_audio.cpp156
-rw-r--r--test/test_callback_ret.cpp118
-rw-r--r--test/test_deadlock.cpp87
-rw-r--r--test/test_device_changed_callback.cpp41
-rw-r--r--test/test_devices.cpp156
-rw-r--r--test/test_duplex.cpp117
-rw-r--r--test/test_latency.cpp22
-rw-r--r--test/test_loopback.cpp323
-rw-r--r--test/test_overload_callback.cpp41
-rw-r--r--test/test_record.cpp57
-rw-r--r--test/test_resampler.cpp613
-rw-r--r--test/test_ring_array.cpp27
-rw-r--r--test/test_ring_buffer.cpp126
-rw-r--r--test/test_sanity.cpp87
-rw-r--r--test/test_tone.cpp58
-rw-r--r--test/test_utils.cpp6
17 files changed, 1174 insertions, 931 deletions
diff --git a/test/common.h b/test/common.h
index 76d318c..ad464a4 100644
--- a/test/common.h
+++ b/test/common.h
@@ -7,7 +7,7 @@
#if !defined(TEST_COMMON)
#define TEST_COMMON
-#if defined( _WIN32)
+#if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@@ -17,18 +17,19 @@
#include <unistd.h>
#endif
-#include <cstdarg>
#include "cubeb/cubeb.h"
#include "cubeb_mixer.h"
+#include <cstdarg>
-template<typename T, size_t N>
+template <typename T, size_t N>
constexpr size_t
-ARRAY_LENGTH(T(&)[N])
+ARRAY_LENGTH(T (&)[N])
{
return N;
}
-inline void delay(unsigned int ms)
+inline void
+delay(unsigned int ms)
{
#if defined(_WIN32)
Sleep(ms);
@@ -49,33 +50,24 @@ typedef struct {
} layout_info;
struct backend_caps {
- const char* id;
+ const char * id;
const int input_capabilities;
};
-
// This static table allows knowing if a backend has audio input capabilities.
// We don't rely on opening a stream and checking if it works, because this
// would make the test skip the tests that make use of audio input, if a
// particular backend has a bug that causes a failure during audio input stream
-// creation
+// creation
static backend_caps backend_capabilities[] = {
- {"sun", 1},
- {"wasapi", 1},
- {"kai", 1},
- {"audiounit", 1},
- {"audiotrack", 0},
- {"opensl", 1},
- {"aaudio", 1},
- {"jack", 1},
- {"pulse", 1},
- {"sndio", 1},
- {"oss", 1},
- {"winmm", 0},
- {"alsa", 1},
+ {"sun", 1}, {"wasapi", 1}, {"kai", 1}, {"audiounit", 1},
+ {"audiotrack", 0}, {"opensl", 1}, {"aaudio", 1}, {"jack", 1},
+ {"pulse", 1}, {"sndio", 1}, {"oss", 1}, {"winmm", 0},
+ {"alsa", 1},
};
-inline int can_run_audio_input_test(cubeb * ctx)
+inline int
+can_run_audio_input_test(cubeb * ctx)
{
cubeb_device_collection devices;
int input_device_available = 0;
@@ -94,29 +86,32 @@ inline int can_run_audio_input_test(cubeb * ctx)
}
for (uint32_t i = 0; i < devices.count; i++) {
- input_device_available |= (devices.device[i].state ==
- CUBEB_DEVICE_STATE_ENABLED);
+ input_device_available |=
+ (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED);
}
if (!input_device_available) {
fprintf(stderr, "there are input devices, but they are not "
- "available, skipping\n");
+ "available, skipping\n");
}
cubeb_device_collection_destroy(ctx, &devices);
int backend_has_input_capabilities;
const char * backend_id = cubeb_get_backend_id(ctx);
- for (uint32_t i = 0; i < sizeof(backend_capabilities) / sizeof(backend_caps); i++) {
+ for (uint32_t i = 0; i < sizeof(backend_capabilities) / sizeof(backend_caps);
+ i++) {
if (strcmp(backend_capabilities[i].id, backend_id) == 0) {
- backend_has_input_capabilities = backend_capabilities[i].input_capabilities;
+ backend_has_input_capabilities =
+ backend_capabilities[i].input_capabilities;
}
}
return !!input_device_available && !!backend_has_input_capabilities;
}
-inline void print_log(const char * msg, ...)
+inline void
+print_log(const char * msg, ...)
{
va_list args;
va_start(args, msg);
@@ -127,7 +122,8 @@ inline void print_log(const char * msg, ...)
/** Initialize cubeb with backend override.
* Create call cubeb_init passing value for CUBEB_BACKEND env var as
* override. */
-inline int common_init(cubeb ** ctx, char const * ctx_name)
+inline int
+common_init(cubeb ** ctx, char const * ctx_name)
{
#ifdef ENABLE_NORMAL_LOG
if (cubeb_set_log_callback(CUBEB_LOG_NORMAL, print_log) != CUBEB_OK) {
@@ -150,22 +146,21 @@ inline int common_init(cubeb ** ctx, char const * ctx_name)
if (r == CUBEB_OK && backend) {
ctx_backend = cubeb_get_backend_id(*ctx);
if (strcmp(backend, ctx_backend) != 0) {
- fprintf(stderr, "Requested backend `%s', got `%s'\n",
- backend, ctx_backend);
+ fprintf(stderr, "Requested backend `%s', got `%s'\n", backend,
+ ctx_backend);
}
}
return r;
}
-#if defined( _WIN32)
+#if defined(_WIN32)
class TestEnvironment : public ::testing::Environment {
public:
- void SetUp() override {
- hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
- }
+ void SetUp() override { hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); }
- void TearDown() override {
+ void TearDown() override
+ {
if (SUCCEEDED(hr)) {
CoUninitialize();
}
@@ -175,7 +170,8 @@ private:
HRESULT hr;
};
-::testing::Environment* const foo_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment);
+::testing::Environment * const foo_env =
+ ::testing::AddGlobalTestEnvironment(new TestEnvironment);
#endif
#endif /* TEST_COMMON */
diff --git a/test/test_audio.cpp b/test/test_audio.cpp
index bc4b435..7c99a18 100644
--- a/test/test_audio.cpp
+++ b/test/test_audio.cpp
@@ -11,16 +11,16 @@
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <stdio.h>
-#include <stdlib.h>
+#include "cubeb/cubeb.h"
#include <math.h>
#include <memory>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include "cubeb/cubeb.h"
#include <string>
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
using namespace std;
@@ -28,37 +28,49 @@ using namespace std;
#define MAX_NUM_CHANNELS 32
#define VOLUME 0.2
-float get_frequency(int channel_index)
+float
+get_frequency(int channel_index)
{
- return 220.0f * (channel_index+1);
+ return 220.0f * (channel_index + 1);
}
-template<typename T> T ConvertSample(double input);
-template<> float ConvertSample(double input) { return input; }
-template<> short ConvertSample(double input) { return short(input * 32767.0f); }
+template <typename T>
+T
+ConvertSample(double input);
+template <>
+float
+ConvertSample(double input)
+{
+ return input;
+}
+template <>
+short
+ConvertSample(double input)
+{
+ return short(input * 32767.0f);
+}
/* store the phase of the generated waveform */
struct synth_state {
synth_state(int num_channels_, float sample_rate_)
- : num_channels(num_channels_),
- sample_rate(sample_rate_)
+ : num_channels(num_channels_), sample_rate(sample_rate_)
{
- for(int i=0;i < MAX_NUM_CHANNELS;++i)
+ for (int i = 0; i < MAX_NUM_CHANNELS; ++i)
phase[i] = 0.0f;
}
- template<typename T>
- void run(T* audiobuffer, long nframes)
- {
- for(int c=0;c < num_channels;++c) {
- float freq = get_frequency(c);
- float phase_inc = 2.0 * M_PI * freq / sample_rate;
- for(long n=0;n < nframes;++n) {
- audiobuffer[n*num_channels+c] = ConvertSample<T>(sin(phase[c]) * VOLUME);
- phase[c] += phase_inc;
- }
+ template <typename T> void run(T * audiobuffer, long nframes)
+ {
+ for (int c = 0; c < num_channels; ++c) {
+ float freq = get_frequency(c);
+ float phase_inc = 2.0 * M_PI * freq / sample_rate;
+ for (long n = 0; n < nframes; ++n) {
+ audiobuffer[n * num_channels + c] =
+ ConvertSample<T>(sin(phase[c]) * VOLUME);
+ phase[c] += phase_inc;
}
}
+ }
private:
int num_channels;
@@ -66,45 +78,51 @@ private:
float sample_rate;
};
-template<typename T>
-long data_cb(cubeb_stream * /*stream*/, void * user, const void * /*inputbuffer*/, void * outputbuffer, long nframes)
+template <typename T>
+long
+data_cb(cubeb_stream * /*stream*/, void * user, const void * /*inputbuffer*/,
+ void * outputbuffer, long nframes)
{
- synth_state *synth = (synth_state *)user;
- synth->run((T*)outputbuffer, nframes);
+ synth_state * synth = (synth_state *)user;
+ synth->run((T *)outputbuffer, nframes);
return nframes;
}
-void state_cb_audio(cubeb_stream * /*stream*/, void * /*user*/, cubeb_state /*state*/)
+void
+state_cb_audio(cubeb_stream * /*stream*/, void * /*user*/,
+ cubeb_state /*state*/)
{
}
/* Our android backends don't support float, only int16. */
-int supports_float32(string backend_id)
+int
+supports_float32(string backend_id)
{
- return backend_id != "opensl"
- && backend_id != "audiotrack";
+ return backend_id != "opensl" && backend_id != "audiotrack";
}
/* Some backends don't have code to deal with more than mono or stereo. */
-int supports_channel_count(string backend_id, int nchannels)
+int
+supports_channel_count(string backend_id, int nchannels)
{
return nchannels <= 2 ||
- (backend_id != "opensl" && backend_id != "audiotrack");
+ (backend_id != "opensl" && backend_id != "audiotrack");
}
-int run_test(int num_channels, int sampling_rate, int is_float)
+int
+run_test(int num_channels, int sampling_rate, int is_float)
{
int r = CUBEB_OK;
- cubeb *ctx = NULL;
+ cubeb * ctx = NULL;
r = common_init(&ctx, "Cubeb audio test: channels");
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb library\n");
return r;
}
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
const char * backend_id = cubeb_get_backend_id(ctx);
@@ -114,7 +132,9 @@ int run_test(int num_channels, int sampling_rate, int is_float)
return CUBEB_OK;
}
- fprintf(stderr, "Testing %d channel(s), %d Hz, %s (%s)\n", num_channels, sampling_rate, is_float ? "float" : "short", cubeb_get_backend_id(ctx));
+ fprintf(stderr, "Testing %d channel(s), %d Hz, %s (%s)\n", num_channels,
+ sampling_rate, is_float ? "float" : "short",
+ cubeb_get_backend_id(ctx));
cubeb_stream_params params;
params.format = is_float ? CUBEB_SAMPLE_FLOAT32NE : CUBEB_SAMPLE_S16NE;
@@ -125,16 +145,17 @@ int run_test(int num_channels, int sampling_rate, int is_float)
synth_state synth(params.channels, params.rate);
- cubeb_stream *stream = NULL;
+ cubeb_stream * stream = NULL;
r = cubeb_stream_init(ctx, &stream, "test tone", NULL, NULL, NULL, &params,
- 4096, is_float ? &data_cb<float> : &data_cb<short>, state_cb_audio, &synth);
+ 4096, is_float ? &data_cb<float> : &data_cb<short>,
+ state_cb_audio, &synth);
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb stream: %d\n", r);
return r;
}
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_stream_start(stream);
delay(200);
@@ -143,11 +164,12 @@ int run_test(int num_channels, int sampling_rate, int is_float)
return r;
}
-int run_volume_test(int is_float)
+int
+run_volume_test(int is_float)
{
int r = CUBEB_OK;
- cubeb *ctx = NULL;
+ cubeb * ctx = NULL;
r = common_init(&ctx, "Cubeb audio test");
if (r != CUBEB_OK) {
@@ -155,8 +177,8 @@ int run_volume_test(int is_float)
return r;
}
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
const char * backend_id = cubeb_get_backend_id(ctx);
@@ -174,24 +196,23 @@ int run_volume_test(int is_float)
synth_state synth(params.channels, params.rate);
- cubeb_stream *stream = NULL;
+ cubeb_stream * stream = NULL;
r = cubeb_stream_init(ctx, &stream, "test tone", NULL, NULL, NULL, &params,
- 4096, is_float ? &data_cb<float> : &data_cb<short>,
- state_cb_audio, &synth);
+ 4096, is_float ? &data_cb<float> : &data_cb<short>,
+ state_cb_audio, &synth);
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb stream: %d\n", r);
return r;
}
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
fprintf(stderr, "Testing: volume\n");
- for(int i=0;i <= 4; ++i)
- {
- fprintf(stderr, "Volume: %d%%\n", i*25);
+ for (int i = 0; i <= 4; ++i) {
+ fprintf(stderr, "Volume: %d%%\n", i * 25);
- cubeb_stream_set_volume(stream, i/4.0f);
+ cubeb_stream_set_volume(stream, i / 4.0f);
cubeb_stream_start(stream);
delay(400);
cubeb_stream_stop(stream);
@@ -201,35 +222,25 @@ int run_volume_test(int is_float)
return r;
}
-TEST(cubeb, run_volume_test_short)
-{
- ASSERT_EQ(run_volume_test(0), CUBEB_OK);
-}
+TEST(cubeb, run_volume_test_short) { ASSERT_EQ(run_volume_test(0), CUBEB_OK); }
-TEST(cubeb, run_volume_test_float)
-{
- ASSERT_EQ(run_volume_test(1), CUBEB_OK);
-}
+TEST(cubeb, run_volume_test_float) { ASSERT_EQ(run_volume_test(1), CUBEB_OK); }
TEST(cubeb, run_channel_rate_test)
{
unsigned int channel_values[] = {
- 1,
- 2,
- 3,
- 4,
- 6,
+ 1, 2, 3, 4, 6,
};
int freq_values[] = {
- 16000,
- 24000,
- 44100,
- 48000,
+ 16000,
+ 24000,
+ 44100,
+ 48000,
};
- for(auto channels : channel_values) {
- for(auto freq : freq_values) {
+ for (auto channels : channel_values) {
+ for (auto freq : freq_values) {
ASSERT_TRUE(channels < MAX_NUM_CHANNELS);
fprintf(stderr, "--------------------------\n");
ASSERT_EQ(run_test(channels, freq, 0), CUBEB_OK);
@@ -238,6 +249,5 @@ TEST(cubeb, run_channel_rate_test)
}
}
-
#undef MAX_NUM_CHANNELS
#undef VOLUME
diff --git a/test/test_callback_ret.cpp b/test/test_callback_ret.cpp
index 49676f7..a9d9a40 100644
--- a/test/test_callback_ret.cpp
+++ b/test/test_callback_ret.cpp
@@ -1,9 +1,9 @@
/*
-* Copyright � 2017 Mozilla Foundation
-*
-* This program is made available under an ISC-style license. See the
-* accompanying file LICENSE for details.
-*/
+ * Copyright � 2017 Mozilla Foundation
+ *
+ * This program is made available under an ISC-style license. See the
+ * accompanying file LICENSE for details.
+ */
/* libcubeb api/function test. Test that different return values from user
specified callbacks are handled correctly. */
@@ -11,36 +11,34 @@
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <memory>
+#include "cubeb/cubeb.h"
#include <atomic>
+#include <memory>
#include <string>
-#include "cubeb/cubeb.h"
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
const uint32_t SAMPLE_FREQUENCY = 48000;
const cubeb_sample_format SAMPLE_FORMAT = CUBEB_SAMPLE_S16NE;
-enum test_direction {
- INPUT_ONLY,
- OUTPUT_ONLY,
- DUPLEX
-};
+enum test_direction { INPUT_ONLY, OUTPUT_ONLY, DUPLEX };
// Structure which is used by data callbacks to track the total callbacks
// executed vs the number of callbacks expected.
struct user_state_callback_ret {
- std::atomic<int> cb_count{ 0 };
- std::atomic<int> expected_cb_count{ 0 };
- std::atomic<int> error_state{ 0 };
+ std::atomic<int> cb_count{0};
+ std::atomic<int> expected_cb_count{0};
+ std::atomic<int> error_state{0};
};
// Data callback that always returns 0
-long data_cb_ret_zero(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+long
+data_cb_ret_zero(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
- user_state_callback_ret * u = (user_state_callback_ret *) user;
+ user_state_callback_ret * u = (user_state_callback_ret *)user;
// If this is the first time the callback has been called set our expected
// callback count
if (u->cb_count == 0) {
@@ -55,7 +53,10 @@ long data_cb_ret_zero(cubeb_stream * stream, void * user, const void * inputbuff
}
// Data callback that always returns nframes - 1
-long data_cb_ret_nframes_minus_one(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+long
+data_cb_ret_nframes_minus_one(cubeb_stream * stream, void * user,
+ const void * inputbuffer, void * outputbuffer,
+ long nframes)
{
user_state_callback_ret * u = (user_state_callback_ret *)user;
// If this is the first time the callback has been called set our expected
@@ -70,7 +71,7 @@ long data_cb_ret_nframes_minus_one(cubeb_stream * stream, void * user, const voi
}
if (outputbuffer != NULL) {
// If we have an output buffer insert silence
- short * ob = (short *) outputbuffer;
+ short * ob = (short *)outputbuffer;
for (long i = 0; i < nframes - 1; i++) {
ob[i] = 0;
}
@@ -79,7 +80,9 @@ long data_cb_ret_nframes_minus_one(cubeb_stream * stream, void * user, const voi
}
// Data callback that always returns nframes
-long data_cb_ret_nframes(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+long
+data_cb_ret_nframes(cubeb_stream * stream, void * user,
+ const void * inputbuffer, void * outputbuffer, long nframes)
{
user_state_callback_ret * u = (user_state_callback_ret *)user;
u->cb_count++;
@@ -91,7 +94,7 @@ long data_cb_ret_nframes(cubeb_stream * stream, void * user, const void * inputb
}
if (outputbuffer != NULL) {
// If we have an output buffer insert silence
- short * ob = (short *) outputbuffer;
+ short * ob = (short *)outputbuffer;
for (long i = 0; i < nframes; i++) {
ob[i] = 0;
}
@@ -102,7 +105,7 @@ long data_cb_ret_nframes(cubeb_stream * stream, void * user, const void * inputb
// Data callback that always returns CUBEB_ERROR
long
data_cb_ret_error(cubeb_stream * stream, void * user, const void * inputbuffer,
- void * outputbuffer, long nframes)
+ void * outputbuffer, long nframes)
{
user_state_callback_ret * u = (user_state_callback_ret *)user;
// If this is the first time the callback has been called set our expected
@@ -118,7 +121,8 @@ data_cb_ret_error(cubeb_stream * stream, void * user, const void * inputbuffer,
return CUBEB_ERROR;
}
-void state_cb_ret(cubeb_stream * stream, void * user, cubeb_state state)
+void
+state_cb_ret(cubeb_stream * stream, void * user, cubeb_state state)
{
if (stream == NULL)
return;
@@ -126,11 +130,14 @@ void state_cb_ret(cubeb_stream * stream, void * user, cubeb_state state)
switch (state) {
case CUBEB_STATE_STARTED:
- fprintf(stderr, "stream started\n"); break;
+ fprintf(stderr, "stream started\n");
+ break;
case CUBEB_STATE_STOPPED:
- fprintf(stderr, "stream stopped\n"); break;
+ fprintf(stderr, "stream stopped\n");
+ break;
case CUBEB_STATE_DRAINED:
- fprintf(stderr, "stream drained\n"); break;
+ fprintf(stderr, "stream drained\n");
+ break;
case CUBEB_STATE_ERROR:
fprintf(stderr, "stream error\n");
u->error_state.fetch_add(1);
@@ -140,9 +147,10 @@ void state_cb_ret(cubeb_stream * stream, void * user, cubeb_state state)
}
}
-void run_test_callback(test_direction direction,
- cubeb_data_callback data_cb,
- const std::string & test_desc) {
+void
+run_test_callback(test_direction direction, cubeb_data_callback data_cb,
+ const std::string & test_desc)
+{
cubeb * ctx;
cubeb_stream * stream;
cubeb_stream_params input_params;
@@ -154,13 +162,13 @@ void run_test_callback(test_direction direction,
r = common_init(&ctx, "Cubeb callback return value example");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
if ((direction == INPUT_ONLY || direction == DUPLEX) &&
!can_run_audio_input_test(ctx)) {
/* This test needs an available input device, skip it if this host does not
- * have one or if the backend doesn't implement input. */
+ * have one or if the backend doesn't implement input. */
return;
}
@@ -175,22 +183,21 @@ void run_test_callback(test_direction direction,
r = cubeb_get_min_latency(ctx, &input_params, &latency_frames);
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
- switch (direction)
- {
+ switch (direction) {
case INPUT_ONLY:
- r = cubeb_stream_init(ctx, &stream, "Cubeb callback ret input",
- NULL, &input_params, NULL, NULL,
- latency_frames, data_cb, state_cb_ret, &user_state);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb callback ret input", NULL,
+ &input_params, NULL, NULL, latency_frames, data_cb,
+ state_cb_ret, &user_state);
break;
case OUTPUT_ONLY:
- r = cubeb_stream_init(ctx, &stream, "Cubeb callback ret output",
- NULL, NULL, NULL, &output_params,
- latency_frames, data_cb, state_cb_ret, &user_state);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb callback ret output", NULL, NULL,
+ NULL, &output_params, latency_frames, data_cb,
+ state_cb_ret, &user_state);
break;
case DUPLEX:
- r = cubeb_stream_init(ctx, &stream, "Cubeb callback ret duplex",
- NULL, &input_params, NULL, &output_params,
- latency_frames, data_cb, state_cb_ret, &user_state);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb callback ret duplex", NULL,
+ &input_params, NULL, &output_params, latency_frames,
+ data_cb, state_cb_ret, &user_state);
break;
default:
ASSERT_TRUE(false) << "Unrecognized test direction!";
@@ -198,14 +205,14 @@ void run_test_callback(test_direction direction,
EXPECT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_stream_start(stream);
delay(100);
cubeb_stream_stop(stream);
- ASSERT_EQ(user_state.expected_cb_count, user_state.cb_count) <<
- "Callback called unexpected number of times for " << test_desc << "!";
+ ASSERT_EQ(user_state.expected_cb_count, user_state.cb_count)
+ << "Callback called unexpected number of times for " << test_desc << "!";
// TODO: On some test configurations, the data_callback is never called.
if (data_cb == data_cb_ret_error && user_state.cb_count != 0) {
ASSERT_EQ(user_state.error_state, 1) << "Callback expected error state";
@@ -215,8 +222,10 @@ void run_test_callback(test_direction direction,
TEST(cubeb, test_input_callback)
{
run_test_callback(INPUT_ONLY, data_cb_ret_zero, "input only, return 0");
- run_test_callback(INPUT_ONLY, data_cb_ret_nframes_minus_one, "input only, return nframes - 1");
- run_test_callback(INPUT_ONLY, data_cb_ret_nframes, "input only, return nframes");
+ run_test_callback(INPUT_ONLY, data_cb_ret_nframes_minus_one,
+ "input only, return nframes - 1");
+ run_test_callback(INPUT_ONLY, data_cb_ret_nframes,
+ "input only, return nframes");
run_test_callback(INPUT_ONLY, data_cb_ret_error,
"input only, return CUBEB_ERROR");
}
@@ -224,8 +233,10 @@ TEST(cubeb, test_input_callback)
TEST(cubeb, test_output_callback)
{
run_test_callback(OUTPUT_ONLY, data_cb_ret_zero, "output only, return 0");
- run_test_callback(OUTPUT_ONLY, data_cb_ret_nframes_minus_one, "output only, return nframes - 1");
- run_test_callback(OUTPUT_ONLY, data_cb_ret_nframes, "output only, return nframes");
+ run_test_callback(OUTPUT_ONLY, data_cb_ret_nframes_minus_one,
+ "output only, return nframes - 1");
+ run_test_callback(OUTPUT_ONLY, data_cb_ret_nframes,
+ "output only, return nframes");
run_test_callback(OUTPUT_ONLY, data_cb_ret_error,
"output only, return CUBEB_ERROR");
}
@@ -233,7 +244,8 @@ TEST(cubeb, test_output_callback)
TEST(cubeb, test_duplex_callback)
{
run_test_callback(DUPLEX, data_cb_ret_zero, "duplex, return 0");
- run_test_callback(DUPLEX, data_cb_ret_nframes_minus_one, "duplex, return nframes - 1");
+ run_test_callback(DUPLEX, data_cb_ret_nframes_minus_one,
+ "duplex, return nframes - 1");
run_test_callback(DUPLEX, data_cb_ret_nframes, "duplex, return nframes");
run_test_callback(DUPLEX, data_cb_ret_error, "duplex, return CUBEB_ERROR");
}
diff --git a/test/test_deadlock.cpp b/test/test_deadlock.cpp
index 373ba6a..8684881 100644
--- a/test/test_deadlock.cpp
+++ b/test/test_deadlock.cpp
@@ -43,18 +43,18 @@
*/
#include "gtest/gtest.h"
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
-#include "common.h" // for layout_infos
-#include "cubeb/cubeb.h" // for cubeb utils
-#include "cubeb_utils.h" // for owned_critical_section, auto_lock
-#include <iostream> // for fprintf
-#include <pthread.h> // for pthread
-#include <signal.h> // for signal
-#include <stdexcept> // for std::logic_error
-#include <string> // for std::string
-#include <unistd.h> // for sleep, usleep
-#include <atomic> // for std::atomic
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
+#include "common.h" // for layout_infos
+#include "cubeb/cubeb.h" // for cubeb utils
+#include "cubeb_utils.h" // for owned_critical_section, auto_lock
+#include <atomic> // for std::atomic
+#include <iostream> // for fprintf
+#include <pthread.h> // for pthread
+#include <signal.h> // for signal
+#include <stdexcept> // for std::logic_error
+#include <string> // for std::string
+#include <unistd.h> // for sleep, usleep
// The signal alias for calling our thread killer.
#define CALL_THREAD_KILLER SIGUSR1
@@ -64,7 +64,7 @@
bool killed = false;
// This indicator will become true when the assigned task is done.
-std::atomic<bool> task_done{ false };
+std::atomic<bool> task_done{false};
// Indicating the data callback is fired or not.
bool called = false;
@@ -72,12 +72,13 @@ bool called = false;
// Toggle to true when running data callback. Before data callback gets
// the mutex for cubeb context, it toggles back to false.
// The task to get channel layout should be executed when this is true.
-std::atomic<bool> callbacking_before_getting_context{ false };
+std::atomic<bool> callbacking_before_getting_context{false};
owned_critical_section context_mutex;
cubeb * context = nullptr;
-cubeb * get_cubeb_context_unlocked()
+cubeb *
+get_cubeb_context_unlocked()
{
if (context) {
return context;
@@ -92,21 +93,25 @@ cubeb * get_cubeb_context_unlocked()
return context;
}
-cubeb * get_cubeb_context()
+cubeb *
+get_cubeb_context()
{
auto_lock lock(context_mutex);
return get_cubeb_context_unlocked();
}
-void state_cb_audio(cubeb_stream * /*stream*/, void * /*user*/, cubeb_state /*state*/)
+void
+state_cb_audio(cubeb_stream * /*stream*/, void * /*user*/,
+ cubeb_state /*state*/)
{
}
// Fired by coreaudio's rendering mechanism. It holds a mutex shared with the
// current used AudioUnit.
-template<typename T>
-long data_cb(cubeb_stream * /*stream*/, void * /*user*/,
- const void * /*inputbuffer*/, void * outputbuffer, long nframes)
+template <typename T>
+long
+data_cb(cubeb_stream * /*stream*/, void * /*user*/,
+ const void * /*inputbuffer*/, void * outputbuffer, long nframes)
{
called = true;
@@ -137,7 +142,8 @@ long data_cb(cubeb_stream * /*stream*/, void * /*user*/,
}
// Called by wait_to_get_layout, which is run out of main thread.
-void get_preferred_channel_layout()
+void
+get_preferred_channel_layout()
{
auto_lock lock(context_mutex);
cubeb * context = get_cubeb_context_unlocked();
@@ -151,12 +157,13 @@ void get_preferred_channel_layout()
fprintf(stderr, "layout is %s\n", layout_infos[layout].name);
}
-void * wait_to_get_layout(void *)
+void *
+wait_to_get_layout(void *)
{
uint64_t tid; // Current thread id.
pthread_threadid_np(NULL, &tid);
- while(!callbacking_before_getting_context) {
+ while (!callbacking_before_getting_context) {
fprintf(stderr, "[%llu] waiting for data callback ...\n", tid);
usleep(1000); // Force to switch threads by sleeping 1 ms.
}
@@ -168,17 +175,20 @@ void * wait_to_get_layout(void *)
return NULL;
}
-void * watchdog(void * s)
+void *
+watchdog(void * s)
{
uint64_t tid; // Current thread id.
pthread_threadid_np(NULL, &tid);
- pthread_t subject = *((pthread_t *) s);
+ pthread_t subject = *((pthread_t *)s);
uint64_t stid; // task thread id.
pthread_threadid_np(subject, &stid);
unsigned int sec = 2;
- fprintf(stderr, "[%llu] sleep %d seconds before checking task for thread %llu\n", tid, sec, stid);
+ fprintf(stderr,
+ "[%llu] sleep %d seconds before checking task for thread %llu\n", tid,
+ sec, stid);
sleep(sec); // Force to switch threads.
fprintf(stderr, "[%llu] check task for thread %llu now\n", tid, stid);
@@ -190,12 +200,14 @@ void * watchdog(void * s)
// so we need to unlock it manually.
context_mutex.unlock();
}
- fprintf(stderr, "[%llu] the assigned task for thread %llu is %sdone\n", tid, stid, (task_done) ? "" : "not ");
+ fprintf(stderr, "[%llu] the assigned task for thread %llu is %sdone\n", tid,
+ stid, (task_done) ? "" : "not ");
return NULL;
}
-void thread_killer(int signal)
+void
+thread_killer(int signal)
{
ASSERT_EQ(signal, CALL_THREAD_KILLER);
fprintf(stderr, "task thread is killed!\n");
@@ -211,8 +223,8 @@ TEST(cubeb, run_deadlock_test)
cubeb * ctx = get_cubeb_context();
ASSERT_TRUE(!!ctx);
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
cubeb_stream_params params;
params.format = CUBEB_SAMPLE_FLOAT32NE;
@@ -222,24 +234,26 @@ TEST(cubeb, run_deadlock_test)
params.prefs = CUBEB_STREAM_PREF_NONE;
cubeb_stream * stream = NULL;
- int r = cubeb_stream_init(ctx, &stream, "test deadlock", NULL, NULL, NULL,
- &params, 512, &data_cb<float>, state_cb_audio, NULL);
+ int r =
+ cubeb_stream_init(ctx, &stream, "test deadlock", NULL, NULL, NULL,
+ &params, 512, &data_cb<float>, state_cb_audio, NULL);
ASSERT_EQ(r, CUBEB_OK);
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
// Install signal handler.
signal(CALL_THREAD_KILLER, thread_killer);
pthread_t subject, detector;
pthread_create(&subject, NULL, wait_to_get_layout, NULL);
- pthread_create(&detector, NULL, watchdog, (void *) &subject);
+ pthread_create(&detector, NULL, watchdog, (void *)&subject);
uint64_t stid, dtid;
pthread_threadid_np(subject, &stid);
pthread_threadid_np(detector, &dtid);
- fprintf(stderr, "task thread %llu, monitor thread %llu are created\n", stid, dtid);
+ fprintf(stderr, "task thread %llu, monitor thread %llu are created\n", stid,
+ dtid);
cubeb_stream_start(stream);
@@ -248,7 +262,8 @@ TEST(cubeb, run_deadlock_test)
ASSERT_TRUE(called);
- fprintf(stderr, "\n%sDeadlock detected!\n", (called && !task_done.load()) ? "" : "No ");
+ fprintf(stderr, "\n%sDeadlock detected!\n",
+ (called && !task_done.load()) ? "" : "No ");
// Check the task is killed by ourselves if deadlock happends.
// Otherwise, thread_killer should not be triggered.
diff --git a/test/test_device_changed_callback.cpp b/test/test_device_changed_callback.cpp
index 890ebd9..ddf810d 100644
--- a/test/test_device_changed_callback.cpp
+++ b/test/test_device_changed_callback.cpp
@@ -11,12 +11,12 @@
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <stdio.h>
-#include <memory>
#include "cubeb/cubeb.h"
+#include <memory>
+#include <stdio.h>
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
#define SAMPLE_FREQUENCY 48000
@@ -26,23 +26,28 @@
#define OUTPUT_CHANNELS 2
#define OUTPUT_LAYOUT CUBEB_LAYOUT_STEREO
-long data_callback(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+long
+data_callback(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
return 0;
}
-void state_callback(cubeb_stream * stream, void * user, cubeb_state state)
+void
+state_callback(cubeb_stream * stream, void * user, cubeb_state state)
{
}
-void device_changed_callback(void * user)
+void
+device_changed_callback(void * user)
{
fprintf(stderr, "device changed callback\n");
ASSERT_TRUE(false) << "Error: device changed callback"
" called without changing devices";
}
-void test_registering_null_callback_twice(cubeb_stream * stream)
+void
+test_registering_null_callback_twice(cubeb_stream * stream)
{
int r = cubeb_stream_register_device_changed_callback(stream, nullptr);
if (r == CUBEB_ERROR_NOT_SUPPORTED) {
@@ -51,12 +56,15 @@ void test_registering_null_callback_twice(cubeb_stream * stream)
ASSERT_EQ(r, CUBEB_OK) << "Error registering null device changed callback";
r = cubeb_stream_register_device_changed_callback(stream, nullptr);
- ASSERT_EQ(r, CUBEB_OK) << "Error registering null device changed callback again";
+ ASSERT_EQ(r, CUBEB_OK)
+ << "Error registering null device changed callback again";
}
-void test_registering_and_unregistering_callback(cubeb_stream * stream)
+void
+test_registering_and_unregistering_callback(cubeb_stream * stream)
{
- int r = cubeb_stream_register_device_changed_callback(stream, device_changed_callback);
+ int r = cubeb_stream_register_device_changed_callback(
+ stream, device_changed_callback);
if (r == CUBEB_ERROR_NOT_SUPPORTED) {
return;
}
@@ -75,7 +83,6 @@ TEST(cubeb, device_changed_callbacks)
int r = CUBEB_OK;
uint32_t latency_frames = 0;
-
r = common_init(&ctx, "Cubeb duplex example with device change");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
@@ -83,8 +90,8 @@ TEST(cubeb, device_changed_callbacks)
return;
}
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
/* typical user-case: mono input, stereo output, low latency. */
input_params.format = STREAM_FORMAT;
@@ -101,9 +108,9 @@ TEST(cubeb, device_changed_callbacks)
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
- r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",
- NULL, &input_params, NULL, &output_params,
- latency_frames, data_callback, state_callback, nullptr);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", NULL, &input_params, NULL,
+ &output_params, latency_frames, data_callback,
+ state_callback, nullptr);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
test_registering_null_callback_twice(stream);
diff --git a/test/test_devices.cpp b/test/test_devices.cpp
index a194663..d0eab2d 100644
--- a/test/test_devices.cpp
+++ b/test/test_devices.cpp
@@ -7,19 +7,20 @@
/* libcubeb enumerate device test/example.
* Prints out a list of devices enumerated. */
+#include "cubeb/cubeb.h"
#include "gtest/gtest.h"
+#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <memory>
-#include "cubeb/cubeb.h"
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
static long
-data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
// noop, unused
return 0;
@@ -35,52 +36,52 @@ static void
print_device_info(cubeb_device_info * info, FILE * f)
{
char devfmts[64] = "";
- const char * devtype, * devstate, * devdeffmt;
+ const char *devtype, *devstate, *devdeffmt;
switch (info->type) {
- case CUBEB_DEVICE_TYPE_INPUT:
- devtype = "input";
- break;
- case CUBEB_DEVICE_TYPE_OUTPUT:
- devtype = "output";
- break;
- case CUBEB_DEVICE_TYPE_UNKNOWN:
- default:
- devtype = "unknown?";
- break;
+ case CUBEB_DEVICE_TYPE_INPUT:
+ devtype = "input";
+ break;
+ case CUBEB_DEVICE_TYPE_OUTPUT:
+ devtype = "output";
+ break;
+ case CUBEB_DEVICE_TYPE_UNKNOWN:
+ default:
+ devtype = "unknown?";
+ break;
};
switch (info->state) {
- case CUBEB_DEVICE_STATE_DISABLED:
- devstate = "disabled";
- break;
- case CUBEB_DEVICE_STATE_UNPLUGGED:
- devstate = "unplugged";
- break;
- case CUBEB_DEVICE_STATE_ENABLED:
- devstate = "enabled";
- break;
- default:
- devstate = "unknown?";
- break;
+ case CUBEB_DEVICE_STATE_DISABLED:
+ devstate = "disabled";
+ break;
+ case CUBEB_DEVICE_STATE_UNPLUGGED:
+ devstate = "unplugged";
+ break;
+ case CUBEB_DEVICE_STATE_ENABLED:
+ devstate = "enabled";
+ break;
+ default:
+ devstate = "unknown?";
+ break;
};
switch (info->default_format) {
- case CUBEB_DEVICE_FMT_S16LE:
- devdeffmt = "S16LE";
- break;
- case CUBEB_DEVICE_FMT_S16BE:
- devdeffmt = "S16BE";
- break;
- case CUBEB_DEVICE_FMT_F32LE:
- devdeffmt = "F32LE";
- break;
- case CUBEB_DEVICE_FMT_F32BE:
- devdeffmt = "F32BE";
- break;
- default:
- devdeffmt = "unknown?";
- break;
+ case CUBEB_DEVICE_FMT_S16LE:
+ devdeffmt = "S16LE";
+ break;
+ case CUBEB_DEVICE_FMT_S16BE:
+ devdeffmt = "S16BE";
+ break;
+ case CUBEB_DEVICE_FMT_F32LE:
+ devdeffmt = "F32LE";
+ break;
+ case CUBEB_DEVICE_FMT_F32BE:
+ devdeffmt = "F32BE";
+ break;
+ default:
+ devdeffmt = "unknown?";
+ break;
};
if (info->format & CUBEB_DEVICE_FMT_S16LE)
@@ -93,23 +94,22 @@ print_device_info(cubeb_device_info * info, FILE * f)
strcat(devfmts, " F32BE");
fprintf(f,
- "dev: \"%s\"%s\n"
- "\tName: \"%s\"\n"
- "\tGroup: \"%s\"\n"
- "\tVendor: \"%s\"\n"
- "\tType: %s\n"
- "\tState: %s\n"
- "\tCh: %u\n"
- "\tFormat: %s (0x%x) (default: %s)\n"
- "\tRate: %u - %u (default: %u)\n"
- "\tLatency: lo %u frames, hi %u frames\n",
- info->device_id, info->preferred ? " (PREFERRED)" : "",
- info->friendly_name, info->group_id, info->vendor_name,
- devtype, devstate, info->max_channels,
- (devfmts[0] == '\0') ? devfmts : devfmts + 1,
- (unsigned int)info->format, devdeffmt,
- info->min_rate, info->max_rate, info->default_rate,
- info->latency_lo, info->latency_hi);
+ "dev: \"%s\"%s\n"
+ "\tName: \"%s\"\n"
+ "\tGroup: \"%s\"\n"
+ "\tVendor: \"%s\"\n"
+ "\tType: %s\n"
+ "\tState: %s\n"
+ "\tCh: %u\n"
+ "\tFormat: %s (0x%x) (default: %s)\n"
+ "\tRate: %u - %u (default: %u)\n"
+ "\tLatency: lo %u frames, hi %u frames\n",
+ info->device_id, info->preferred ? " (PREFERRED)" : "",
+ info->friendly_name, info->group_id, info->vendor_name, devtype,
+ devstate, info->max_channels,
+ (devfmts[0] == '\0') ? devfmts : devfmts + 1,
+ (unsigned int)info->format, devdeffmt, info->min_rate, info->max_rate,
+ info->default_rate, info->latency_lo, info->latency_hi);
}
static void
@@ -125,22 +125,22 @@ TEST(cubeb, destroy_default_collection)
{
int r;
cubeb * ctx = NULL;
- cubeb_device_collection collection{ nullptr, 0 };
+ cubeb_device_collection collection{nullptr, 0};
r = common_init(&ctx, "Cubeb audio test");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
ASSERT_EQ(collection.device, nullptr);
- ASSERT_EQ(collection.count, (size_t) 0);
+ ASSERT_EQ(collection.count, (size_t)0);
r = cubeb_device_collection_destroy(ctx, &collection);
if (r != CUBEB_ERROR_NOT_SUPPORTED) {
ASSERT_EQ(r, CUBEB_OK);
ASSERT_EQ(collection.device, nullptr);
- ASSERT_EQ(collection.count, (size_t) 0);
+ ASSERT_EQ(collection.count, (size_t)0);
}
}
@@ -153,11 +153,11 @@ TEST(cubeb, enumerate_devices)
r = common_init(&ctx, "Cubeb audio test");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
fprintf(stdout, "Enumerating input devices for backend %s\n",
- cubeb_get_backend_id(ctx));
+ cubeb_get_backend_id(ctx));
r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_INPUT, &collection);
if (r == CUBEB_ERROR_NOT_SUPPORTED) {
@@ -200,9 +200,9 @@ TEST(cubeb, enumerate_devices)
input_params.layout = output_params.layout = CUBEB_LAYOUT_MONO;
input_params.prefs = output_params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",
- NULL, &input_params, NULL, &output_params,
- 1024, data_cb_duplex, state_cb_duplex, nullptr);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", NULL, &input_params, NULL,
+ &output_params, 1024, data_cb_duplex, state_cb_duplex,
+ nullptr);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
@@ -220,11 +220,11 @@ TEST(cubeb, stream_get_current_device)
int r = common_init(&ctx, "Cubeb audio test");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
fprintf(stdout, "Getting current devices for backend %s\n",
- cubeb_get_backend_id(ctx));
+ cubeb_get_backend_id(ctx));
if (!can_run_audio_input_test(ctx)) {
return;
@@ -240,12 +240,12 @@ TEST(cubeb, stream_get_current_device)
input_params.layout = output_params.layout = CUBEB_LAYOUT_MONO;
input_params.prefs = output_params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",
- NULL, &input_params, NULL, &output_params,
- 1024, data_cb_duplex, state_cb_duplex, nullptr);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", NULL, &input_params, NULL,
+ &output_params, 1024, data_cb_duplex, state_cb_duplex,
+ nullptr);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_device * device;
r = cubeb_stream_get_current_device(stream, &device);
diff --git a/test/test_duplex.cpp b/test/test_duplex.cpp
index 6eeca8c..518f44f 100644
--- a/test/test_duplex.cpp
+++ b/test/test_duplex.cpp
@@ -11,15 +11,15 @@
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <memory>
#include "cubeb/cubeb.h"
#include <atomic>
+#include <math.h>
+#include <memory>
+#include <stdio.h>
+#include <stdlib.h>
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
#define SAMPLE_FREQUENCY 48000
@@ -29,16 +29,17 @@
#define OUTPUT_CHANNELS 2
#define OUTPUT_LAYOUT CUBEB_LAYOUT_STEREO
-struct user_state_duplex
-{
- std::atomic<int> invalid_audio_value{ 0 };
+struct user_state_duplex {
+ std::atomic<int> invalid_audio_value{0};
};
-long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+long
+data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
- user_state_duplex * u = reinterpret_cast<user_state_duplex*>(user);
- float *ib = (float *)inputbuffer;
- float *ob = (float *)outputbuffer;
+ user_state_duplex * u = reinterpret_cast<user_state_duplex *>(user);
+ float * ib = (float *)inputbuffer;
+ float * ob = (float *)outputbuffer;
if (stream == NULL || inputbuffer == NULL || outputbuffer == NULL) {
return CUBEB_ERROR;
@@ -58,18 +59,22 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer
return nframes;
}
-void state_cb_duplex(cubeb_stream * stream, void * /*user*/, cubeb_state state)
+void
+state_cb_duplex(cubeb_stream * stream, void * /*user*/, cubeb_state state)
{
if (stream == NULL)
return;
switch (state) {
case CUBEB_STATE_STARTED:
- fprintf(stderr, "stream started\n"); break;
+ fprintf(stderr, "stream started\n");
+ break;
case CUBEB_STATE_STOPPED:
- fprintf(stderr, "stream stopped\n"); break;
+ fprintf(stderr, "stream stopped\n");
+ break;
case CUBEB_STATE_DRAINED:
- fprintf(stderr, "stream drained\n"); break;
+ fprintf(stderr, "stream drained\n");
+ break;
default:
fprintf(stderr, "unknown stream state %d\n", state);
}
@@ -79,8 +84,8 @@ void state_cb_duplex(cubeb_stream * stream, void * /*user*/, cubeb_state state)
TEST(cubeb, duplex)
{
- cubeb *ctx;
- cubeb_stream *stream;
+ cubeb * ctx;
+ cubeb_stream * stream;
cubeb_stream_params input_params;
cubeb_stream_params output_params;
int r;
@@ -90,8 +95,8 @@ TEST(cubeb, duplex)
r = common_init(&ctx, "Cubeb duplex example");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
/* This test needs an available input device, skip it if this host does not
* have one. */
@@ -114,13 +119,13 @@ TEST(cubeb, duplex)
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
- r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",
- NULL, &input_params, NULL, &output_params,
- latency_frames, data_cb_duplex, state_cb_duplex, &stream_state);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", NULL, &input_params, NULL,
+ &output_params, latency_frames, data_cb_duplex,
+ state_cb_duplex, &stream_state);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_stream_start(stream);
delay(500);
@@ -129,7 +134,8 @@ TEST(cubeb, duplex)
ASSERT_FALSE(stream_state.invalid_audio_value.load());
}
-void device_collection_changed_callback(cubeb * context, void * user)
+void
+device_collection_changed_callback(cubeb * context, void * user)
{
fprintf(stderr, "collection changed callback\n");
ASSERT_TRUE(false) << "Error: device collection changed callback"
@@ -150,7 +156,6 @@ duplex_collection_change_impl(cubeb * ctx)
device_collection_changed_callback, nullptr);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
-
/* typical user-case: mono input, stereo output, low latency. */
input_params.format = STREAM_FORMAT;
input_params.rate = SAMPLE_FREQUENCY;
@@ -217,7 +222,9 @@ TEST(cubeb, duplex_collection_change_no_unregister)
duplex_collection_change_impl(ctx);
}
-long data_cb_input(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+long
+data_cb_input(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
if (stream == NULL || inputbuffer == NULL || outputbuffer != NULL) {
return CUBEB_ERROR;
@@ -226,20 +233,25 @@ long data_cb_input(cubeb_stream * stream, void * user, const void * inputbuffer,
return nframes;
}
-void state_cb_input(cubeb_stream * stream, void * /*user*/, cubeb_state state)
+void
+state_cb_input(cubeb_stream * stream, void * /*user*/, cubeb_state state)
{
if (stream == NULL)
return;
switch (state) {
case CUBEB_STATE_STARTED:
- fprintf(stderr, "stream started\n"); break;
+ fprintf(stderr, "stream started\n");
+ break;
case CUBEB_STATE_STOPPED:
- fprintf(stderr, "stream stopped\n"); break;
+ fprintf(stderr, "stream stopped\n");
+ break;
case CUBEB_STATE_DRAINED:
- fprintf(stderr, "stream drained\n"); break;
+ fprintf(stderr, "stream drained\n");
+ break;
case CUBEB_STATE_ERROR:
- fprintf(stderr, "stream runs into error state\n"); break;
+ fprintf(stderr, "stream runs into error state\n");
+ break;
default:
fprintf(stderr, "unknown stream state %d\n", state);
}
@@ -247,7 +259,9 @@ void state_cb_input(cubeb_stream * stream, void * /*user*/, cubeb_state state)
return;
}
-std::vector<cubeb_devid> get_devices(cubeb * ctx, cubeb_device_type type) {
+std::vector<cubeb_devid>
+get_devices(cubeb * ctx, cubeb_device_type type)
+{
std::vector<cubeb_devid> devices;
cubeb_device_collection collection;
@@ -271,8 +285,8 @@ std::vector<cubeb_devid> get_devices(cubeb * ctx, cubeb_device_type type) {
TEST(cubeb, one_duplex_one_input)
{
- cubeb *ctx;
- cubeb_stream *duplex_stream;
+ cubeb * ctx;
+ cubeb_stream * duplex_stream;
cubeb_stream_params input_params;
cubeb_stream_params output_params;
int r;
@@ -282,17 +296,19 @@ TEST(cubeb, one_duplex_one_input)
r = common_init(&ctx, "Cubeb duplex example");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
/* This test needs at least two available input devices. */
- std::vector<cubeb_devid> input_devices = get_devices(ctx, CUBEB_DEVICE_TYPE_INPUT);
+ std::vector<cubeb_devid> input_devices =
+ get_devices(ctx, CUBEB_DEVICE_TYPE_INPUT);
if (input_devices.size() < 2) {
return;
}
/* This test needs at least one available output device. */
- std::vector<cubeb_devid> output_devices = get_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT);
+ std::vector<cubeb_devid> output_devices =
+ get_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT);
if (output_devices.size() < 1) {
return;
}
@@ -317,27 +333,28 @@ TEST(cubeb, one_duplex_one_input)
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
- r = cubeb_stream_init(ctx, &duplex_stream, "Cubeb duplex",
- duplex_input, &input_params, duplex_output, &output_params,
- latency_frames, data_cb_duplex, state_cb_duplex, &duplex_stream_state);
+ r = cubeb_stream_init(ctx, &duplex_stream, "Cubeb duplex", duplex_input,
+ &input_params, duplex_output, &output_params,
+ latency_frames, data_cb_duplex, state_cb_duplex,
+ &duplex_stream_state);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing duplex cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(duplex_stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(duplex_stream, cubeb_stream_destroy);
r = cubeb_stream_start(duplex_stream);
ASSERT_EQ(r, CUBEB_OK) << "Could not start duplex stream";
delay(500);
- cubeb_stream *input_stream;
- r = cubeb_stream_init(ctx, &input_stream, "Cubeb input",
- input_only, &input_params, NULL, NULL,
- latency_frames, data_cb_input, state_cb_input, nullptr);
+ cubeb_stream * input_stream;
+ r = cubeb_stream_init(ctx, &input_stream, "Cubeb input", input_only,
+ &input_params, NULL, NULL, latency_frames,
+ data_cb_input, state_cb_input, nullptr);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing input-only cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
-
+ cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
+
r = cubeb_stream_start(input_stream);
ASSERT_EQ(r, CUBEB_OK) << "Could not start input stream";
delay(500);
diff --git a/test/test_latency.cpp b/test/test_latency.cpp
index 5228510..97f24ea 100644
--- a/test/test_latency.cpp
+++ b/test/test_latency.cpp
@@ -1,9 +1,9 @@
+#include "cubeb/cubeb.h"
#include "gtest/gtest.h"
-#include <stdlib.h>
#include <memory>
-#include "cubeb/cubeb.h"
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+#include <stdlib.h>
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
TEST(cubeb, latency)
@@ -17,8 +17,8 @@ TEST(cubeb, latency)
r = common_init(&ctx, "Cubeb audio test");
ASSERT_EQ(r, CUBEB_OK);
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
r = cubeb_get_max_channel_count(ctx, &max_channels);
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
@@ -32,13 +32,9 @@ TEST(cubeb, latency)
ASSERT_GT(preferred_rate, 0u);
}
- cubeb_stream_params params = {
- CUBEB_SAMPLE_FLOAT32NE,
- preferred_rate,
- max_channels,
- CUBEB_LAYOUT_UNDEFINED,
- CUBEB_STREAM_PREF_NONE
- };
+ cubeb_stream_params params = {CUBEB_SAMPLE_FLOAT32NE, preferred_rate,
+ max_channels, CUBEB_LAYOUT_UNDEFINED,
+ CUBEB_STREAM_PREF_NONE};
r = cubeb_get_min_latency(ctx, &params, &latency_frames);
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
if (r == CUBEB_OK) {
diff --git a/test/test_loopback.cpp b/test/test_loopback.cpp
index bbb9409..7410bed 100644
--- a/test/test_loopback.cpp
+++ b/test/test_loopback.cpp
@@ -5,41 +5,66 @@
* accompanying file LICENSE for details.
*/
- /* libcubeb api/function test. Requests a loopback device and checks that
- output is being looped back to input. NOTE: Usage of output devices while
- performing this test will cause flakey results! */
+/* libcubeb api/function test. Requests a loopback device and checks that
+ output is being looped back to input. NOTE: Usage of output devices while
+ performing this test will cause flakey results! */
#include "gtest/gtest.h"
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
+#include "cubeb/cubeb.h"
#include <algorithm>
+#include <math.h>
#include <memory>
#include <mutex>
+#include <stdio.h>
+#include <stdlib.h>
#include <string>
-#include "cubeb/cubeb.h"
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
const uint32_t SAMPLE_FREQUENCY = 48000;
const uint32_t TONE_FREQUENCY = 440;
const double OUTPUT_AMPLITUDE = 0.25;
-const int32_t NUM_FRAMES_TO_OUTPUT = SAMPLE_FREQUENCY / 20; /* play ~50ms of samples */
-
-template<typename T> T ConvertSampleToOutput(double input);
-template<> float ConvertSampleToOutput(double input) { return float(input); }
-template<> short ConvertSampleToOutput(double input) { return short(input * 32767.0f); }
+const int32_t NUM_FRAMES_TO_OUTPUT =
+ SAMPLE_FREQUENCY / 20; /* play ~50ms of samples */
+
+template <typename T>
+T
+ConvertSampleToOutput(double input);
+template <>
+float
+ConvertSampleToOutput(double input)
+{
+ return float(input);
+}
+template <>
+short
+ConvertSampleToOutput(double input)
+{
+ return short(input * 32767.0f);
+}
-template<typename T> double ConvertSampleFromOutput(T sample);
-template<> double ConvertSampleFromOutput(float sample) { return double(sample); }
-template<> double ConvertSampleFromOutput(short sample) { return double(sample / 32767.0); }
+template <typename T>
+double
+ConvertSampleFromOutput(T sample);
+template <>
+double
+ConvertSampleFromOutput(float sample)
+{
+ return double(sample);
+}
+template <>
+double
+ConvertSampleFromOutput(short sample)
+{
+ return double(sample / 32767.0);
+}
/* Simple cross correlation to help find phase shift. Not a performant impl */
-std::vector<double> cross_correlate(std::vector<double> & f,
- std::vector<double> & g,
- size_t signal_length)
+std::vector<double>
+cross_correlate(std::vector<double> & f, std::vector<double> & g,
+ size_t signal_length)
{
/* the length we sweep our window through to find the cross correlation */
size_t sweep_length = f.size() - signal_length + 1;
@@ -56,11 +81,12 @@ std::vector<double> cross_correlate(std::vector<double> & f,
}
/* best effort discovery of phase shift between output and (looped) input*/
-size_t find_phase(std::vector<double> & output_frames,
- std::vector<double> & input_frames,
- size_t signal_length)
+size_t
+find_phase(std::vector<double> & output_frames,
+ std::vector<double> & input_frames, size_t signal_length)
{
- std::vector<double> correlation = cross_correlate(output_frames, input_frames, signal_length);
+ std::vector<double> correlation =
+ cross_correlate(output_frames, input_frames, signal_length);
size_t phase = 0;
double max_correlation = correlation.at(0);
for (size_t i = 1; i < correlation.size(); i++) {
@@ -72,9 +98,12 @@ size_t find_phase(std::vector<double> & output_frames,
return phase;
}
-std::vector<double> normalize_frames(std::vector<double> & frames) {
- double max = abs(*std::max_element(frames.begin(), frames.end(),
- [](double a, double b) { return abs(a) < abs(b); }));
+std::vector<double>
+normalize_frames(std::vector<double> & frames)
+{
+ double max = abs(
+ *std::max_element(frames.begin(), frames.end(),
+ [](double a, double b) { return abs(a) < abs(b); }));
std::vector<double> normalized_frames;
normalized_frames.reserve(frames.size());
for (const double frame : frames) {
@@ -83,13 +112,17 @@ std::vector<double> normalize_frames(std::vector<double> & frames) {
return normalized_frames;
}
-/* heuristic comparison of aligned output and input signals, gets flaky if TONE_FREQUENCY is too high */
-void compare_signals(std::vector<double> & output_frames,
- std::vector<double> & input_frames)
+/* heuristic comparison of aligned output and input signals, gets flaky if
+ * TONE_FREQUENCY is too high */
+void
+compare_signals(std::vector<double> & output_frames,
+ std::vector<double> & input_frames)
{
- ASSERT_EQ(output_frames.size(), input_frames.size()) << "#Output frames != #input frames";
+ ASSERT_EQ(output_frames.size(), input_frames.size())
+ << "#Output frames != #input frames";
size_t num_frames = output_frames.size();
- std::vector<double> normalized_output_frames = normalize_frames(output_frames);
+ std::vector<double> normalized_output_frames =
+ normalize_frames(output_frames);
std::vector<double> normalized_input_frames = normalize_frames(input_frames);
/* calculate mean absolute errors */
@@ -100,7 +133,8 @@ void compare_signals(std::vector<double> & output_frames,
/* mean absolute errors between input and silence */
double input_silence_mas = 0.0;
for (size_t i = 0; i < num_frames; i++) {
- io_mas += abs(normalized_output_frames.at(i) - normalized_input_frames.at(i));
+ io_mas +=
+ abs(normalized_output_frames.at(i) - normalized_input_frames.at(i));
output_silence_mas += abs(normalized_output_frames.at(i));
input_silence_mas += abs(normalized_input_frames.at(i));
}
@@ -109,13 +143,16 @@ void compare_signals(std::vector<double> & output_frames,
input_silence_mas /= num_frames;
ASSERT_LT(io_mas, output_silence_mas)
- << "Error between output and input should be less than output and silence!";
+ << "Error between output and input should be less than output and "
+ "silence!";
ASSERT_LT(io_mas, input_silence_mas)
- << "Error between output and input should be less than output and silence!";
+ << "Error between output and input should be less than output and "
+ "silence!";
/* make sure extrema are in (roughly) correct location */
/* number of maxima + minama expected in the frames*/
- const long NUM_EXTREMA = 2 * TONE_FREQUENCY * NUM_FRAMES_TO_OUTPUT / SAMPLE_FREQUENCY;
+ const long NUM_EXTREMA =
+ 2 * TONE_FREQUENCY * NUM_FRAMES_TO_OUTPUT / SAMPLE_FREQUENCY;
/* expected index of first maxima */
const long FIRST_MAXIMUM_INDEX = SAMPLE_FREQUENCY / TONE_FREQUENCY / 4;
/* Threshold we expect all maxima and minima to be above or below. Ideally
@@ -128,15 +165,19 @@ void compare_signals(std::vector<double> & output_frames,
/* expected offset to current extreme: i * stide between extrema */
size_t offset = i * SAMPLE_FREQUENCY / TONE_FREQUENCY / 2;
if (is_maximum) {
- ASSERT_GT(normalized_output_frames.at(FIRST_MAXIMUM_INDEX + offset), THRESHOLD)
- << "Output frames have unexpected missing maximum!";
- ASSERT_GT(normalized_input_frames.at(FIRST_MAXIMUM_INDEX + offset), THRESHOLD)
- << "Input frames have unexpected missing maximum!";
+ ASSERT_GT(normalized_output_frames.at(FIRST_MAXIMUM_INDEX + offset),
+ THRESHOLD)
+ << "Output frames have unexpected missing maximum!";
+ ASSERT_GT(normalized_input_frames.at(FIRST_MAXIMUM_INDEX + offset),
+ THRESHOLD)
+ << "Input frames have unexpected missing maximum!";
} else {
- ASSERT_LT(normalized_output_frames.at(FIRST_MAXIMUM_INDEX + offset), -THRESHOLD)
- << "Output frames have unexpected missing minimum!";
- ASSERT_LT(normalized_input_frames.at(FIRST_MAXIMUM_INDEX + offset), -THRESHOLD)
- << "Input frames have unexpected missing minimum!";
+ ASSERT_LT(normalized_output_frames.at(FIRST_MAXIMUM_INDEX + offset),
+ -THRESHOLD)
+ << "Output frames have unexpected missing minimum!";
+ ASSERT_LT(normalized_input_frames.at(FIRST_MAXIMUM_INDEX + offset),
+ -THRESHOLD)
+ << "Input frames have unexpected missing minimum!";
}
}
}
@@ -150,12 +191,14 @@ struct user_state_loopback {
std::vector<double> input_frames;
};
-template<typename T>
-long data_cb_loop_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+template <typename T>
+long
+data_cb_loop_duplex(cubeb_stream * stream, void * user,
+ const void * inputbuffer, void * outputbuffer, long nframes)
{
- struct user_state_loopback * u = (struct user_state_loopback *) user;
- T * ib = (T *) inputbuffer;
- T * ob = (T *) outputbuffer;
+ struct user_state_loopback * u = (struct user_state_loopback *)user;
+ T * ib = (T *)inputbuffer;
+ T * ob = (T *)outputbuffer;
if (stream == NULL || inputbuffer == NULL || outputbuffer == NULL) {
return CUBEB_ERROR;
@@ -167,7 +210,8 @@ long data_cb_loop_duplex(cubeb_stream * stream, void * user, const void * inputb
double tone = 0.0;
if (u->position + i < NUM_FRAMES_TO_OUTPUT) {
/* generate sine wave */
- tone = sin(2 * M_PI*(i + u->position) * TONE_FREQUENCY / SAMPLE_FREQUENCY);
+ tone =
+ sin(2 * M_PI * (i + u->position) * TONE_FREQUENCY / SAMPLE_FREQUENCY);
tone *= OUTPUT_AMPLITUDE;
}
ob[i] = ConvertSampleToOutput<T>(tone);
@@ -181,15 +225,19 @@ long data_cb_loop_duplex(cubeb_stream * stream, void * user, const void * inputb
return nframes;
}
-template<typename T>
-long data_cb_loop_input_only(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+template <typename T>
+long
+data_cb_loop_input_only(cubeb_stream * stream, void * user,
+ const void * inputbuffer, void * outputbuffer,
+ long nframes)
{
- struct user_state_loopback * u = (struct user_state_loopback *) user;
- T * ib = (T *) inputbuffer;
+ struct user_state_loopback * u = (struct user_state_loopback *)user;
+ T * ib = (T *)inputbuffer;
if (outputbuffer != NULL) {
// Can't assert as it needs to return, so expect to fail instead
- EXPECT_EQ(outputbuffer, (void *) NULL) << "outputbuffer should be null in input only callback";
+ EXPECT_EQ(outputbuffer, (void *)NULL)
+ << "outputbuffer should be null in input only callback";
return CUBEB_ERROR;
}
@@ -205,11 +253,13 @@ long data_cb_loop_input_only(cubeb_stream * stream, void * user, const void * in
return nframes;
}
-template<typename T>
-long data_cb_playback(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+template <typename T>
+long
+data_cb_playback(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
- struct user_state_loopback * u = (struct user_state_loopback *) user;
- T * ob = (T *) outputbuffer;
+ struct user_state_loopback * u = (struct user_state_loopback *)user;
+ T * ob = (T *)outputbuffer;
if (stream == NULL || outputbuffer == NULL) {
return CUBEB_ERROR;
@@ -221,7 +271,8 @@ long data_cb_playback(cubeb_stream * stream, void * user, const void * inputbuff
double tone = 0.0;
if (u->position + i < NUM_FRAMES_TO_OUTPUT) {
/* generate sine wave */
- tone = sin(2 * M_PI*(i + u->position) * TONE_FREQUENCY / SAMPLE_FREQUENCY);
+ tone =
+ sin(2 * M_PI * (i + u->position) * TONE_FREQUENCY / SAMPLE_FREQUENCY);
tone *= OUTPUT_AMPLITUDE;
}
ob[i] = ConvertSampleToOutput<T>(tone);
@@ -233,18 +284,22 @@ long data_cb_playback(cubeb_stream * stream, void * user, const void * inputbuff
return nframes;
}
-void state_cb_loop(cubeb_stream * stream, void * /*user*/, cubeb_state state)
+void
+state_cb_loop(cubeb_stream * stream, void * /*user*/, cubeb_state state)
{
if (stream == NULL)
return;
switch (state) {
case CUBEB_STATE_STARTED:
- fprintf(stderr, "stream started\n"); break;
+ fprintf(stderr, "stream started\n");
+ break;
case CUBEB_STATE_STOPPED:
- fprintf(stderr, "stream stopped\n"); break;
+ fprintf(stderr, "stream stopped\n");
+ break;
case CUBEB_STATE_DRAINED:
- fprintf(stderr, "stream drained\n"); break;
+ fprintf(stderr, "stream drained\n");
+ break;
default:
fprintf(stderr, "unknown stream state %d\n", state);
}
@@ -252,7 +307,8 @@ void state_cb_loop(cubeb_stream * stream, void * /*user*/, cubeb_state state)
return;
}
-void run_loopback_duplex_test(bool is_float)
+void
+run_loopback_duplex_test(bool is_float)
{
cubeb * ctx;
cubeb_stream * stream;
@@ -264,8 +320,8 @@ void run_loopback_duplex_test(bool is_float)
r = common_init(&ctx, "Cubeb loopback example: duplex stream");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
/* This test needs an available input device, skip it if this host does not
* have one. */
@@ -291,35 +347,41 @@ void run_loopback_duplex_test(bool is_float)
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
/* setup a duplex stream with loopback */
- r = cubeb_stream_init(ctx, &stream, "Cubeb loopback",
- NULL, &input_params, NULL, &output_params, latency_frames,
- is_float ? data_cb_loop_duplex<float> : data_cb_loop_duplex<short>,
+ r = cubeb_stream_init(ctx, &stream, "Cubeb loopback", NULL, &input_params,
+ NULL, &output_params, latency_frames,
+ is_float ? data_cb_loop_duplex<float>
+ : data_cb_loop_duplex<short>,
state_cb_loop, user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_stream_start(stream);
delay(300);
cubeb_stream_stop(stream);
- /* access after stop should not happen, but lock just in case and to appease sanitization tools */
+ /* access after stop should not happen, but lock just in case and to appease
+ * sanitization tools */
std::lock_guard<std::mutex> lock(user_data->user_state_mutex);
std::vector<double> & output_frames = user_data->output_frames;
std::vector<double> & input_frames = user_data->input_frames;
ASSERT_EQ(output_frames.size(), input_frames.size())
- << "#Output frames != #input frames";
+ << "#Output frames != #input frames";
- size_t phase = find_phase(user_data->output_frames, user_data->input_frames, NUM_FRAMES_TO_OUTPUT);
+ size_t phase = find_phase(user_data->output_frames, user_data->input_frames,
+ NUM_FRAMES_TO_OUTPUT);
/* extract vectors of just the relevant signal from output and input */
auto output_frames_signal_start = output_frames.begin();
auto output_frames_signal_end = output_frames.begin() + NUM_FRAMES_TO_OUTPUT;
- std::vector<double> trimmed_output_frames(output_frames_signal_start, output_frames_signal_end);
+ std::vector<double> trimmed_output_frames(output_frames_signal_start,
+ output_frames_signal_end);
auto input_frames_signal_start = input_frames.begin() + phase;
- auto input_frames_signal_end = input_frames.begin() + phase + NUM_FRAMES_TO_OUTPUT;
- std::vector<double> trimmed_input_frames(input_frames_signal_start, input_frames_signal_end);
+ auto input_frames_signal_end =
+ input_frames.begin() + phase + NUM_FRAMES_TO_OUTPUT;
+ std::vector<double> trimmed_input_frames(input_frames_signal_start,
+ input_frames_signal_end);
compare_signals(trimmed_output_frames, trimmed_input_frames);
}
@@ -330,7 +392,8 @@ TEST(cubeb, loopback_duplex)
run_loopback_duplex_test(false);
}
-void run_loopback_separate_streams_test(bool is_float)
+void
+run_loopback_separate_streams_test(bool is_float)
{
cubeb * ctx;
cubeb_stream * input_stream;
@@ -343,8 +406,8 @@ void run_loopback_separate_streams_test(bool is_float)
r = common_init(&ctx, "Cubeb loopback example: separate streams");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
if (!can_run_audio_input_test(ctx)) {
return;
@@ -368,24 +431,26 @@ void run_loopback_separate_streams_test(bool is_float)
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
/* setup an input stream with loopback */
- r = cubeb_stream_init(ctx, &input_stream, "Cubeb loopback input only",
- NULL, &input_params, NULL, NULL, latency_frames,
- is_float ? data_cb_loop_input_only<float> : data_cb_loop_input_only<short>,
+ r = cubeb_stream_init(ctx, &input_stream, "Cubeb loopback input only", NULL,
+ &input_params, NULL, NULL, latency_frames,
+ is_float ? data_cb_loop_input_only<float>
+ : data_cb_loop_input_only<short>,
state_cb_loop, user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
+ cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
/* setup an output stream */
- r = cubeb_stream_init(ctx, &output_stream, "Cubeb loopback output only",
- NULL, NULL, NULL, &output_params, latency_frames,
- is_float ? data_cb_playback<float> : data_cb_playback<short>,
+ r = cubeb_stream_init(ctx, &output_stream, "Cubeb loopback output only", NULL,
+ NULL, NULL, &output_params, latency_frames,
+ is_float ? data_cb_playback<float>
+ : data_cb_playback<short>,
state_cb_loop, user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_output_stream_at_exit(output_stream, cubeb_stream_destroy);
+ cleanup_output_stream_at_exit(output_stream, cubeb_stream_destroy);
cubeb_stream_start(input_stream);
cubeb_stream_start(output_stream);
@@ -393,22 +458,27 @@ void run_loopback_separate_streams_test(bool is_float)
cubeb_stream_stop(output_stream);
cubeb_stream_stop(input_stream);
- /* access after stop should not happen, but lock just in case and to appease sanitization tools */
+ /* access after stop should not happen, but lock just in case and to appease
+ * sanitization tools */
std::lock_guard<std::mutex> lock(user_data->user_state_mutex);
std::vector<double> & output_frames = user_data->output_frames;
std::vector<double> & input_frames = user_data->input_frames;
ASSERT_LE(output_frames.size(), input_frames.size())
- << "#Output frames should be less or equal to #input frames";
+ << "#Output frames should be less or equal to #input frames";
- size_t phase = find_phase(user_data->output_frames, user_data->input_frames, NUM_FRAMES_TO_OUTPUT);
+ size_t phase = find_phase(user_data->output_frames, user_data->input_frames,
+ NUM_FRAMES_TO_OUTPUT);
/* extract vectors of just the relevant signal from output and input */
auto output_frames_signal_start = output_frames.begin();
auto output_frames_signal_end = output_frames.begin() + NUM_FRAMES_TO_OUTPUT;
- std::vector<double> trimmed_output_frames(output_frames_signal_start, output_frames_signal_end);
+ std::vector<double> trimmed_output_frames(output_frames_signal_start,
+ output_frames_signal_end);
auto input_frames_signal_start = input_frames.begin() + phase;
- auto input_frames_signal_end = input_frames.begin() + phase + NUM_FRAMES_TO_OUTPUT;
- std::vector<double> trimmed_input_frames(input_frames_signal_start, input_frames_signal_end);
+ auto input_frames_signal_end =
+ input_frames.begin() + phase + NUM_FRAMES_TO_OUTPUT;
+ std::vector<double> trimmed_input_frames(input_frames_signal_start,
+ input_frames_signal_end);
compare_signals(trimmed_output_frames, trimmed_input_frames);
}
@@ -419,7 +489,8 @@ TEST(cubeb, loopback_separate_streams)
run_loopback_separate_streams_test(false);
}
-void run_loopback_silence_test(bool is_float)
+void
+run_loopback_silence_test(bool is_float)
{
cubeb * ctx;
cubeb_stream * input_stream;
@@ -430,8 +501,8 @@ void run_loopback_silence_test(bool is_float)
r = common_init(&ctx, "Cubeb loopback example: record silence");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
if (!can_run_audio_input_test(ctx)) {
return;
@@ -450,20 +521,22 @@ void run_loopback_silence_test(bool is_float)
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
/* setup an input stream with loopback */
- r = cubeb_stream_init(ctx, &input_stream, "Cubeb loopback input only",
- NULL, &input_params, NULL, NULL, latency_frames,
- is_float ? data_cb_loop_input_only<float> : data_cb_loop_input_only<short>,
+ r = cubeb_stream_init(ctx, &input_stream, "Cubeb loopback input only", NULL,
+ &input_params, NULL, NULL, latency_frames,
+ is_float ? data_cb_loop_input_only<float>
+ : data_cb_loop_input_only<short>,
state_cb_loop, user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
+ cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
cubeb_stream_start(input_stream);
delay(300);
cubeb_stream_stop(input_stream);
- /* access after stop should not happen, but lock just in case and to appease sanitization tools */
+ /* access after stop should not happen, but lock just in case and to appease
+ * sanitization tools */
std::lock_guard<std::mutex> lock(user_data->user_state_mutex);
std::vector<double> & input_frames = user_data->input_frames;
@@ -483,7 +556,8 @@ TEST(cubeb, loopback_silence)
run_loopback_silence_test(false);
}
-void run_loopback_device_selection_test(bool is_float)
+void
+run_loopback_device_selection_test(bool is_float)
{
cubeb * ctx;
cubeb_device_collection collection;
@@ -494,11 +568,12 @@ void run_loopback_device_selection_test(bool is_float)
int r;
uint32_t latency_frames = 0;
- r = common_init(&ctx, "Cubeb loopback example: device selection, separate streams");
+ r = common_init(&ctx,
+ "Cubeb loopback example: device selection, separate streams");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
if (!can_run_audio_input_test(ctx)) {
return;
@@ -507,7 +582,7 @@ void run_loopback_device_selection_test(bool is_float)
r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT, &collection);
if (r == CUBEB_ERROR_NOT_SUPPORTED) {
fprintf(stderr, "Device enumeration not supported"
- " for this backend, skipping this test.\n");
+ " for this backend, skipping this test.\n");
return;
}
@@ -545,23 +620,26 @@ void run_loopback_device_selection_test(bool is_float)
/* setup an input stream with loopback */
r = cubeb_stream_init(ctx, &input_stream, "Cubeb loopback input only",
- device_id.c_str(), &input_params, NULL, NULL, latency_frames,
- is_float ? data_cb_loop_input_only<float> : data_cb_loop_input_only<short>,
+ device_id.c_str(), &input_params, NULL, NULL,
+ latency_frames,
+ is_float ? data_cb_loop_input_only<float>
+ : data_cb_loop_input_only<short>,
state_cb_loop, user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
+ cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
/* setup an output stream */
- r = cubeb_stream_init(ctx, &output_stream, "Cubeb loopback output only",
- NULL, NULL, device_id.c_str(), &output_params, latency_frames,
- is_float ? data_cb_playback<float> : data_cb_playback<short>,
+ r = cubeb_stream_init(ctx, &output_stream, "Cubeb loopback output only", NULL,
+ NULL, device_id.c_str(), &output_params, latency_frames,
+ is_float ? data_cb_playback<float>
+ : data_cb_playback<short>,
state_cb_loop, user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_output_stream_at_exit(output_stream, cubeb_stream_destroy);
+ cleanup_output_stream_at_exit(output_stream, cubeb_stream_destroy);
cubeb_stream_start(input_stream);
cubeb_stream_start(output_stream);
@@ -569,22 +647,27 @@ void run_loopback_device_selection_test(bool is_float)
cubeb_stream_stop(output_stream);
cubeb_stream_stop(input_stream);
- /* access after stop should not happen, but lock just in case and to appease sanitization tools */
+ /* access after stop should not happen, but lock just in case and to appease
+ * sanitization tools */
std::lock_guard<std::mutex> lock(user_data->user_state_mutex);
std::vector<double> & output_frames = user_data->output_frames;
std::vector<double> & input_frames = user_data->input_frames;
ASSERT_LE(output_frames.size(), input_frames.size())
- << "#Output frames should be less or equal to #input frames";
+ << "#Output frames should be less or equal to #input frames";
- size_t phase = find_phase(user_data->output_frames, user_data->input_frames, NUM_FRAMES_TO_OUTPUT);
+ size_t phase = find_phase(user_data->output_frames, user_data->input_frames,
+ NUM_FRAMES_TO_OUTPUT);
/* extract vectors of just the relevant signal from output and input */
auto output_frames_signal_start = output_frames.begin();
auto output_frames_signal_end = output_frames.begin() + NUM_FRAMES_TO_OUTPUT;
- std::vector<double> trimmed_output_frames(output_frames_signal_start, output_frames_signal_end);
+ std::vector<double> trimmed_output_frames(output_frames_signal_start,
+ output_frames_signal_end);
auto input_frames_signal_start = input_frames.begin() + phase;
- auto input_frames_signal_end = input_frames.begin() + phase + NUM_FRAMES_TO_OUTPUT;
- std::vector<double> trimmed_input_frames(input_frames_signal_start, input_frames_signal_end);
+ auto input_frames_signal_end =
+ input_frames.begin() + phase + NUM_FRAMES_TO_OUTPUT;
+ std::vector<double> trimmed_input_frames(input_frames_signal_start,
+ input_frames_signal_end);
compare_signals(trimmed_output_frames, trimmed_input_frames);
}
diff --git a/test/test_overload_callback.cpp b/test/test_overload_callback.cpp
index 502489c..14c1ec3 100644
--- a/test/test_overload_callback.cpp
+++ b/test/test_overload_callback.cpp
@@ -9,23 +9,24 @@
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <stdio.h>
-#include <stdlib.h>
+#include "cubeb/cubeb.h"
+#include <atomic>
#include <math.h>
#include <memory>
-#include <atomic>
-#include "cubeb/cubeb.h"
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+#include <stdio.h>
+#include <stdlib.h>
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_S16LE
-std::atomic<bool> load_callback{ false };
+std::atomic<bool> load_callback{false};
static long
-data_cb(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+data_cb(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
if (load_callback) {
fprintf(stderr, "Sleeping...\n");
@@ -42,15 +43,20 @@ state_cb(cubeb_stream * stream, void * /*user*/, cubeb_state state)
switch (state) {
case CUBEB_STATE_STARTED:
- fprintf(stderr, "stream started\n"); break;
+ fprintf(stderr, "stream started\n");
+ break;
case CUBEB_STATE_STOPPED:
- fprintf(stderr, "stream stopped\n"); break;
+ fprintf(stderr, "stream stopped\n");
+ break;
case CUBEB_STATE_DRAINED:
- FAIL() << "this test is not supposed to drain"; break;
+ FAIL() << "this test is not supposed to drain";
+ break;
case CUBEB_STATE_ERROR:
- fprintf(stderr, "stream error\n"); break;
+ fprintf(stderr, "stream error\n");
+ break;
default:
- FAIL() << "this test is not supposed to have a weird state"; break;
+ FAIL() << "this test is not supposed to have a weird state";
+ break;
}
}
@@ -65,8 +71,8 @@ TEST(cubeb, overload_callback)
r = common_init(&ctx, "Cubeb callback overload");
ASSERT_EQ(r, CUBEB_OK);
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
// This test is specifically designed to test a behaviour of the WASAPI
// backend in a specific scenario.
@@ -83,13 +89,12 @@ TEST(cubeb, overload_callback)
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
ASSERT_EQ(r, CUBEB_OK);
- r = cubeb_stream_init(ctx, &stream, "Cubeb",
- NULL, NULL, NULL, &output_params,
+ r = cubeb_stream_init(ctx, &stream, "Cubeb", NULL, NULL, NULL, &output_params,
latency_frames, data_cb, state_cb, NULL);
ASSERT_EQ(r, CUBEB_OK);
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_stream_start(stream);
delay(500);
diff --git a/test/test_record.cpp b/test/test_record.cpp
index ba0c758..5b46b21 100644
--- a/test/test_record.cpp
+++ b/test/test_record.cpp
@@ -10,31 +10,32 @@
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <memory>
#include "cubeb/cubeb.h"
#include <atomic>
+#include <math.h>
+#include <memory>
+#include <stdio.h>
+#include <stdlib.h>
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE
-struct user_state_record
-{
- std::atomic<int> invalid_audio_value{ 0 };
+struct user_state_record {
+ std::atomic<int> invalid_audio_value{0};
};
-long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
+long
+data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer,
+ void * outputbuffer, long nframes)
{
- user_state_record * u = reinterpret_cast<user_state_record*>(user);
- float *b = (float *)inputbuffer;
+ user_state_record * u = reinterpret_cast<user_state_record *>(user);
+ float * b = (float *)inputbuffer;
- if (stream == NULL || inputbuffer == NULL || outputbuffer != NULL) {
+ if (stream == NULL || inputbuffer == NULL || outputbuffer != NULL) {
return CUBEB_ERROR;
}
@@ -48,18 +49,22 @@ long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer
return nframes;
}
-void state_cb_record(cubeb_stream * stream, void * /*user*/, cubeb_state state)
+void
+state_cb_record(cubeb_stream * stream, void * /*user*/, cubeb_state state)
{
if (stream == NULL)
return;
switch (state) {
case CUBEB_STATE_STARTED:
- fprintf(stderr, "stream started\n"); break;
+ fprintf(stderr, "stream started\n");
+ break;
case CUBEB_STATE_STOPPED:
- fprintf(stderr, "stream stopped\n"); break;
+ fprintf(stderr, "stream stopped\n");
+ break;
case CUBEB_STATE_DRAINED:
- fprintf(stderr, "stream drained\n"); break;
+ fprintf(stderr, "stream drained\n");
+ break;
default:
fprintf(stderr, "unknown stream state %d\n", state);
}
@@ -69,11 +74,12 @@ void state_cb_record(cubeb_stream * stream, void * /*user*/, cubeb_state state)
TEST(cubeb, record)
{
- if (cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr /*print_log*/) != CUBEB_OK) {
+ if (cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr /*print_log*/) !=
+ CUBEB_OK) {
fprintf(stderr, "Set log callback failed\n");
}
- cubeb *ctx;
- cubeb_stream *stream;
+ cubeb * ctx;
+ cubeb_stream * stream;
cubeb_stream_params params;
int r;
user_state_record stream_state;
@@ -81,8 +87,8 @@ TEST(cubeb, record)
r = common_init(&ctx, "Cubeb record example");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
/* This test needs an available input device, skip it if this host does not
* have one. */
@@ -96,12 +102,13 @@ TEST(cubeb, record)
params.layout = CUBEB_LAYOUT_UNDEFINED;
params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "Cubeb record (mono)", NULL, &params, NULL, nullptr,
- 4096, data_cb_record, state_cb_record, &stream_state);
+ r = cubeb_stream_init(ctx, &stream, "Cubeb record (mono)", NULL, &params,
+ NULL, nullptr, 4096, data_cb_record, state_cb_record,
+ &stream_state);
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_stream_start(stream);
delay(500);
diff --git a/test/test_resampler.cpp b/test/test_resampler.cpp
index 3d55db6..adbcfd8 100644
--- a/test/test_resampler.cpp
+++ b/test/test_resampler.cpp
@@ -7,12 +7,12 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif // NOMINMAX
-#include "gtest/gtest.h"
#include "common.h"
#include "cubeb_resampler_internal.h"
-#include <stdio.h>
+#include "gtest/gtest.h"
#include <algorithm>
#include <iostream>
+#include <stdio.h>
/* Windows cmath USE_MATH_DEFINE thing... */
const float PI = 3.14159265359f;
@@ -21,16 +21,8 @@ const float PI = 3.14159265359f;
* only part of the test suite is ran. */
#ifdef THOROUGH_TESTING
/* Some standard sample rates we're testing with. */
-const uint32_t sample_rates[] = {
- 8000,
- 16000,
- 32000,
- 44100,
- 48000,
- 88200,
- 96000,
- 192000
-};
+const uint32_t sample_rates[] = {8000, 16000, 32000, 44100,
+ 48000, 88200, 96000, 192000};
/* The maximum number of channels we're resampling. */
const uint32_t max_channels = 2;
/* The minimum an maximum number of milliseconds we're resampling for. This is
@@ -44,8 +36,8 @@ const uint32_t chunk_increment = 1;
const uint32_t sample_rates[] = {
8000,
- 44100,
- 48000,
+ 44100,
+ 48000,
};
const uint32_t max_channels = 2;
const uint32_t min_chunks = 10; /* ms */
@@ -68,7 +60,8 @@ const uint32_t chunk_increment = 10;
*/
/* Use the correct implementation of fopen, depending on the platform. */
-void fopen_portable(FILE ** f, const char * name, const char * mode)
+void
+fopen_portable(FILE ** f, const char * name, const char * mode)
{
#ifdef WIN32
fopen_s(f, name, mode);
@@ -77,8 +70,9 @@ void fopen_portable(FILE ** f, const char * name, const char * mode)
#endif
}
-template<typename T>
-void dump(const char * name, T * frames, size_t count)
+template <typename T>
+void
+dump(const char * name, T * frames, size_t count)
{
FILE * file;
fopen_portable(&file, name, "wb");
@@ -94,33 +88,42 @@ void dump(const char * name, T * frames, size_t count)
fclose(file);
}
#else
-template<typename T>
-void dump(const char * name, T * frames, size_t count)
-{ }
+template <typename T>
+void
+dump(const char * name, T * frames, size_t count)
+{
+}
#endif
// The more the ratio is far from 1, the more we accept a big error.
-float epsilon_tweak_ratio(float ratio)
+float
+epsilon_tweak_ratio(float ratio)
{
return ratio >= 1 ? ratio : 1 / ratio;
}
// Epsilon values for comparing resampled data to expected data.
// The bigger the resampling ratio is, the more lax we are about errors.
-template<typename T>
-T epsilon(float ratio);
+template <typename T>
+T
+epsilon(float ratio);
-template<>
-float epsilon(float ratio) {
+template <>
+float
+epsilon(float ratio)
+{
return 0.08f * epsilon_tweak_ratio(ratio);
}
-template<>
-int16_t epsilon(float ratio) {
+template <>
+int16_t
+epsilon(float ratio)
+{
return static_cast<int16_t>(10 * epsilon_tweak_ratio(ratio));
}
-void test_delay_lines(uint32_t delay_frames, uint32_t channels, uint32_t chunk_ms)
+void
+test_delay_lines(uint32_t delay_frames, uint32_t channels, uint32_t chunk_ms)
{
const size_t length_s = 2;
const size_t rate = 44100;
@@ -134,13 +137,14 @@ void test_delay_lines(uint32_t delay_frames, uint32_t channels, uint32_t chunk_m
/** Generate diracs every 100 frames, and check they are delayed. */
input.push_silence(length_frames * channels);
- for (uint32_t i = 0; i < input.length() - 1; i+=100) {
+ for (uint32_t i = 0; i < input.length() - 1; i += 100) {
input.data()[i + channel] = 0.5;
channel = (channel + 1) % channels;
}
dump("input.raw", input.data(), input.length());
- while(input.length()) {
- uint32_t to_pop = std::min<uint32_t>(input.length(), chunk_length * channels);
+ while (input.length()) {
+ uint32_t to_pop =
+ std::min<uint32_t>(input.length(), chunk_length * channels);
float * in = delay.input_buffer(to_pop / channels);
input.pop(in, to_pop);
delay.written(to_pop / channels);
@@ -150,7 +154,8 @@ void test_delay_lines(uint32_t delay_frames, uint32_t channels, uint32_t chunk_m
}
// Check the diracs have been shifted by `delay_frames` frames.
- for (uint32_t i = 0; i < output.length() - delay_frames * channels + 1; i+=100) {
+ for (uint32_t i = 0; i < output.length() - delay_frames * channels + 1;
+ i += 100) {
ASSERT_EQ(output.data()[i + channel + delay_frames * channels], 0.5);
channel = (channel + 1) % channels;
}
@@ -163,12 +168,16 @@ void test_delay_lines(uint32_t delay_frames, uint32_t channels, uint32_t chunk_m
* Then a sample-wise comparison is performed against a sine wave generated at
* the correct rate.
*/
-template<typename T>
-void test_resampler_one_way(uint32_t channels, uint32_t source_rate, uint32_t target_rate, float chunk_duration)
+template <typename T>
+void
+test_resampler_one_way(uint32_t channels, uint32_t source_rate,
+ uint32_t target_rate, float chunk_duration)
{
- size_t chunk_duration_in_source_frames = static_cast<uint32_t>(ceil(chunk_duration * source_rate / 1000.));
+ size_t chunk_duration_in_source_frames =
+ static_cast<uint32_t>(ceil(chunk_duration * source_rate / 1000.));
float resampling_ratio = static_cast<float>(source_rate) / target_rate;
- cubeb_resampler_speex_one_way<T> resampler(channels, source_rate, target_rate, 3);
+ cubeb_resampler_speex_one_way<T> resampler(channels, source_rate, target_rate,
+ 3);
auto_array<T> source(channels * source_rate * 10);
auto_array<T> destination(channels * target_rate * 10);
auto_array<T> expected(channels * target_rate * 10);
@@ -178,8 +187,8 @@ void test_resampler_one_way(uint32_t channels, uint32_t source_rate, uint32_t ta
// generate a sine wave in each channel, at the source sample rate
source.push_silence(channels * source_rate * buf_len);
- while(offset != source.length()) {
- float p = phase_index++ / static_cast<float>(source_rate);
+ while (offset != source.length()) {
+ float p = phase_index++ / static_cast<float>(source_rate);
for (uint32_t j = 0; j < channels; j++) {
source.data()[offset++] = 0.5 * sin(440. * 2 * PI * p);
}
@@ -189,14 +198,15 @@ void test_resampler_one_way(uint32_t channels, uint32_t source_rate, uint32_t ta
expected.push_silence(channels * target_rate * buf_len);
// generate a sine wave in each channel, at the target sample rate.
- // Insert silent samples at the beginning to account for the resampler latency.
+ // Insert silent samples at the beginning to account for the resampler
+ // latency.
offset = resampler.latency() * channels;
for (uint32_t i = 0; i < offset; i++) {
expected.data()[i] = 0.0f;
}
phase_index = 0;
while (offset != expected.length()) {
- float p = phase_index++ / static_cast<float>(target_rate);
+ float p = phase_index++ / static_cast<float>(target_rate);
for (uint32_t j = 0; j < channels; j++) {
expected.data()[offset++] = 0.5 * sin(440. * 2 * PI * p);
}
@@ -207,14 +217,16 @@ void test_resampler_one_way(uint32_t channels, uint32_t source_rate, uint32_t ta
// resample by chunk
uint32_t write_offset = 0;
destination.push_silence(channels * target_rate * buf_len);
- while (write_offset < destination.length())
- {
- size_t output_frames = static_cast<uint32_t>(floor(chunk_duration_in_source_frames / resampling_ratio));
+ while (write_offset < destination.length()) {
+ size_t output_frames = static_cast<uint32_t>(
+ floor(chunk_duration_in_source_frames / resampling_ratio));
uint32_t input_frames = resampler.input_needed_for_output(output_frames);
resampler.input(source.data(), input_frames);
source.pop(nullptr, input_frames * channels);
- resampler.output(destination.data() + write_offset,
- std::min(output_frames, (destination.length() - write_offset) / channels));
+ resampler.output(
+ destination.data() + write_offset,
+ std::min(output_frames,
+ (destination.length() - write_offset) / channels));
write_offset += output_frames * channels;
}
@@ -225,36 +237,38 @@ void test_resampler_one_way(uint32_t channels, uint32_t source_rate, uint32_t ta
for (uint32_t i = resampler.latency() + 1; i < expected.length(); i++) {
float diff = fabs(expected.data()[i] - destination.data()[i]);
if (diff > epsilon<T>(resampling_ratio)) {
- fprintf(stderr, "divergence at %d: %f %f (delta %f)\n", i, expected.data()[i], destination.data()[i], diff);
+ fprintf(stderr, "divergence at %d: %f %f (delta %f)\n", i,
+ expected.data()[i], destination.data()[i], diff);
fuzzy_equal = false;
}
}
ASSERT_TRUE(fuzzy_equal);
}
-template<typename T>
-cubeb_sample_format cubeb_format();
+template <typename T>
+cubeb_sample_format
+cubeb_format();
-template<>
-cubeb_sample_format cubeb_format<float>()
+template <>
+cubeb_sample_format
+cubeb_format<float>()
{
return CUBEB_SAMPLE_FLOAT32NE;
}
-template<>
-cubeb_sample_format cubeb_format<short>()
+template <>
+cubeb_sample_format
+cubeb_format<short>()
{
return CUBEB_SAMPLE_S16NE;
}
struct osc_state {
osc_state()
- : input_phase_index(0)
- , output_phase_index(0)
- , output_offset(0)
- , input_channels(0)
- , output_channels(0)
- {}
+ : input_phase_index(0), output_phase_index(0), output_offset(0),
+ input_channels(0), output_channels(0)
+ {
+ }
uint32_t input_phase_index;
uint32_t max_output_phase_index;
uint32_t output_phase_index;
@@ -267,12 +281,13 @@ struct osc_state {
auto_array<float> output;
};
-uint32_t fill_with_sine(float * buf, uint32_t rate, uint32_t channels,
- uint32_t frames, uint32_t initial_phase)
+uint32_t
+fill_with_sine(float * buf, uint32_t rate, uint32_t channels, uint32_t frames,
+ uint32_t initial_phase)
{
uint32_t offset = 0;
for (uint32_t i = 0; i < frames; i++) {
- float p = initial_phase++ / static_cast<float>(rate);
+ float p = initial_phase++ / static_cast<float>(rate);
for (uint32_t j = 0; j < channels; j++) {
buf[offset++] = 0.5 * sin(440. * 2 * PI * p);
}
@@ -280,48 +295,51 @@ uint32_t fill_with_sine(float * buf, uint32_t rate, uint32_t channels,
return initial_phase;
}
-long data_cb_resampler(cubeb_stream * /*stm*/, void * user_ptr,
- const void * input_buffer, void * output_buffer, long frame_count)
+long
+data_cb_resampler(cubeb_stream * /*stm*/, void * user_ptr,
+ const void * input_buffer, void * output_buffer,
+ long frame_count)
{
- osc_state * state = reinterpret_cast<osc_state*>(user_ptr);
- const float * in = reinterpret_cast<const float*>(input_buffer);
- float * out = reinterpret_cast<float*>(output_buffer);
+ osc_state * state = reinterpret_cast<osc_state *>(user_ptr);
+ const float * in = reinterpret_cast<const float *>(input_buffer);
+ float * out = reinterpret_cast<float *>(output_buffer);
state->input.push(in, frame_count * state->input_channels);
/* Check how much output frames we need to write */
- uint32_t remaining = state->max_output_phase_index - state->output_phase_index;
+ uint32_t remaining =
+ state->max_output_phase_index - state->output_phase_index;
uint32_t to_write = std::min<uint32_t>(remaining, frame_count);
- state->output_phase_index = fill_with_sine(out,
- state->target_rate,
- state->output_channels,
- to_write,
- state->output_phase_index);
+ state->output_phase_index =
+ fill_with_sine(out, state->target_rate, state->output_channels, to_write,
+ state->output_phase_index);
return to_write;
}
-template<typename T>
-bool array_fuzzy_equal(const auto_array<T>& lhs, const auto_array<T>& rhs, T epsi)
+template <typename T>
+bool
+array_fuzzy_equal(const auto_array<T> & lhs, const auto_array<T> & rhs, T epsi)
{
uint32_t len = std::min(lhs.length(), rhs.length());
for (uint32_t i = 0; i < len; i++) {
if (fabs(lhs.at(i) - rhs.at(i)) > epsi) {
- std::cout << "not fuzzy equal at index: " << i
- << " lhs: " << lhs.at(i) << " rhs: " << rhs.at(i)
+ std::cout << "not fuzzy equal at index: " << i << " lhs: " << lhs.at(i)
+ << " rhs: " << rhs.at(i)
<< " delta: " << fabs(lhs.at(i) - rhs.at(i))
- << " epsilon: "<< epsi << std::endl;
+ << " epsilon: " << epsi << std::endl;
return false;
}
}
return true;
}
-template<typename T>
-void test_resampler_duplex(uint32_t input_channels, uint32_t output_channels,
- uint32_t input_rate, uint32_t output_rate,
- uint32_t target_rate, float chunk_duration)
+template <typename T>
+void
+test_resampler_duplex(uint32_t input_channels, uint32_t output_channels,
+ uint32_t input_rate, uint32_t output_rate,
+ uint32_t target_rate, float chunk_duration)
{
cubeb_stream_params input_params;
cubeb_stream_params output_params;
@@ -336,47 +354,48 @@ void test_resampler_duplex(uint32_t input_channels, uint32_t output_channels,
input_params.prefs = output_params.prefs = CUBEB_STREAM_PREF_NONE;
long got;
- cubeb_resampler * resampler =
- cubeb_resampler_create((cubeb_stream*)nullptr, &input_params, &output_params, target_rate,
- data_cb_resampler, (void*)&state, CUBEB_RESAMPLER_QUALITY_VOIP,
- CUBEB_RESAMPLER_RECLOCK_NONE);
+ cubeb_resampler * resampler = cubeb_resampler_create(
+ (cubeb_stream *)nullptr, &input_params, &output_params, target_rate,
+ data_cb_resampler, (void *)&state, CUBEB_RESAMPLER_QUALITY_VOIP,
+ CUBEB_RESAMPLER_RECLOCK_NONE);
long latency = cubeb_resampler_latency(resampler);
const uint32_t duration_s = 2;
int32_t duration_frames = duration_s * target_rate;
- uint32_t input_array_frame_count = ceil(chunk_duration * input_rate / 1000) + ceilf(static_cast<float>(input_rate) / target_rate) * 2;
+ uint32_t input_array_frame_count =
+ ceil(chunk_duration * input_rate / 1000) +
+ ceilf(static_cast<float>(input_rate) / target_rate) * 2;
uint32_t output_array_frame_count = chunk_duration * output_rate / 1000;
auto_array<float> input_buffer(input_channels * input_array_frame_count);
auto_array<float> output_buffer(output_channels * output_array_frame_count);
auto_array<float> expected_resampled_input(input_channels * duration_frames);
- auto_array<float> expected_resampled_output(output_channels * output_rate * duration_s);
+ auto_array<float> expected_resampled_output(output_channels * output_rate *
+ duration_s);
state.max_output_phase_index = duration_s * target_rate;
expected_resampled_input.push_silence(input_channels * duration_frames);
- expected_resampled_output.push_silence(output_channels * output_rate * duration_s);
+ expected_resampled_output.push_silence(output_channels * output_rate *
+ duration_s);
/* expected output is a 440Hz sine wave at 16kHz */
- fill_with_sine(expected_resampled_input.data() + latency,
- target_rate, input_channels, duration_frames - latency, 0);
+ fill_with_sine(expected_resampled_input.data() + latency, target_rate,
+ input_channels, duration_frames - latency, 0);
/* expected output is a 440Hz sine wave at 32kHz */
- fill_with_sine(expected_resampled_output.data() + latency,
- output_rate, output_channels, output_rate * duration_s - latency, 0);
+ fill_with_sine(expected_resampled_output.data() + latency, output_rate,
+ output_channels, output_rate * duration_s - latency, 0);
while (state.output_phase_index != state.max_output_phase_index) {
uint32_t leftover_samples = input_buffer.length() * input_channels;
input_buffer.reserve(input_array_frame_count);
- state.input_phase_index = fill_with_sine(input_buffer.data() + leftover_samples,
- input_rate,
- input_channels,
- input_array_frame_count - leftover_samples,
- state.input_phase_index);
+ state.input_phase_index = fill_with_sine(
+ input_buffer.data() + leftover_samples, input_rate, input_channels,
+ input_array_frame_count - leftover_samples, state.input_phase_index);
long input_consumed = input_array_frame_count;
input_buffer.set_length(input_array_frame_count);
- got = cubeb_resampler_fill(resampler,
- input_buffer.data(), &input_consumed,
+ got = cubeb_resampler_fill(resampler, input_buffer.data(), &input_consumed,
output_buffer.data(), output_array_frame_count);
/* handle leftover input */
@@ -389,16 +408,20 @@ void test_resampler_duplex(uint32_t input_channels, uint32_t output_channels,
state.output.push(output_buffer.data(), got * state.output_channels);
}
- dump("input_expected.raw", expected_resampled_input.data(), expected_resampled_input.length());
- dump("output_expected.raw", expected_resampled_output.data(), expected_resampled_output.length());
+ dump("input_expected.raw", expected_resampled_input.data(),
+ expected_resampled_input.length());
+ dump("output_expected.raw", expected_resampled_output.data(),
+ expected_resampled_output.length());
dump("input.raw", state.input.data(), state.input.length());
dump("output.raw", state.output.data(), state.output.length());
- // This is disabled because the latency estimation in the resampler code is
- // slightly off so we can generate expected vectors.
- // See https://github.com/kinetiknz/cubeb/issues/93
- // ASSERT_TRUE(array_fuzzy_equal(state.input, expected_resampled_input, epsilon<T>(input_rate/target_rate)));
- // ASSERT_TRUE(array_fuzzy_equal(state.output, expected_resampled_output, epsilon<T>(output_rate/target_rate)));
+ // This is disabled because the latency estimation in the resampler code is
+ // slightly off so we can generate expected vectors.
+ // See https://github.com/kinetiknz/cubeb/issues/93
+ // ASSERT_TRUE(array_fuzzy_equal(state.input, expected_resampled_input,
+ // epsilon<T>(input_rate/target_rate)));
+ // ASSERT_TRUE(array_fuzzy_equal(state.output, expected_resampled_output,
+ // epsilon<T>(output_rate/target_rate)));
cubeb_resampler_destroy(resampler);
}
@@ -409,13 +432,20 @@ TEST(cubeb, resampler_one_way)
{
/* Test one way resamplers */
for (uint32_t channels = 1; channels <= max_channels; channels++) {
- for (uint32_t source_rate = 0; source_rate < array_size(sample_rates); source_rate++) {
- for (uint32_t dest_rate = 0; dest_rate < array_size(sample_rates); dest_rate++) {
- for (uint32_t chunk_duration = min_chunks; chunk_duration < max_chunks; chunk_duration+=chunk_increment) {
- fprintf(stderr, "one_way: channels: %d, source_rate: %d, dest_rate: %d, chunk_duration: %d\n",
- channels, sample_rates[source_rate], sample_rates[dest_rate], chunk_duration);
+ for (uint32_t source_rate = 0; source_rate < array_size(sample_rates);
+ source_rate++) {
+ for (uint32_t dest_rate = 0; dest_rate < array_size(sample_rates);
+ dest_rate++) {
+ for (uint32_t chunk_duration = min_chunks; chunk_duration < max_chunks;
+ chunk_duration += chunk_increment) {
+ fprintf(stderr,
+ "one_way: channels: %d, source_rate: %d, dest_rate: %d, "
+ "chunk_duration: %d\n",
+ channels, sample_rates[source_rate], sample_rates[dest_rate],
+ chunk_duration);
test_resampler_one_way<float>(channels, sample_rates[source_rate],
- sample_rates[dest_rate], chunk_duration);
+ sample_rates[dest_rate],
+ chunk_duration);
}
}
}
@@ -424,19 +454,27 @@ TEST(cubeb, resampler_one_way)
TEST(cubeb, DISABLED_resampler_duplex)
{
- for (uint32_t input_channels = 1; input_channels <= max_channels; input_channels++) {
- for (uint32_t output_channels = 1; output_channels <= max_channels; output_channels++) {
- for (uint32_t source_rate_input = 0; source_rate_input < array_size(sample_rates); source_rate_input++) {
- for (uint32_t source_rate_output = 0; source_rate_output < array_size(sample_rates); source_rate_output++) {
- for (uint32_t dest_rate = 0; dest_rate < array_size(sample_rates); dest_rate++) {
- for (uint32_t chunk_duration = min_chunks; chunk_duration < max_chunks; chunk_duration+=chunk_increment) {
- fprintf(stderr, "input channels:%d output_channels:%d input_rate:%d "
- "output_rate:%d target_rate:%d chunk_ms:%d\n",
- input_channels, output_channels,
- sample_rates[source_rate_input],
- sample_rates[source_rate_output],
- sample_rates[dest_rate],
- chunk_duration);
+ for (uint32_t input_channels = 1; input_channels <= max_channels;
+ input_channels++) {
+ for (uint32_t output_channels = 1; output_channels <= max_channels;
+ output_channels++) {
+ for (uint32_t source_rate_input = 0;
+ source_rate_input < array_size(sample_rates); source_rate_input++) {
+ for (uint32_t source_rate_output = 0;
+ source_rate_output < array_size(sample_rates);
+ source_rate_output++) {
+ for (uint32_t dest_rate = 0; dest_rate < array_size(sample_rates);
+ dest_rate++) {
+ for (uint32_t chunk_duration = min_chunks;
+ chunk_duration < max_chunks;
+ chunk_duration += chunk_increment) {
+ fprintf(stderr,
+ "input channels:%d output_channels:%d input_rate:%d "
+ "output_rate:%d target_rate:%d chunk_ms:%d\n",
+ input_channels, output_channels,
+ sample_rates[source_rate_input],
+ sample_rates[source_rate_output], sample_rates[dest_rate],
+ chunk_duration);
test_resampler_duplex<float>(input_channels, output_channels,
sample_rates[source_rate_input],
sample_rates[source_rate_output],
@@ -453,19 +491,21 @@ TEST(cubeb, DISABLED_resampler_duplex)
TEST(cubeb, resampler_delay_line)
{
for (uint32_t channel = 1; channel <= 2; channel++) {
- for (uint32_t delay_frames = 4; delay_frames <= 40; delay_frames+=chunk_increment) {
+ for (uint32_t delay_frames = 4; delay_frames <= 40;
+ delay_frames += chunk_increment) {
for (uint32_t chunk_size = 10; chunk_size <= 30; chunk_size++) {
- fprintf(stderr, "channel: %d, delay_frames: %d, chunk_size: %d\n",
- channel, delay_frames, chunk_size);
+ fprintf(stderr, "channel: %d, delay_frames: %d, chunk_size: %d\n",
+ channel, delay_frames, chunk_size);
test_delay_lines(delay_frames, channel, chunk_size);
}
}
}
}
-long test_output_only_noop_data_cb(cubeb_stream * /*stm*/, void * /*user_ptr*/,
- const void * input_buffer,
- void * output_buffer, long frame_count)
+long
+test_output_only_noop_data_cb(cubeb_stream * /*stm*/, void * /*user_ptr*/,
+ const void * input_buffer, void * output_buffer,
+ long frame_count)
{
EXPECT_TRUE(output_buffer);
EXPECT_TRUE(!input_buffer);
@@ -482,26 +522,26 @@ TEST(cubeb, resampler_output_only_noop)
output_params.format = CUBEB_SAMPLE_FLOAT32NE;
target_rate = output_params.rate;
- cubeb_resampler * resampler =
- cubeb_resampler_create((cubeb_stream*)nullptr, nullptr, &output_params, target_rate,
- test_output_only_noop_data_cb, nullptr,
- CUBEB_RESAMPLER_QUALITY_VOIP,
- CUBEB_RESAMPLER_RECLOCK_NONE);
+ cubeb_resampler * resampler = cubeb_resampler_create(
+ (cubeb_stream *)nullptr, nullptr, &output_params, target_rate,
+ test_output_only_noop_data_cb, nullptr, CUBEB_RESAMPLER_QUALITY_VOIP,
+ CUBEB_RESAMPLER_RECLOCK_NONE);
const long out_frames = 128;
float out_buffer[out_frames];
long got;
- got = cubeb_resampler_fill(resampler, nullptr, nullptr,
- out_buffer, out_frames);
+ got =
+ cubeb_resampler_fill(resampler, nullptr, nullptr, out_buffer, out_frames);
ASSERT_EQ(got, out_frames);
cubeb_resampler_destroy(resampler);
}
-long test_drain_data_cb(cubeb_stream * /*stm*/, void * user_ptr,
- const void * input_buffer,
- void * output_buffer, long frame_count)
+long
+test_drain_data_cb(cubeb_stream * /*stm*/, void * user_ptr,
+ const void * input_buffer, void * output_buffer,
+ long frame_count)
{
EXPECT_TRUE(output_buffer);
EXPECT_TRUE(!input_buffer);
@@ -521,19 +561,18 @@ TEST(cubeb, resampler_drain)
target_rate = 48000;
int cb_count = 0;
- cubeb_resampler * resampler =
- cubeb_resampler_create((cubeb_stream*)nullptr, nullptr, &output_params, target_rate,
- test_drain_data_cb, &cb_count,
- CUBEB_RESAMPLER_QUALITY_VOIP,
- CUBEB_RESAMPLER_RECLOCK_NONE);
+ cubeb_resampler * resampler = cubeb_resampler_create(
+ (cubeb_stream *)nullptr, nullptr, &output_params, target_rate,
+ test_drain_data_cb, &cb_count, CUBEB_RESAMPLER_QUALITY_VOIP,
+ CUBEB_RESAMPLER_RECLOCK_NONE);
const long out_frames = 128;
float out_buffer[out_frames];
long got;
do {
- got = cubeb_resampler_fill(resampler, nullptr, nullptr,
- out_buffer, out_frames);
+ got = cubeb_resampler_fill(resampler, nullptr, nullptr, out_buffer,
+ out_frames);
} while (got == out_frames);
/* The callback should be called once but not again after returning <
@@ -545,16 +584,18 @@ TEST(cubeb, resampler_drain)
// gtest does not support using ASSERT_EQ and friend in a function that returns
// a value.
-void check_output(const void * input_buffer, void * output_buffer, long frame_count)
+void
+check_output(const void * input_buffer, void * output_buffer, long frame_count)
{
ASSERT_EQ(input_buffer, nullptr);
ASSERT_EQ(frame_count, 256);
ASSERT_TRUE(!!output_buffer);
}
-long cb_passthrough_resampler_output(cubeb_stream * /*stm*/, void * /*user_ptr*/,
- const void * input_buffer,
- void * output_buffer, long frame_count)
+long
+cb_passthrough_resampler_output(cubeb_stream * /*stm*/, void * /*user_ptr*/,
+ const void * input_buffer, void * output_buffer,
+ long frame_count)
{
check_output(input_buffer, output_buffer, frame_count);
return frame_count;
@@ -562,7 +603,8 @@ long cb_passthrough_resampler_output(cubeb_stream * /*stm*/, void * /*user_ptr*/
TEST(cubeb, resampler_passthrough_output_only)
{
- // Test that the passthrough resampler works when there is only an output stream.
+ // Test that the passthrough resampler works when there is only an output
+ // stream.
cubeb_stream_params output_params;
const size_t output_channels = 2;
@@ -571,11 +613,10 @@ TEST(cubeb, resampler_passthrough_output_only)
output_params.format = CUBEB_SAMPLE_FLOAT32NE;
int target_rate = output_params.rate;
- cubeb_resampler * resampler =
- cubeb_resampler_create((cubeb_stream*)nullptr, nullptr, &output_params,
- target_rate, cb_passthrough_resampler_output, nullptr,
- CUBEB_RESAMPLER_QUALITY_VOIP,
- CUBEB_RESAMPLER_RECLOCK_NONE);
+ cubeb_resampler * resampler = cubeb_resampler_create(
+ (cubeb_stream *)nullptr, nullptr, &output_params, target_rate,
+ cb_passthrough_resampler_output, nullptr, CUBEB_RESAMPLER_QUALITY_VOIP,
+ CUBEB_RESAMPLER_RECLOCK_NONE);
float output_buffer[output_channels * 256];
@@ -590,16 +631,18 @@ TEST(cubeb, resampler_passthrough_output_only)
// gtest does not support using ASSERT_EQ and friend in a function that returns
// a value.
-void check_input(const void * input_buffer, void * output_buffer, long frame_count)
+void
+check_input(const void * input_buffer, void * output_buffer, long frame_count)
{
ASSERT_EQ(output_buffer, nullptr);
ASSERT_EQ(frame_count, 256);
ASSERT_TRUE(!!input_buffer);
}
-long cb_passthrough_resampler_input(cubeb_stream * /*stm*/, void * /*user_ptr*/,
- const void * input_buffer,
- void * output_buffer, long frame_count)
+long
+cb_passthrough_resampler_input(cubeb_stream * /*stm*/, void * /*user_ptr*/,
+ const void * input_buffer, void * output_buffer,
+ long frame_count)
{
check_input(input_buffer, output_buffer, frame_count);
return frame_count;
@@ -607,7 +650,8 @@ long cb_passthrough_resampler_input(cubeb_stream * /*stm*/, void * /*user_ptr*/,
TEST(cubeb, resampler_passthrough_input_only)
{
- // Test that the passthrough resampler works when there is only an output stream.
+ // Test that the passthrough resampler works when there is only an output
+ // stream.
cubeb_stream_params input_params;
const size_t input_channels = 2;
@@ -616,11 +660,10 @@ TEST(cubeb, resampler_passthrough_input_only)
input_params.format = CUBEB_SAMPLE_FLOAT32NE;
int target_rate = input_params.rate;
- cubeb_resampler * resampler =
- cubeb_resampler_create((cubeb_stream*)nullptr, &input_params, nullptr,
- target_rate, cb_passthrough_resampler_input, nullptr,
- CUBEB_RESAMPLER_QUALITY_VOIP,
- CUBEB_RESAMPLER_RECLOCK_NONE);
+ cubeb_resampler * resampler = cubeb_resampler_create(
+ (cubeb_stream *)nullptr, &input_params, nullptr, target_rate,
+ cb_passthrough_resampler_input, nullptr, CUBEB_RESAMPLER_QUALITY_VOIP,
+ CUBEB_RESAMPLER_RECLOCK_NONE);
float input_buffer[input_channels * 256];
@@ -634,11 +677,12 @@ TEST(cubeb, resampler_passthrough_input_only)
cubeb_resampler_destroy(resampler);
}
-template<typename T>
-long seq(T* array, int stride, long start, long count)
+template <typename T>
+long
+seq(T * array, int stride, long start, long count)
{
uint32_t output_idx = 0;
- for(int i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
for (int j = 0; j < stride; j++) {
array[output_idx + j] = static_cast<T>(start + i);
}
@@ -647,8 +691,9 @@ long seq(T* array, int stride, long start, long count)
return start + count;
}
-template<typename T>
-void is_seq(T * array, int stride, long count, long expected_start)
+template <typename T>
+void
+is_seq(T * array, int stride, long count, long expected_start)
{
uint32_t output_index = 0;
for (long i = 0; i < count; i++) {
@@ -659,8 +704,9 @@ void is_seq(T * array, int stride, long count, long expected_start)
}
}
-template<typename T>
-void is_not_seq(T * array, int stride, long count, long expected_start)
+template <typename T>
+void
+is_not_seq(T * array, int stride, long count, long expected_start)
{
uint32_t output_index = 0;
for (long i = 0; i < count; i++) {
@@ -677,22 +723,25 @@ struct closure {
// gtest does not support using ASSERT_EQ and friend in a function that returns
// a value.
-template<typename T>
-void check_duplex(const T * input_buffer,
- T * output_buffer, long frame_count,
- int input_channel_count)
+template <typename T>
+void
+check_duplex(const T * input_buffer, T * output_buffer, long frame_count,
+ int input_channel_count)
{
ASSERT_EQ(frame_count, 256);
// Silence scan-build warning.
- ASSERT_TRUE(!!output_buffer); assert(output_buffer);
- ASSERT_TRUE(!!input_buffer); assert(input_buffer);
+ ASSERT_TRUE(!!output_buffer);
+ assert(output_buffer);
+ ASSERT_TRUE(!!input_buffer);
+ assert(input_buffer);
int output_index = 0;
int input_index = 0;
for (int i = 0; i < frame_count; i++) {
// output is two channels, input one or two channels.
if (input_channel_count == 1) {
- output_buffer[output_index] = output_buffer[output_index + 1] = input_buffer[i];
+ output_buffer[output_index] = output_buffer[output_index + 1] =
+ input_buffer[i];
} else if (input_channel_count == 2) {
output_buffer[output_index] = input_buffer[input_index];
output_buffer[output_index + 1] = input_buffer[input_index + 1];
@@ -702,18 +751,18 @@ void check_duplex(const T * input_buffer,
}
}
-long cb_passthrough_resampler_duplex(cubeb_stream * /*stm*/, void * user_ptr,
- const void * input_buffer,
- void * output_buffer, long frame_count)
+long
+cb_passthrough_resampler_duplex(cubeb_stream * /*stm*/, void * user_ptr,
+ const void * input_buffer, void * output_buffer,
+ long frame_count)
{
- closure * c = reinterpret_cast<closure*>(user_ptr);
- check_duplex<float>(static_cast<const float*>(input_buffer),
- static_cast<float*>(output_buffer),
- frame_count, c->input_channel_count);
+ closure * c = reinterpret_cast<closure *>(user_ptr);
+ check_duplex<float>(static_cast<const float *>(input_buffer),
+ static_cast<float *>(output_buffer), frame_count,
+ c->input_channel_count);
return frame_count;
}
-
TEST(cubeb, resampler_passthrough_duplex_callback_reordering)
{
// Test that when pre-buffering on resampler creation, we can survive an input
@@ -738,11 +787,10 @@ TEST(cubeb, resampler_passthrough_duplex_callback_reordering)
closure c;
c.input_channel_count = input_channels;
- cubeb_resampler * resampler =
- cubeb_resampler_create((cubeb_stream*)nullptr, &input_params, &output_params,
- target_rate, cb_passthrough_resampler_duplex, &c,
- CUBEB_RESAMPLER_QUALITY_VOIP,
- CUBEB_RESAMPLER_RECLOCK_NONE);
+ cubeb_resampler * resampler = cubeb_resampler_create(
+ (cubeb_stream *)nullptr, &input_params, &output_params, target_rate,
+ cb_passthrough_resampler_duplex, &c, CUBEB_RESAMPLER_QUALITY_VOIP,
+ CUBEB_RESAMPLER_RECLOCK_NONE);
const long BUF_BASE_SIZE = 256;
float input_buffer_prebuffer[input_channels * BUF_BASE_SIZE * 2];
@@ -753,12 +801,14 @@ TEST(cubeb, resampler_passthrough_duplex_callback_reordering)
long seq_idx = 0;
long output_seq_idx = 0;
- long prebuffer_frames = ARRAY_LENGTH(input_buffer_prebuffer) / input_params.channels;
- seq_idx = seq(input_buffer_prebuffer, input_channels, seq_idx,
- prebuffer_frames);
+ long prebuffer_frames =
+ ARRAY_LENGTH(input_buffer_prebuffer) / input_params.channels;
+ seq_idx =
+ seq(input_buffer_prebuffer, input_channels, seq_idx, prebuffer_frames);
- long got = cubeb_resampler_fill(resampler, input_buffer_prebuffer, &prebuffer_frames,
- output_buffer, BUF_BASE_SIZE);
+ long got =
+ cubeb_resampler_fill(resampler, input_buffer_prebuffer, &prebuffer_frames,
+ output_buffer, BUF_BASE_SIZE);
output_seq_idx += BUF_BASE_SIZE;
@@ -771,23 +821,29 @@ TEST(cubeb, resampler_passthrough_duplex_callback_reordering)
// Simulate that sometimes, we don't have the input callback on time
if (i != 0 && (i % 100) == 0) {
long zero = 0;
- got = cubeb_resampler_fill(resampler, input_buffer_normal /* unused here */,
- &zero, output_buffer, BUF_BASE_SIZE);
+ got =
+ cubeb_resampler_fill(resampler, input_buffer_normal /* unused here */,
+ &zero, output_buffer, BUF_BASE_SIZE);
is_seq(output_buffer, 2, BUF_BASE_SIZE, output_seq_idx);
output_seq_idx += BUF_BASE_SIZE;
} else if (i != 0 && (i % 100) == 1) {
// if this is the case, the on the next iteration, we'll have twice the
// amount of input frames
- seq_idx = seq(input_buffer_glitch, input_channels, seq_idx, BUF_BASE_SIZE * 2);
+ seq_idx =
+ seq(input_buffer_glitch, input_channels, seq_idx, BUF_BASE_SIZE * 2);
frames = 2 * BUF_BASE_SIZE;
- got = cubeb_resampler_fill(resampler, input_buffer_glitch, &frames, output_buffer, BUF_BASE_SIZE);
+ got = cubeb_resampler_fill(resampler, input_buffer_glitch, &frames,
+ output_buffer, BUF_BASE_SIZE);
is_seq(output_buffer, 2, BUF_BASE_SIZE, output_seq_idx);
output_seq_idx += BUF_BASE_SIZE;
} else {
- // normal case
- seq_idx = seq(input_buffer_normal, input_channels, seq_idx, BUF_BASE_SIZE);
+ // normal case
+ seq_idx =
+ seq(input_buffer_normal, input_channels, seq_idx, BUF_BASE_SIZE);
long normal_input_frame_count = 256;
- got = cubeb_resampler_fill(resampler, input_buffer_normal, &normal_input_frame_count, output_buffer, BUF_BASE_SIZE);
+ got = cubeb_resampler_fill(resampler, input_buffer_normal,
+ &normal_input_frame_count, output_buffer,
+ BUF_BASE_SIZE);
is_seq(output_buffer, 2, BUF_BASE_SIZE, output_seq_idx);
output_seq_idx += BUF_BASE_SIZE;
}
@@ -822,10 +878,10 @@ TEST(cubeb, resampler_drift_drop_data)
closure c;
c.input_channel_count = input_channels;
- cubeb_resampler * resampler =
- cubeb_resampler_create((cubeb_stream*)nullptr, &input_params, &output_params,
- target_rate, cb_passthrough_resampler_duplex, &c,
- CUBEB_RESAMPLER_QUALITY_VOIP, CUBEB_RESAMPLER_RECLOCK_NONE);
+ cubeb_resampler * resampler = cubeb_resampler_create(
+ (cubeb_stream *)nullptr, &input_params, &output_params, target_rate,
+ cb_passthrough_resampler_duplex, &c, CUBEB_RESAMPLER_QUALITY_VOIP,
+ CUBEB_RESAMPLER_RECLOCK_NONE);
const long BUF_BASE_SIZE = 256;
@@ -836,20 +892,24 @@ TEST(cubeb, resampler_drift_drop_data)
// Number buffer used for pre-buffering, that some backends do.
const long PREBUFFER_FACTOR = 2;
- std::vector<float> input_buffer_prebuffer(input_channels * BUF_BASE_SIZE * PREBUFFER_FACTOR);
- std::vector<float> input_buffer_glitch(input_channels * BUF_BASE_SIZE * UNDERRUN_FACTOR);
+ std::vector<float> input_buffer_prebuffer(input_channels * BUF_BASE_SIZE *
+ PREBUFFER_FACTOR);
+ std::vector<float> input_buffer_glitch(input_channels * BUF_BASE_SIZE *
+ UNDERRUN_FACTOR);
std::vector<float> input_buffer_normal(input_channels * BUF_BASE_SIZE);
std::vector<float> output_buffer(output_channels * BUF_BASE_SIZE);
long seq_idx = 0;
long output_seq_idx = 0;
- long prebuffer_frames = input_buffer_prebuffer.size() / input_params.channels;
+ long prebuffer_frames =
+ input_buffer_prebuffer.size() / input_params.channels;
seq_idx = seq(input_buffer_prebuffer.data(), input_channels, seq_idx,
- prebuffer_frames);
+ prebuffer_frames);
- long got = cubeb_resampler_fill(resampler, input_buffer_prebuffer.data(), &prebuffer_frames,
- output_buffer.data(), BUF_BASE_SIZE);
+ long got = cubeb_resampler_fill(resampler, input_buffer_prebuffer.data(),
+ &prebuffer_frames, output_buffer.data(),
+ BUF_BASE_SIZE);
output_seq_idx += BUF_BASE_SIZE;
@@ -861,30 +921,40 @@ TEST(cubeb, resampler_drift_drop_data)
long int frames = BUF_BASE_SIZE;
if (i != 0 && (i % 100) == 1) {
// Once in a while, the output thread misses its deadline.
- // The input thread still produces data, so it ends up accumulating. Simulate this by providing a
- // much bigger input buffer. Check that the sequence is now unaligned, meaning we've dropped data
- // to keep everything in sync.
- seq_idx = seq(input_buffer_glitch.data(), input_channels, seq_idx, BUF_BASE_SIZE * UNDERRUN_FACTOR);
+ // The input thread still produces data, so it ends up accumulating.
+ // Simulate this by providing a much bigger input buffer. Check that the
+ // sequence is now unaligned, meaning we've dropped data to keep
+ // everything in sync.
+ seq_idx = seq(input_buffer_glitch.data(), input_channels, seq_idx,
+ BUF_BASE_SIZE * UNDERRUN_FACTOR);
frames = BUF_BASE_SIZE * UNDERRUN_FACTOR;
- got = cubeb_resampler_fill(resampler, input_buffer_glitch.data(), &frames, output_buffer.data(), BUF_BASE_SIZE);
+ got =
+ cubeb_resampler_fill(resampler, input_buffer_glitch.data(), &frames,
+ output_buffer.data(), BUF_BASE_SIZE);
is_seq(output_buffer.data(), 2, BUF_BASE_SIZE, output_seq_idx);
output_seq_idx += BUF_BASE_SIZE;
- }
- else if (i != 0 && (i % 100) == 2) {
+ } else if (i != 0 && (i % 100) == 2) {
// On the next iteration, the sequence should be broken
- seq_idx = seq(input_buffer_normal.data(), input_channels, seq_idx, BUF_BASE_SIZE);
+ seq_idx = seq(input_buffer_normal.data(), input_channels, seq_idx,
+ BUF_BASE_SIZE);
long normal_input_frame_count = 256;
- got = cubeb_resampler_fill(resampler, input_buffer_normal.data(), &normal_input_frame_count, output_buffer.data(), BUF_BASE_SIZE);
- is_not_seq(output_buffer.data(), output_channels, BUF_BASE_SIZE, output_seq_idx);
+ got = cubeb_resampler_fill(resampler, input_buffer_normal.data(),
+ &normal_input_frame_count,
+ output_buffer.data(), BUF_BASE_SIZE);
+ is_not_seq(output_buffer.data(), output_channels, BUF_BASE_SIZE,
+ output_seq_idx);
// Reclock so that we can use is_seq again.
output_seq_idx = output_buffer[BUF_BASE_SIZE * output_channels - 1] + 1;
- }
- else {
+ } else {
// normal case
- seq_idx = seq(input_buffer_normal.data(), input_channels, seq_idx, BUF_BASE_SIZE);
+ seq_idx = seq(input_buffer_normal.data(), input_channels, seq_idx,
+ BUF_BASE_SIZE);
long normal_input_frame_count = 256;
- got = cubeb_resampler_fill(resampler, input_buffer_normal.data(), &normal_input_frame_count, output_buffer.data(), BUF_BASE_SIZE);
- is_seq(output_buffer.data(), output_channels, BUF_BASE_SIZE, output_seq_idx);
+ got = cubeb_resampler_fill(resampler, input_buffer_normal.data(),
+ &normal_input_frame_count,
+ output_buffer.data(), BUF_BASE_SIZE);
+ is_seq(output_buffer.data(), output_channels, BUF_BASE_SIZE,
+ output_seq_idx);
output_seq_idx += BUF_BASE_SIZE;
}
ASSERT_EQ(got, BUF_BASE_SIZE);
@@ -895,16 +965,15 @@ TEST(cubeb, resampler_drift_drop_data)
}
static long
-passthrough_resampler_fill_eq_input(cubeb_stream * stream,
- void * user_ptr,
+passthrough_resampler_fill_eq_input(cubeb_stream * stream, void * user_ptr,
void const * input_buffer,
- void * output_buffer,
- long nframes) {
+ void * output_buffer, long nframes)
+{
// gtest does not support using ASSERT_EQ and friends in a
// function that returns a value.
[nframes, input_buffer]() {
ASSERT_EQ(nframes, 32);
- const float* input = static_cast<const float*>(input_buffer);
+ const float * input = static_cast<const float *>(input_buffer);
for (int i = 0; i < 64; ++i) {
ASSERT_FLOAT_EQ(input[i], 0.01 * i);
}
@@ -912,12 +981,13 @@ passthrough_resampler_fill_eq_input(cubeb_stream * stream,
return nframes;
}
-TEST(cubeb, passthrough_resampler_fill_eq_input) {
+TEST(cubeb, passthrough_resampler_fill_eq_input)
+{
uint32_t channels = 2;
uint32_t sample_rate = 44100;
passthrough_resampler<float> resampler =
- passthrough_resampler<float>(nullptr, passthrough_resampler_fill_eq_input,
- nullptr, channels, sample_rate);
+ passthrough_resampler<float>(nullptr, passthrough_resampler_fill_eq_input,
+ nullptr, channels, sample_rate);
long input_frame_count = 32;
long output_frame_count = 32;
@@ -926,23 +996,23 @@ TEST(cubeb, passthrough_resampler_fill_eq_input) {
for (uint32_t i = 0; i < input_frame_count * channels; ++i) {
input[i] = 0.01 * i;
}
- long got = resampler.fill(input, &input_frame_count, output, output_frame_count);
+ long got =
+ resampler.fill(input, &input_frame_count, output, output_frame_count);
ASSERT_EQ(got, output_frame_count);
// Input frames used must be equal to output frames.
ASSERT_EQ(input_frame_count, output_frame_count);
}
static long
-passthrough_resampler_fill_short_input(cubeb_stream * stream,
- void * user_ptr,
+passthrough_resampler_fill_short_input(cubeb_stream * stream, void * user_ptr,
void const * input_buffer,
- void * output_buffer,
- long nframes) {
+ void * output_buffer, long nframes)
+{
// gtest does not support using ASSERT_EQ and friends in a
// function that returns a value.
[nframes, input_buffer]() {
ASSERT_EQ(nframes, 32);
- const float* input = static_cast<const float*>(input_buffer);
+ const float * input = static_cast<const float *>(input_buffer);
// First part contains the input
for (int i = 0; i < 32; ++i) {
ASSERT_FLOAT_EQ(input[i], 0.01 * i);
@@ -955,12 +1025,13 @@ passthrough_resampler_fill_short_input(cubeb_stream * stream,
return nframes;
}
-TEST(cubeb, passthrough_resampler_fill_short_input) {
+TEST(cubeb, passthrough_resampler_fill_short_input)
+{
uint32_t channels = 2;
uint32_t sample_rate = 44100;
- passthrough_resampler<float> resampler =
- passthrough_resampler<float>(nullptr, passthrough_resampler_fill_short_input,
- nullptr, channels, sample_rate);
+ passthrough_resampler<float> resampler = passthrough_resampler<float>(
+ nullptr, passthrough_resampler_fill_short_input, nullptr, channels,
+ sample_rate);
long input_frame_count = 16;
long output_frame_count = 32;
@@ -969,25 +1040,25 @@ TEST(cubeb, passthrough_resampler_fill_short_input) {
for (uint32_t i = 0; i < input_frame_count * channels; ++i) {
input[i] = 0.01 * i;
}
- long got = resampler.fill(input, &input_frame_count, output, output_frame_count);
+ long got =
+ resampler.fill(input, &input_frame_count, output, output_frame_count);
ASSERT_EQ(got, output_frame_count);
// Input frames used are less than the output frames due to glitch.
ASSERT_EQ(input_frame_count, output_frame_count - 16);
}
static long
-passthrough_resampler_fill_input_left(cubeb_stream * stream,
- void * user_ptr,
- void const * input_buffer,
- void * output_buffer,
- long nframes) {
+passthrough_resampler_fill_input_left(cubeb_stream * stream, void * user_ptr,
+ void const * input_buffer,
+ void * output_buffer, long nframes)
+{
// gtest does not support using ASSERT_EQ and friends in a
// function that returns a value.
- int iteration = *static_cast<int*>(user_ptr);
+ int iteration = *static_cast<int *>(user_ptr);
if (iteration == 1) {
[nframes, input_buffer]() {
ASSERT_EQ(nframes, 32);
- const float* input = static_cast<const float*>(input_buffer);
+ const float * input = static_cast<const float *>(input_buffer);
for (int i = 0; i < 64; ++i) {
ASSERT_FLOAT_EQ(input[i], 0.01 * i);
}
@@ -995,7 +1066,7 @@ passthrough_resampler_fill_input_left(cubeb_stream * stream,
} else if (iteration == 2) {
[nframes, input_buffer]() {
ASSERT_EQ(nframes, 32);
- const float* input = static_cast<const float*>(input_buffer);
+ const float * input = static_cast<const float *>(input_buffer);
for (int i = 0; i < 32; ++i) {
// First part contains the reamaining input samples from previous
// iteration (since they were more).
@@ -1007,7 +1078,7 @@ passthrough_resampler_fill_input_left(cubeb_stream * stream,
} else if (iteration == 3) {
[nframes, input_buffer]() {
ASSERT_EQ(nframes, 32);
- const float* input = static_cast<const float*>(input_buffer);
+ const float * input = static_cast<const float *>(input_buffer);
for (int i = 0; i < 32; ++i) {
// First part (16 frames) contains the reamaining input samples
// from previous iteration (since they were more).
@@ -1024,13 +1095,14 @@ passthrough_resampler_fill_input_left(cubeb_stream * stream,
return nframes;
}
-TEST(cubeb, passthrough_resampler_fill_input_left) {
+TEST(cubeb, passthrough_resampler_fill_input_left)
+{
const uint32_t channels = 2;
const uint32_t sample_rate = 44100;
int iteration = 0;
- passthrough_resampler<float> resampler =
- passthrough_resampler<float>(nullptr, passthrough_resampler_fill_input_left,
- &iteration, channels, sample_rate);
+ passthrough_resampler<float> resampler = passthrough_resampler<float>(
+ nullptr, passthrough_resampler_fill_input_left, &iteration, channels,
+ sample_rate);
long input_frame_count = 48; // 32 + 16
const long output_frame_count = 32;
@@ -1042,7 +1114,8 @@ TEST(cubeb, passthrough_resampler_fill_input_left) {
// 1st iteration, add the extra input.
iteration = 1;
- long got = resampler.fill(input, &input_frame_count, output, output_frame_count);
+ long got =
+ resampler.fill(input, &input_frame_count, output, output_frame_count);
ASSERT_EQ(got, output_frame_count);
// Input frames used must be equal to output frames.
ASSERT_EQ(input_frame_count, output_frame_count);
@@ -1066,7 +1139,8 @@ TEST(cubeb, passthrough_resampler_fill_input_left) {
ASSERT_EQ(input_frame_count, output_frame_count - 8);
}
-TEST(cubeb, individual_methods) {
+TEST(cubeb, individual_methods)
+{
const uint32_t channels = 2;
const uint32_t sample_rate = 44100;
const uint32_t frames = 256;
@@ -1075,15 +1149,16 @@ TEST(cubeb, individual_methods) {
uint32_t frames_needed1 = dl.input_needed_for_output(0);
ASSERT_EQ(frames_needed1, 0u);
- cubeb_resampler_speex_one_way<float> one_way(channels, sample_rate, sample_rate, CUBEB_RESAMPLER_QUALITY_DEFAULT);
+ cubeb_resampler_speex_one_way<float> one_way(
+ channels, sample_rate, sample_rate, CUBEB_RESAMPLER_QUALITY_DEFAULT);
float buffer[channels * frames] = {0.0};
// Add all frames in the resampler's internal buffer.
one_way.input(buffer, frames);
- // Ask for less than the existing frames, this would create a uint overlflow without the fix.
+ // Ask for less than the existing frames, this would create a uint overlflow
+ // without the fix.
uint32_t frames_needed2 = one_way.input_needed_for_output(0);
ASSERT_EQ(frames_needed2, 0u);
}
-
#undef NOMINMAX
#undef DUMP_ARRAYS
diff --git a/test/test_ring_array.cpp b/test/test_ring_array.cpp
index d258d50..a364684 100644
--- a/test/test_ring_array.cpp
+++ b/test/test_ring_array.cpp
@@ -1,10 +1,10 @@
#include "gtest/gtest.h"
#ifdef __APPLE__
-#include <string.h>
-#include <iostream>
-#include <CoreAudio/CoreAudioTypes.h>
#include "cubeb/cubeb.h"
#include "cubeb_ring_array.h"
+#include <CoreAudio/CoreAudioTypes.h>
+#include <iostream>
+#include <string.h>
TEST(cubeb, ring_array)
{
@@ -15,12 +15,12 @@ TEST(cubeb, ring_array)
unsigned int capacity = 8;
ring_array_init(&ra, capacity, sizeof(int), 1, 1);
- int verify_data[capacity] ;// {1,2,3,4,5,6,7,8};
+ int verify_data[capacity]; // {1,2,3,4,5,6,7,8};
AudioBuffer * p_data = NULL;
for (unsigned int i = 0; i < capacity; ++i) {
verify_data[i] = i; // in case capacity change value
- *(int*)ra.buffer_array[i].mData = i;
+ *(int *)ra.buffer_array[i].mData = i;
ASSERT_EQ(ra.buffer_array[i].mDataByteSize, sizeof(int));
ASSERT_EQ(ra.buffer_array[i].mNumberChannels, 1u);
}
@@ -29,7 +29,7 @@ TEST(cubeb, ring_array)
for (unsigned int i = 0; i < capacity; ++i) {
p_data = ring_array_get_free_buffer(&ra);
ASSERT_NE(p_data, nullptr);
- ASSERT_EQ(*(int*)p_data->mData, verify_data[i]);
+ ASSERT_EQ(*(int *)p_data->mData, verify_data[i]);
}
/*Now array is full extra store should give NULL*/
ASSERT_EQ(ring_array_get_free_buffer(&ra), nullptr);
@@ -37,14 +37,14 @@ TEST(cubeb, ring_array)
for (unsigned int i = 0; i < capacity; ++i) {
p_data = ring_array_get_data_buffer(&ra);
ASSERT_NE(p_data, nullptr);
- ASSERT_EQ(*(int*)p_data->mData, verify_data[i]);
+ ASSERT_EQ(*(int *)p_data->mData, verify_data[i]);
}
/*Now array is empty extra fetch should give NULL*/
ASSERT_EQ(ring_array_get_data_buffer(&ra), nullptr);
p_data = NULL;
/* Repeated store fetch should can go for ever*/
- for (unsigned int i = 0; i < 2*capacity; ++i) {
+ for (unsigned int i = 0; i < 2 * capacity; ++i) {
p_data = ring_array_get_free_buffer(&ra);
ASSERT_NE(p_data, nullptr);
ASSERT_EQ(ring_array_get_data_buffer(&ra), p_data);
@@ -55,19 +55,18 @@ TEST(cubeb, ring_array)
for (unsigned int i = 0; i < capacity; ++i) {
p_data = ring_array_get_free_buffer(&ra);
ASSERT_NE(p_data, nullptr);
- ASSERT_EQ(*((int*)p_data->mData), verify_data[i]);
- (*((int*)p_data->mData))++; // Modify data
+ ASSERT_EQ(*((int *)p_data->mData), verify_data[i]);
+ (*((int *)p_data->mData))++; // Modify data
}
for (unsigned int i = 0; i < capacity; ++i) {
p_data = ring_array_get_data_buffer(&ra);
ASSERT_NE(p_data, nullptr);
- ASSERT_EQ(*((int*)p_data->mData), verify_data[i]+1); // Verify modified data
+ ASSERT_EQ(*((int *)p_data->mData),
+ verify_data[i] + 1); // Verify modified data
}
ring_array_destroy(&ra);
}
#else
-TEST(cubeb, DISABLED_ring_array)
-{
-}
+TEST(cubeb, DISABLED_ring_array) {}
#endif
diff --git a/test/test_ring_buffer.cpp b/test/test_ring_buffer.cpp
index 203b9f6..fffe108 100644
--- a/test/test_ring_buffer.cpp
+++ b/test/test_ring_buffer.cpp
@@ -9,20 +9,16 @@
#define NOMINMAX
#endif
-#include "gtest/gtest.h"
#include "cubeb_ringbuffer.h"
+#include "gtest/gtest.h"
+#include <chrono>
#include <iostream>
#include <thread>
-#include <chrono>
/* Generate a monotonically increasing sequence of numbers. */
-template<typename T>
-class sequence_generator
-{
+template <typename T> class sequence_generator {
public:
- sequence_generator(size_t channels)
- : channels(channels)
- { }
+ sequence_generator(size_t channels) : channels(channels) {}
void get(T * elements, size_t frames)
{
for (size_t i = 0; i < frames; i++) {
@@ -32,44 +28,41 @@ public:
index_++;
}
}
- void rewind(size_t frames)
- {
- index_ -= frames;
- }
+ void rewind(size_t frames) { index_ -= frames; }
+
private:
size_t index_ = 0;
size_t channels = 0;
};
/* Checks that a sequence is monotonically increasing. */
-template<typename T>
-class sequence_verifier
-{
- public:
- sequence_verifier(size_t channels)
- : channels(channels)
- { }
- void check(T * elements, size_t frames)
- {
- for (size_t i = 0; i < frames; i++) {
- for (size_t c = 0; c < channels; c++) {
- if (elements[i * channels + c] != static_cast<T>(index_)) {
- std::cerr << "Element " << i << " is different. Expected "
- << static_cast<T>(index_) << ", got " << elements[i]
- << ". (channel count: " << channels << ")." << std::endl;
- ASSERT_TRUE(false);
- }
+template <typename T> class sequence_verifier {
+public:
+ sequence_verifier(size_t channels) : channels(channels) {}
+ void check(T * elements, size_t frames)
+ {
+ for (size_t i = 0; i < frames; i++) {
+ for (size_t c = 0; c < channels; c++) {
+ if (elements[i * channels + c] != static_cast<T>(index_)) {
+ std::cerr << "Element " << i << " is different. Expected "
+ << static_cast<T>(index_) << ", got " << elements[i]
+ << ". (channel count: " << channels << ")." << std::endl;
+ ASSERT_TRUE(false);
}
- index_++;
}
+ index_++;
}
- private:
- size_t index_ = 0;
- size_t channels = 0;
+ }
+
+private:
+ size_t index_ = 0;
+ size_t channels = 0;
};
-template<typename T>
-void test_ring(lock_free_audio_ring_buffer<T>& buf, int channels, int capacity_frames)
+template <typename T>
+void
+test_ring(lock_free_audio_ring_buffer<T> & buf, int channels,
+ int capacity_frames)
{
std::unique_ptr<T[]> seq(new T[capacity_frames * channels]);
sequence_generator<T> gen(channels);
@@ -79,7 +72,7 @@ void test_ring(lock_free_audio_ring_buffer<T>& buf, int channels, int capacity_f
const int block_size = 128;
- while(iterations--) {
+ while (iterations--) {
gen.get(seq.get(), block_size);
int rv = buf.enqueue(seq.get(), block_size);
ASSERT_EQ(rv, block_size);
@@ -90,8 +83,10 @@ void test_ring(lock_free_audio_ring_buffer<T>& buf, int channels, int capacity_f
}
}
-template<typename T>
-void test_ring_multi(lock_free_audio_ring_buffer<T>& buf, int channels, int capacity_frames)
+template <typename T>
+void
+test_ring_multi(lock_free_audio_ring_buffer<T> & buf, int channels,
+ int capacity_frames)
{
sequence_verifier<T> checker(channels);
std::unique_ptr<T[]> out_buffer(new T[capacity_frames * channels]);
@@ -103,7 +98,7 @@ void test_ring_multi(lock_free_audio_ring_buffer<T>& buf, int channels, int capa
std::unique_ptr<T[]> in_buffer(new T[capacity_frames * channels]);
sequence_generator<T> gen(channels);
- while(iterations--) {
+ while (iterations--) {
std::this_thread::yield();
gen.get(in_buffer.get(), block_size);
int rv = buf.enqueue(in_buffer.get(), block_size);
@@ -116,7 +111,7 @@ void test_ring_multi(lock_free_audio_ring_buffer<T>& buf, int channels, int capa
int remaining = 1002;
- while(remaining--) {
+ while (remaining--) {
std::this_thread::yield();
int rv = buf.dequeue(out_buffer.get(), block_size);
ASSERT_TRUE(rv <= block_size);
@@ -126,8 +121,9 @@ void test_ring_multi(lock_free_audio_ring_buffer<T>& buf, int channels, int capa
t.join();
}
-template<typename T>
-void basic_api_test(T& ring)
+template <typename T>
+void
+basic_api_test(T & ring)
{
ASSERT_EQ(ring.capacity(), 128);
@@ -157,30 +153,32 @@ void basic_api_test(T& ring)
ASSERT_EQ(ring.available_write(), 128);
}
-void test_reset_api() {
- const size_t ring_buffer_size = 128;
- const size_t enqueue_size = ring_buffer_size / 2;
+void
+test_reset_api()
+{
+ const size_t ring_buffer_size = 128;
+ const size_t enqueue_size = ring_buffer_size / 2;
- lock_free_queue<float> ring(ring_buffer_size);
- std::thread t([=, &ring] {
- std::unique_ptr<float[]> in_buffer(new float[enqueue_size]);
- ring.enqueue(in_buffer.get(), enqueue_size);
- });
+ lock_free_queue<float> ring(ring_buffer_size);
+ std::thread t([=, &ring] {
+ std::unique_ptr<float[]> in_buffer(new float[enqueue_size]);
+ ring.enqueue(in_buffer.get(), enqueue_size);
+ });
- t.join();
+ t.join();
- ring.reset_thread_ids();
+ ring.reset_thread_ids();
- // Enqueue with a different thread. We have reset the thread ID
- // in the ring buffer, this should work.
- std::thread t2([=, &ring] {
- std::unique_ptr<float[]> in_buffer(new float[enqueue_size]);
- ring.enqueue(in_buffer.get(), enqueue_size);
- });
+ // Enqueue with a different thread. We have reset the thread ID
+ // in the ring buffer, this should work.
+ std::thread t2([=, &ring] {
+ std::unique_ptr<float[]> in_buffer(new float[enqueue_size]);
+ ring.enqueue(in_buffer.get(), enqueue_size);
+ });
- t2.join();
+ t2.join();
- ASSERT_TRUE(true);
+ ASSERT_TRUE(true);
}
TEST(cubeb, ring_buffer)
@@ -208,8 +206,8 @@ TEST(cubeb, ring_buffer)
/* Test mono to 9.1 */
for (size_t channels = min_channels; channels < max_channels; channels++) {
/* Use non power-of-two numbers to catch edge-cases. */
- for (size_t capacity_frames = min_capacity;
- capacity_frames < max_capacity; capacity_frames+=capacity_increment) {
+ for (size_t capacity_frames = min_capacity; capacity_frames < max_capacity;
+ capacity_frames += capacity_increment) {
lock_free_audio_ring_buffer<float> ring(channels, capacity_frames);
test_ring(ring, channels, capacity_frames);
}
@@ -218,8 +216,8 @@ TEST(cubeb, ring_buffer)
/* Multi thread testing */
for (size_t channels = min_channels; channels < max_channels; channels++) {
/* Use non power-of-two numbers to catch edge-cases. */
- for (size_t capacity_frames = min_capacity;
- capacity_frames < max_capacity; capacity_frames+=capacity_increment) {
+ for (size_t capacity_frames = min_capacity; capacity_frames < max_capacity;
+ capacity_frames += capacity_increment) {
lock_free_audio_ring_buffer<short> ring(channels, capacity_frames);
test_ring_multi(ring, channels, capacity_frames);
}
diff --git a/test/test_sanity.cpp b/test/test_sanity.cpp
index d681c50..6468531 100644
--- a/test/test_sanity.cpp
+++ b/test/test_sanity.cpp
@@ -10,12 +10,12 @@
#endif
#include "cubeb/cubeb.h"
#include <atomic>
+#include <math.h>
#include <stdio.h>
#include <string.h>
-#include <math.h>
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
#define STREAM_RATE 44100
@@ -24,14 +24,17 @@
#define STREAM_LAYOUT CUBEB_LAYOUT_MONO
#define STREAM_FORMAT CUBEB_SAMPLE_S16LE
-int is_windows_7()
+int
+is_windows_7()
{
#ifdef __MINGW32__
- fprintf(stderr, "Warning: this test was built with MinGW.\n"
- "MinGW does not contain necessary version checking infrastructure. Claiming to be Windows 7, even if we're not.\n");
+ fprintf(stderr,
+ "Warning: this test was built with MinGW.\n"
+ "MinGW does not contain necessary version checking infrastructure. "
+ "Claiming to be Windows 7, even if we're not.\n");
return 1;
#endif
-#if (defined(_WIN32) || defined(__WIN32__)) && ( !defined(__MINGW32__))
+#if (defined(_WIN32) || defined(__WIN32__)) && (!defined(__MINGW32__))
OSVERSIONINFOEX osvi;
DWORDLONG condition_mask = 0;
@@ -45,7 +48,8 @@ int is_windows_7()
VER_SET_CONDITION(condition_mask, VER_MAJORVERSION, VER_EQUAL);
VER_SET_CONDITION(condition_mask, VER_MINORVERSION, VER_GREATER_EQUAL);
- return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, condition_mask);
+ return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION,
+ condition_mask);
#else
return 0;
#endif
@@ -56,7 +60,9 @@ static std::atomic<uint64_t> total_frames_written;
static int delay_callback;
static long
-test_data_callback(cubeb_stream * stm, void * user_ptr, const void * /*inputbuffer*/, void * outputbuffer, long nframes)
+test_data_callback(cubeb_stream * stm, void * user_ptr,
+ const void * /*inputbuffer*/, void * outputbuffer,
+ long nframes)
{
EXPECT_TRUE(stm && user_ptr == &dummy && outputbuffer && nframes > 0);
assert(outputbuffer);
@@ -70,7 +76,8 @@ test_data_callback(cubeb_stream * stm, void * user_ptr, const void * /*inputbuff
}
void
-test_state_callback(cubeb_stream * /*stm*/, void * /*user_ptr*/, cubeb_state /*state*/)
+test_state_callback(cubeb_stream * /*stm*/, void * /*user_ptr*/,
+ cubeb_state /*state*/)
{
}
@@ -78,7 +85,7 @@ TEST(cubeb, init_destroy_context)
{
int r;
cubeb * ctx;
- char const* backend_id;
+ char const * backend_id;
r = common_init(&ctx, "test_sanity");
ASSERT_EQ(r, CUBEB_OK);
@@ -161,8 +168,9 @@ TEST(cubeb, init_destroy_stream)
params.layout = STREAM_LAYOUT;
params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_data_callback, test_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_data_callback, test_state_callback,
+ &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream, nullptr);
@@ -189,8 +197,9 @@ TEST(cubeb, init_destroy_multiple_streams)
params.prefs = CUBEB_STREAM_PREF_NONE;
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
- r = cubeb_stream_init(ctx, &stream[i], "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_data_callback, test_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream[i], "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_data_callback,
+ test_state_callback, &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream[i], nullptr);
}
@@ -219,8 +228,9 @@ TEST(cubeb, configure_stream)
params.layout = CUBEB_LAYOUT_STEREO;
params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_data_callback, test_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_data_callback, test_state_callback,
+ &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream, nullptr);
@@ -251,8 +261,9 @@ TEST(cubeb, configure_stream_undefined_layout)
params.layout = CUBEB_LAYOUT_UNDEFINED;
params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_data_callback, test_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_data_callback, test_state_callback,
+ &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream, nullptr);
@@ -288,8 +299,9 @@ test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
params.prefs = CUBEB_STREAM_PREF_NONE;
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
- r = cubeb_stream_init(ctx, &stream[i], "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_data_callback, test_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream[i], "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_data_callback,
+ test_state_callback, &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream[i], nullptr);
if (early) {
@@ -378,7 +390,8 @@ TEST(cubeb, init_destroy_multiple_contexts_and_streams)
ASSERT_NE(ctx[i], nullptr);
for (j = 0; j < streams_per_ctx; ++j) {
- r = cubeb_stream_init(ctx[i], &stream[i * streams_per_ctx + j], "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
+ r = cubeb_stream_init(ctx[i], &stream[i * streams_per_ctx + j], "test",
+ NULL, NULL, NULL, &params, STREAM_LATENCY,
test_data_callback, test_state_callback, &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream[i * streams_per_ctx + j], nullptr);
@@ -412,8 +425,9 @@ TEST(cubeb, basic_stream_operations)
params.layout = STREAM_LAYOUT;
params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_data_callback, test_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_data_callback, test_state_callback,
+ &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream, nullptr);
@@ -470,8 +484,9 @@ TEST(cubeb, stream_position)
params.layout = STREAM_LAYOUT;
params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_data_callback, test_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_data_callback, test_state_callback,
+ &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream, nullptr);
@@ -559,7 +574,9 @@ static std::atomic<int> do_drain;
static std::atomic<int> got_drain;
static long
-test_drain_data_callback(cubeb_stream * stm, void * user_ptr, const void * /*inputbuffer*/, void * outputbuffer, long nframes)
+test_drain_data_callback(cubeb_stream * stm, void * user_ptr,
+ const void * /*inputbuffer*/, void * outputbuffer,
+ long nframes)
{
EXPECT_TRUE(stm && user_ptr == &dummy && outputbuffer && nframes > 0);
assert(outputbuffer);
@@ -575,7 +592,8 @@ test_drain_data_callback(cubeb_stream * stm, void * user_ptr, const void * /*inp
}
void
-test_drain_state_callback(cubeb_stream * /*stm*/, void * /*user_ptr*/, cubeb_state state)
+test_drain_state_callback(cubeb_stream * /*stm*/, void * /*user_ptr*/,
+ cubeb_state state)
{
if (state == CUBEB_STATE_DRAINED) {
ASSERT_TRUE(!got_drain);
@@ -604,8 +622,9 @@ TEST(cubeb, drain)
params.layout = STREAM_LAYOUT;
params.prefs = CUBEB_STREAM_PREF_NONE;
- r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
- test_drain_data_callback, test_drain_state_callback, &dummy);
+ r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params,
+ STREAM_LATENCY, test_drain_data_callback,
+ test_drain_state_callback, &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream, nullptr);
@@ -631,9 +650,9 @@ TEST(cubeb, drain)
ASSERT_EQ(r, CUBEB_OK);
ASSERT_TRUE(got_drain);
- // Really, we should be able to rely on position reaching our final written frame, but
- // for now let's make sure it doesn't continue beyond that point.
- //ASSERT_LE(position, total_frames_written.load());
+ // Really, we should be able to rely on position reaching our final written
+ // frame, but for now let's make sure it doesn't continue beyond that point.
+ // ASSERT_LE(position, total_frames_written.load());
cubeb_stream_destroy(stream);
cubeb_destroy(ctx);
@@ -663,7 +682,7 @@ TEST(cubeb, stable_devid)
cubeb_device_collection first;
cubeb_device_collection second;
cubeb_device_type all_devices =
- (cubeb_device_type) (CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT);
+ (cubeb_device_type)(CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT);
size_t n;
r = common_init(&ctx, "test_sanity");
diff --git a/test/test_tone.cpp b/test/test_tone.cpp
index 9d0e1af..56ff876 100644
--- a/test/test_tone.cpp
+++ b/test/test_tone.cpp
@@ -10,19 +10,18 @@
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <memory>
-#include <limits.h>
#include "cubeb/cubeb.h"
#include <atomic>
+#include <limits.h>
+#include <math.h>
+#include <memory>
+#include <stdio.h>
+#include <stdlib.h>
-//#define ENABLE_NORMAL_LOG
-//#define ENABLE_VERBOSE_LOG
+// #define ENABLE_NORMAL_LOG
+// #define ENABLE_VERBOSE_LOG
#include "common.h"
-
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_S16LE
@@ -31,10 +30,12 @@ struct cb_user_data {
std::atomic<long> position;
};
-long data_cb_tone(cubeb_stream *stream, void *user, const void* /*inputbuffer*/, void *outputbuffer, long nframes)
+long
+data_cb_tone(cubeb_stream * stream, void * user, const void * /*inputbuffer*/,
+ void * outputbuffer, long nframes)
{
- struct cb_user_data *u = (struct cb_user_data *)user;
- short *b = (short *)outputbuffer;
+ struct cb_user_data * u = (struct cb_user_data *)user;
+ short * b = (short *)outputbuffer;
float t1, t2;
int i;
@@ -44,9 +45,9 @@ long data_cb_tone(cubeb_stream *stream, void *user, const void* /*inputbuffer*/,
/* generate our test tone on the fly */
for (i = 0; i < nframes; i++) {
/* North American dial tone */
- t1 = sin(2*M_PI*(i + u->position)*350/SAMPLE_FREQUENCY);
- t2 = sin(2*M_PI*(i + u->position)*440/SAMPLE_FREQUENCY);
- b[i] = (SHRT_MAX / 2) * t1;
+ t1 = sin(2 * M_PI * (i + u->position) * 350 / SAMPLE_FREQUENCY);
+ t2 = sin(2 * M_PI * (i + u->position) * 440 / SAMPLE_FREQUENCY);
+ b[i] = (SHRT_MAX / 2) * t1;
b[i] += (SHRT_MAX / 2) * t2;
/* European dial tone */
/*
@@ -61,20 +62,24 @@ long data_cb_tone(cubeb_stream *stream, void *user, const void* /*inputbuffer*/,
return nframes;
}
-void state_cb_tone(cubeb_stream *stream, void *user, cubeb_state state)
+void
+state_cb_tone(cubeb_stream * stream, void * user, cubeb_state state)
{
- struct cb_user_data *u = (struct cb_user_data *)user;
+ struct cb_user_data * u = (struct cb_user_data *)user;
if (stream == NULL || u == NULL)
return;
switch (state) {
case CUBEB_STATE_STARTED:
- fprintf(stderr, "stream started\n"); break;
+ fprintf(stderr, "stream started\n");
+ break;
case CUBEB_STATE_STOPPED:
- fprintf(stderr, "stream stopped\n"); break;
+ fprintf(stderr, "stream stopped\n");
+ break;
case CUBEB_STATE_DRAINED:
- fprintf(stderr, "stream drained\n"); break;
+ fprintf(stderr, "stream drained\n");
+ break;
default:
fprintf(stderr, "unknown stream state %d\n", state);
}
@@ -84,16 +89,16 @@ void state_cb_tone(cubeb_stream *stream, void *user, cubeb_state state)
TEST(cubeb, tone)
{
- cubeb *ctx;
- cubeb_stream *stream;
+ cubeb * ctx;
+ cubeb_stream * stream;
cubeb_stream_params params;
int r;
r = common_init(&ctx, "Cubeb tone example");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
- std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
- cleanup_cubeb_at_exit(ctx, cubeb_destroy);
+ std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit(
+ ctx, cubeb_destroy);
params.format = STREAM_FORMAT;
params.rate = SAMPLE_FREQUENCY;
@@ -106,12 +111,13 @@ TEST(cubeb, tone)
user_data->position = 0;
- r = cubeb_stream_init(ctx, &stream, "Cubeb tone (mono)", NULL, NULL, NULL, &params,
- 4096, data_cb_tone, state_cb_tone, user_data.get());
+ r = cubeb_stream_init(ctx, &stream, "Cubeb tone (mono)", NULL, NULL, NULL,
+ &params, 4096, data_cb_tone, state_cb_tone,
+ user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
- cleanup_stream_at_exit(stream, cubeb_stream_destroy);
+ cleanup_stream_at_exit(stream, cubeb_stream_destroy);
cubeb_stream_start(stream);
delay(5000);
diff --git a/test/test_utils.cpp b/test/test_utils.cpp
index cbdb960..a6227d4 100644
--- a/test/test_utils.cpp
+++ b/test/test_utils.cpp
@@ -1,5 +1,5 @@
-#include "gtest/gtest.h"
#include "cubeb_utils.h"
+#include "gtest/gtest.h"
TEST(cubeb, auto_array)
{
@@ -10,7 +10,6 @@ TEST(cubeb, auto_array)
ASSERT_EQ(array2.length(), 0u);
ASSERT_EQ(array2.capacity(), 10u);
-
for (uint32_t i = 0; i < 10; i++) {
a[i] = i;
}
@@ -39,7 +38,7 @@ TEST(cubeb, auto_array)
ASSERT_EQ(b[i], i);
ASSERT_EQ(array.data()[i], 5 + i);
}
- uint32_t* bb = b + 5;
+ uint32_t * bb = b + 5;
array.pop(bb, 5);
ASSERT_EQ(array.capacity(), 10u);
@@ -69,4 +68,3 @@ TEST(cubeb, auto_array)
ASSERT_EQ(array.length(), 15u);
ASSERT_EQ(array.capacity(), 20u);
}
-