aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastien Alaiwan <[email protected]>2014-10-14 21:16:16 +0200
committerSebastien Alaiwan <[email protected]>2014-10-14 21:16:16 +0200
commit4c5618878f7e65096142c504d1eaa25038195ff8 (patch)
treee2a43e460e8ca4da3c5ce4af99d46c8fe92ed419
parenta0aa1de44886d0b788feb2695734b4612ad7eac0 (diff)
downloadcubeb-4c5618878f7e65096142c504d1eaa25038195ff8.tar.gz
cubeb-4c5618878f7e65096142c504d1eaa25038195ff8.zip
jack backend: handle cubeb_stream_set_volume correctly. Add corresponding test to test_audio.
-rw-r--r--src/cubeb_jack.cpp6
-rw-r--r--test/test_audio.cpp75
2 files changed, 78 insertions, 3 deletions
diff --git a/src/cubeb_jack.cpp b/src/cubeb_jack.cpp
index 7aa3218..9b562be 100644
--- a/src/cubeb_jack.cpp
+++ b/src/cubeb_jack.cpp
@@ -166,6 +166,7 @@ struct cubeb_stream {
char stream_name[256];
jack_port_t *output_ports[MAX_CHANNELS];
jack_ringbuffer_t *ringbuffer[MAX_CHANNELS];
+ float volume;
};
struct cubeb {
@@ -352,7 +353,7 @@ cbjack_stream_refill(cubeb_stream * stream)
for(unsigned int c = 0; c < stream->params.channels; c++) {
float* buffer = stream->context->buffer[c];
for (long f = 0; f < num_frames; f++) {
- buffer[f] = interleaved_buffer[(f * stream->params.channels) + c];
+ buffer[f] = interleaved_buffer[(f * stream->params.channels) + c] * stream->volume;
}
}
@@ -607,6 +608,7 @@ cbjack_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_
stm->data_callback = data_callback;
stm->state_callback = state_callback;
stm->position = 0;
+ stm->volume = 1.0f;
if (stm->params.rate != stm->context->jack_sample_rate) {
int resampler_error;
@@ -694,6 +696,8 @@ cbjack_stream_get_latency(cubeb_stream * stream, uint32_t * latency)
static int
cbjack_stream_set_volume(cubeb_stream * stm, float volume)
{
+ AutoLock lock(stm->context->mutex);
+ stm->volume = volume;
return CUBEB_OK;
}
diff --git a/test/test_audio.cpp b/test/test_audio.cpp
index a7b2fb4..22b51ba 100644
--- a/test/test_audio.cpp
+++ b/test/test_audio.cpp
@@ -121,7 +121,7 @@ int run_test(int num_channels, int sampling_rate, int is_float)
cubeb_stream *stream = NULL;
const char * backend_id = NULL;
- ret = cubeb_init(&ctx, "Cubeb audio test");
+ ret = cubeb_init(&ctx, "Cubeb audio test: channels");
if (ret != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb library\n");
goto cleanup;
@@ -167,7 +167,71 @@ cleanup:
return ret;
}
-int main(int argc, char *argv[])
+int run_panning_volume_test()
+{
+ int ret = CUBEB_OK;
+
+ cubeb *ctx = NULL;
+ synth_state* synth = NULL;
+ cubeb_stream *stream = NULL;
+
+ ret = cubeb_init(&ctx, "Cubeb audio test");
+ if (ret != CUBEB_OK) {
+ fprintf(stderr, "Error initializing cubeb library\n");
+ goto cleanup;
+ }
+
+ cubeb_stream_params params;
+ params.format = CUBEB_SAMPLE_S16NE;
+ params.rate = 44100;
+ params.channels = 2;
+
+ synth = synth_create(params.channels, params.rate);
+ if (synth == NULL) {
+ fprintf(stderr, "Out of memory\n");
+ goto cleanup;
+ }
+
+ ret = cubeb_stream_init(ctx, &stream, "test tone", params,
+ 100, data_cb_short, state_cb, synth);
+ if (ret != CUBEB_OK) {
+ fprintf(stderr, "Error initializing cubeb stream: %d\n", ret);
+ goto cleanup;
+ }
+
+ fprintf(stderr, "Testing: volume\n");
+ for(int i=0;i <= 4; ++i)
+ {
+ fprintf(stderr, "Volume: %d%%\n", i*25);
+
+ cubeb_stream_set_volume(stream, i/4.0f);
+ cubeb_stream_start(stream);
+ delay(400);
+ cubeb_stream_stop(stream);
+ delay(100);
+ }
+
+ fprintf(stderr, "Testing: panning\n");
+ for(int i=-4;i <= 4; ++i)
+ {
+ fprintf(stderr, "Panning: %.2f%%\n", i/4.0f);
+
+ cubeb_stream_set_panning(stream, i/4.0f);
+ cubeb_stream_start(stream);
+ delay(400);
+ cubeb_stream_stop(stream);
+ delay(100);
+ }
+
+cleanup:
+ cubeb_stream_destroy(stream);
+ cubeb_destroy(ctx);
+ synth_destroy(synth);
+
+ return ret;
+}
+
+void run_channel_rate_test()
{
int channel_values[] = {
1,
@@ -192,6 +256,13 @@ int main(int argc, char *argv[])
assert(run_test(channel_values[j], freq_values[i], 1) == CUBEB_OK);
}
}
+}
+
+
+int main(int argc, char *argv[])
+{
+ assert(run_panning_volume_test() == CUBEB_OK);
+ run_channel_rate_test();
return CUBEB_OK;
}