Skip to content

Commit

Permalink
test multichannel
Browse files Browse the repository at this point in the history
  • Loading branch information
padenot committed Apr 11, 2024
1 parent 67db4cb commit ab023c9
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions test/test_tone.cpp
Expand Up @@ -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 {
Expand All @@ -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 */
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit ab023c9

Please sign in to comment.