diff options
Diffstat (limited to 'test/test_tone.cpp')
-rw-r--r-- | test/test_tone.cpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/test/test_tone.cpp b/test/test_tone.cpp index 56ff876..0f594ab 100644 --- a/test/test_tone.cpp +++ b/test/test_tone.cpp @@ -18,12 +18,13 @@ #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 +#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32NE +#define CHANNELS 11 /* store the phase of the generated waveform */ struct cb_user_data { @@ -35,25 +36,21 @@ 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; + float * b = (float *)outputbuffer; float t1, t2; int i; if (stream == NULL || u == NULL) return CUBEB_ERROR; + int base_freq = 300; + int wr_idx = 0; /* 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; - b[i] += (SHRT_MAX / 2) * t2; - /* European dial tone */ - /* - t1 = sin(2*M_PI*(i + u->position)*425/SAMPLE_FREQUENCY); - b[i] = SHRT_MAX * t1; - */ + for (int c = 0; c < CHANNELS; c++) { + t1 = sin(2 * M_PI * (i + u->position) * base_freq*(1+c/2.) / SAMPLE_FREQUENCY); + b[wr_idx++] = t1; + } } /* remember our phase to avoid clicking on buffer transitions */ /* we'll still click if position overflows */ @@ -102,8 +99,8 @@ TEST(cubeb, tone) params.format = STREAM_FORMAT; params.rate = SAMPLE_FREQUENCY; - params.channels = 1; - params.layout = CUBEB_LAYOUT_MONO; + params.channels = CHANNELS; + params.layout = 0; params.prefs = CUBEB_STREAM_PREF_NONE; std::unique_ptr<cb_user_data> user_data(new cb_user_data()); @@ -120,7 +117,7 @@ TEST(cubeb, tone) cleanup_stream_at_exit(stream, cubeb_stream_destroy); cubeb_stream_start(stream); - delay(5000); + getchar(); cubeb_stream_stop(stream); ASSERT_TRUE(user_data->position.load()); |