From 8c3e32bd24933f82220b66c88c845c4b2bdf28e7 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Wed, 21 Aug 2019 17:34:40 +0200 Subject: [PATCH] Remove panning API from cubeb This is best done by the host application, and had very little implementation anyways. --- CMakeLists.txt | 1 - include/cubeb/cubeb.h | 14 ---------- src/cubeb-internal.h | 1 - src/cubeb.c | 13 --------- src/cubeb_alsa.c | 1 - src/cubeb_audiotrack.c | 1 - src/cubeb_audiounit.cpp | 27 ------------------- src/cubeb_jack.cpp | 1 - src/cubeb_kai.c | 1 - src/cubeb_opensl.c | 1 - src/cubeb_panner.cpp | 60 ----------------------------------------- src/cubeb_panner.h | 28 ------------------- src/cubeb_pulse.c | 48 --------------------------------- src/cubeb_sndio.c | 1 - src/cubeb_sun.c | 1 - src/cubeb_wasapi.cpp | 1 - src/cubeb_winmm.c | 1 - test/test_audio.cpp | 22 ++++----------- test/test_sanity.cpp | 7 ++--- 19 files changed, 7 insertions(+), 223 deletions(-) delete mode 100644 src/cubeb_panner.cpp delete mode 100644 src/cubeb_panner.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bc98b40..b32a53a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,6 @@ add_library(cubeb src/cubeb.c src/cubeb_mixer.cpp src/cubeb_resampler.cpp - src/cubeb_panner.cpp src/cubeb_log.cpp src/cubeb_strings.c src/cubeb_utils.cpp diff --git a/include/cubeb/cubeb.h b/include/cubeb/cubeb.h index 3305eb6..e6cf8dd 100644 --- a/include/cubeb/cubeb.h +++ b/include/cubeb/cubeb.h @@ -568,20 +568,6 @@ CUBEB_EXPORT int cubeb_stream_get_latency(cubeb_stream * stream, uint32_t * late @retval CUBEB_ERROR_NOT_SUPPORTED */ CUBEB_EXPORT int cubeb_stream_set_volume(cubeb_stream * stream, float volume); -/** If the stream is stereo, set the left/right panning. If the stream is mono, - this has no effect. - @param stream the stream for which to change the panning - @param panning a number from -1.0 to 1.0. -1.0 means that the stream is - fully mixed in the left channel, 1.0 means the stream is fully - mixed in the right channel. 0.0 is equal power in the right and - left channel (default). - @retval CUBEB_OK - @retval CUBEB_ERROR_INVALID_PARAMETER if stream is null or if panning is - outside the [-1.0, 1.0] range. - @retval CUBEB_ERROR_NOT_SUPPORTED - @retval CUBEB_ERROR stream is not mono nor stereo */ -CUBEB_EXPORT int cubeb_stream_set_panning(cubeb_stream * stream, float panning); - /** Get the current output device for this stream. @param stm the stream for which to query the current output device @param device a pointer in which the current output device will be stored. diff --git a/src/cubeb-internal.h b/src/cubeb-internal.h index 9b6199c..312a9ea 100644 --- a/src/cubeb-internal.h +++ b/src/cubeb-internal.h @@ -64,7 +64,6 @@ struct cubeb_ops { int (* stream_get_position)(cubeb_stream * stream, uint64_t * position); int (* stream_get_latency)(cubeb_stream * stream, uint32_t * latency); int (* stream_set_volume)(cubeb_stream * stream, float volumes); - int (* stream_set_panning)(cubeb_stream * stream, float panning); int (* stream_get_current_device)(cubeb_stream * stream, cubeb_device ** const device); int (* stream_device_destroy)(cubeb_stream * stream, diff --git a/src/cubeb.c b/src/cubeb.c index cedd84c..85b104c 100644 --- a/src/cubeb.c +++ b/src/cubeb.c @@ -434,19 +434,6 @@ cubeb_stream_set_volume(cubeb_stream * stream, float volume) return stream->context->ops->stream_set_volume(stream, volume); } -int cubeb_stream_set_panning(cubeb_stream * stream, float panning) -{ - if (!stream || panning < -1.0 || panning > 1.0) { - return CUBEB_ERROR_INVALID_PARAMETER; - } - - if (!stream->context->ops->stream_set_panning) { - return CUBEB_ERROR_NOT_SUPPORTED; - } - - return stream->context->ops->stream_set_panning(stream, panning); -} - int cubeb_stream_get_current_device(cubeb_stream * stream, cubeb_device ** const device) { diff --git a/src/cubeb_alsa.c b/src/cubeb_alsa.c index bfd4d8f..2a3c04e 100644 --- a/src/cubeb_alsa.c +++ b/src/cubeb_alsa.c @@ -1369,7 +1369,6 @@ static struct cubeb_ops const alsa_ops = { .stream_get_position = alsa_stream_get_position, .stream_get_latency = alsa_stream_get_latency, .stream_set_volume = alsa_stream_set_volume, - .stream_set_panning = NULL, .stream_get_current_device = NULL, .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL, diff --git a/src/cubeb_audiotrack.c b/src/cubeb_audiotrack.c index 0f4dfbb..22f1fe0 100644 --- a/src/cubeb_audiotrack.c +++ b/src/cubeb_audiotrack.c @@ -434,7 +434,6 @@ static struct cubeb_ops const audiotrack_ops = { .stream_get_position = audiotrack_stream_get_position, .stream_get_latency = audiotrack_stream_get_latency, .stream_set_volume = audiotrack_stream_set_volume, - .stream_set_panning = NULL, .stream_get_current_device = NULL, .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL, diff --git a/src/cubeb_audiounit.cpp b/src/cubeb_audiounit.cpp index 25355b4..9978504 100644 --- a/src/cubeb_audiounit.cpp +++ b/src/cubeb_audiounit.cpp @@ -23,7 +23,6 @@ #include "cubeb/cubeb.h" #include "cubeb-internal.h" #include "cubeb_mixer.h" -#include "cubeb_panner.h" #if !TARGET_OS_IPHONE #include "cubeb_osx_run_loop.h" #endif @@ -242,7 +241,6 @@ struct cubeb_stream { uint32_t latency_frames = 0; atomic current_latency_frames{ 0 }; atomic total_output_latency_frames { 0 }; - atomic panning{ 0 }; unique_ptr resampler; /* This is true if a device change callback is currently running. */ atomic switching_device{ false }; @@ -692,10 +690,6 @@ audiounit_output_callback(void * user_ptr, stm->frames_played = stm->frames_queued; stm->frames_queued += outframes; - AudioFormatFlags outaff = stm->output_desc.mFormatFlags; - float panning = (stm->output_desc.mChannelsPerFrame == 2) ? - stm->panning.load(memory_order_relaxed) : 0.0f; - /* Post process output samples. */ if (stm->draining) { size_t outbpf = cubeb_sample_size(stm->output_stream_params.format); @@ -711,16 +705,6 @@ audiounit_output_callback(void * user_ptr, stm->temp_buffer_size, outBufferList->mBuffers[0].mData, outBufferList->mBuffers[0].mDataByteSize); - } else { - /* Pan stereo. */ - if (panning != 0.0f) { - if (outaff & kAudioFormatFlagIsFloat) { - cubeb_pan_stereo_buffer_float( - (float*)output_buffer, outframes, panning); - } else if (outaff & kAudioFormatFlagIsSignedInteger) { - cubeb_pan_stereo_buffer_int((short*)output_buffer, outframes, panning); - } - } } return noErr; @@ -3021,16 +3005,6 @@ audiounit_stream_set_volume(cubeb_stream * stm, float volume) return CUBEB_OK; } -int audiounit_stream_set_panning(cubeb_stream * stm, float panning) -{ - if (stm->output_desc.mChannelsPerFrame > 2) { - return CUBEB_ERROR_INVALID_PARAMETER; - } - - stm->panning.store(panning, memory_order_relaxed); - return CUBEB_OK; -} - unique_ptr convert_uint32_into_string(UInt32 data) { // Simply create an empty string if no data. @@ -3632,7 +3606,6 @@ cubeb_ops const audiounit_ops = { /*.stream_get_position =*/ audiounit_stream_get_position, /*.stream_get_latency =*/ audiounit_stream_get_latency, /*.stream_set_volume =*/ audiounit_stream_set_volume, - /*.stream_set_panning =*/ audiounit_stream_set_panning, /*.stream_get_current_device =*/ audiounit_stream_get_current_device, /*.stream_device_destroy =*/ audiounit_stream_device_destroy, /*.stream_register_device_changed_callback =*/ audiounit_stream_register_device_changed_callback, diff --git a/src/cubeb_jack.cpp b/src/cubeb_jack.cpp index 3632da5..3823ee9 100644 --- a/src/cubeb_jack.cpp +++ b/src/cubeb_jack.cpp @@ -130,7 +130,6 @@ static struct cubeb_ops const cbjack_ops = { .stream_get_position = cbjack_stream_get_position, .stream_get_latency = cbjack_get_latency, .stream_set_volume = cbjack_stream_set_volume, - .stream_set_panning = NULL, .stream_get_current_device = cbjack_stream_get_current_device, .stream_device_destroy = cbjack_stream_device_destroy, .stream_register_device_changed_callback = NULL, diff --git a/src/cubeb_kai.c b/src/cubeb_kai.c index f09aed2..5333968 100644 --- a/src/cubeb_kai.c +++ b/src/cubeb_kai.c @@ -362,7 +362,6 @@ static struct cubeb_ops const kai_ops = { /*.stream_get_position =*/ kai_stream_get_position, /*.stream_get_latency = */ kai_stream_get_latency, /*.stream_set_volume =*/ kai_stream_set_volume, - /*.stream_set_panning =*/ NULL, /*.stream_get_current_device =*/ NULL, /*.stream_device_destroy =*/ NULL, /*.stream_register_device_changed_callback=*/ NULL, diff --git a/src/cubeb_opensl.c b/src/cubeb_opensl.c index a5ca3ee..96374ec 100644 --- a/src/cubeb_opensl.c +++ b/src/cubeb_opensl.c @@ -1673,7 +1673,6 @@ static struct cubeb_ops const opensl_ops = { .stream_get_position = opensl_stream_get_position, .stream_get_latency = NULL, .stream_set_volume = opensl_stream_set_volume, - .stream_set_panning = NULL, .stream_get_current_device = NULL, .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL, diff --git a/src/cubeb_panner.cpp b/src/cubeb_panner.cpp deleted file mode 100644 index bd96ed6..0000000 --- a/src/cubeb_panner.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2014 Mozilla Foundation - * - * This program is made available under an ISC-style license. See the - * accompanying file LICENSE for details. - */ - -#define _USE_MATH_DEFINES -#include -#include - -#include "cubeb_panner.h" - -#ifndef M_PI -#define M_PI 3.14159263 -#endif - -/** - * We use a cos/sin law. - */ - -namespace { -template -void cubeb_pan_stereo_buffer(T * buf, uint32_t frames, float pan) -{ - if (pan == 0.0) { - return; - } - /* rescale in [0; 1] */ - pan += 1; - pan /= 2; - float left_gain = float(cos(pan * M_PI * 0.5)); - float right_gain = float(sin(pan * M_PI * 0.5)); - - /* In we are panning on the left, pan the right channel into the left one and - * vice-versa. */ - if (pan < 0.5) { - for (uint32_t i = 0; i < frames * 2; i+=2) { - buf[i] = T(buf[i] + buf[i + 1] * left_gain); - buf[i + 1] = T(buf[i + 1] * right_gain); - } - } else { - for (uint32_t i = 0; i < frames * 2; i+=2) { - buf[i] = T(buf[i] * left_gain); - buf[i + 1] = T(buf[i + 1] + buf[i] * right_gain); - } - } -} -} - -void cubeb_pan_stereo_buffer_float(float * buf, uint32_t frames, float pan) -{ - cubeb_pan_stereo_buffer(buf, frames, pan); -} - -void cubeb_pan_stereo_buffer_int(short * buf, uint32_t frames, float pan) -{ - cubeb_pan_stereo_buffer(buf, frames, pan); -} - diff --git a/src/cubeb_panner.h b/src/cubeb_panner.h deleted file mode 100644 index c61363b..0000000 --- a/src/cubeb_panner.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2014 Mozilla Foundation - * - * This program is made available under an ISC-style license. See the - * accompanying file LICENSE for details. - */ - -#if !defined(CUBEB_PANNER) -#define CUBEB_PANNER - -#if defined(__cplusplus) -extern "C" { -#endif - -/** - * Pan an integer or an float stereo buffer according to a cos/sin pan law - * @param buf the buffer to pan - * @param frames the number of frames in `buf` - * @param pan a float in [-1.0; 1.0] - */ -void cubeb_pan_stereo_buffer_float(float * buf, uint32_t frames, float pan); -void cubeb_pan_stereo_buffer_int(short* buf, uint32_t frames, float pan); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/src/cubeb_pulse.c b/src/cubeb_pulse.c index 92b170b..ea2031f 100644 --- a/src/cubeb_pulse.c +++ b/src/cubeb_pulse.c @@ -1184,53 +1184,6 @@ sink_input_info_cb(pa_context * c, pa_sink_input_info const * i, int eol, void * WRAP(pa_threaded_mainloop_signal)(r->mainloop, 0); } -static int -pulse_stream_set_panning(cubeb_stream * stm, float panning) -{ - const pa_channel_map * map; - pa_cvolume cvol; - uint32_t index; - pa_operation * op; - - if (!stm->output_stream) { - return CUBEB_ERROR; - } - - WRAP(pa_threaded_mainloop_lock)(stm->context->mainloop); - - map = WRAP(pa_stream_get_channel_map)(stm->output_stream); - if (!WRAP(pa_channel_map_can_balance)(map)) { - WRAP(pa_threaded_mainloop_unlock)(stm->context->mainloop); - return CUBEB_ERROR; - } - - index = WRAP(pa_stream_get_index)(stm->output_stream); - - struct sink_input_info_result r = { &cvol, stm->context->mainloop }; - op = WRAP(pa_context_get_sink_input_info)(stm->context->context, - index, - sink_input_info_cb, - &r); - if (op) { - operation_wait(stm->context, stm->output_stream, op); - WRAP(pa_operation_unref)(op); - } - - WRAP(pa_cvolume_set_balance)(&cvol, map, panning); - - op = WRAP(pa_context_set_sink_input_volume)(stm->context->context, - index, &cvol, volume_success, - stm); - if (op) { - operation_wait(stm->context, stm->output_stream, op); - WRAP(pa_operation_unref)(op); - } - - WRAP(pa_threaded_mainloop_unlock)(stm->context->mainloop); - - return CUBEB_OK; -} - typedef struct { char * default_sink_name; char * default_source_name; @@ -1637,7 +1590,6 @@ static struct cubeb_ops const pulse_ops = { .stream_get_position = pulse_stream_get_position, .stream_get_latency = pulse_stream_get_latency, .stream_set_volume = pulse_stream_set_volume, - .stream_set_panning = pulse_stream_set_panning, .stream_get_current_device = pulse_stream_get_current_device, .stream_device_destroy = pulse_stream_device_destroy, .stream_register_device_changed_callback = NULL, diff --git a/src/cubeb_sndio.c b/src/cubeb_sndio.c index 9e99b2c..c90a0e9 100644 --- a/src/cubeb_sndio.c +++ b/src/cubeb_sndio.c @@ -572,7 +572,6 @@ static struct cubeb_ops const sndio_ops = { .stream_get_position = sndio_stream_get_position, .stream_get_latency = sndio_stream_get_latency, .stream_set_volume = sndio_stream_set_volume, - .stream_set_panning = NULL, .stream_get_current_device = NULL, .stream_device_destroy = NULL, .stream_register_device_changed_callback = NULL, diff --git a/src/cubeb_sun.c b/src/cubeb_sun.c index 4dcfd64..64ab0b5 100644 --- a/src/cubeb_sun.c +++ b/src/cubeb_sun.c @@ -745,7 +745,6 @@ static struct cubeb_ops const sun_ops = { .stream_get_position = sun_stream_get_position, .stream_get_latency = sun_stream_get_latency, .stream_set_volume = sun_stream_set_volume, - .stream_set_panning = NULL, .stream_get_current_device = sun_get_current_device, .stream_device_destroy = sun_stream_device_destroy, .stream_register_device_changed_callback = NULL, diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp index 1a31229..ab563fc 100644 --- a/src/cubeb_wasapi.cpp +++ b/src/cubeb_wasapi.cpp @@ -2951,7 +2951,6 @@ cubeb_ops const wasapi_ops = { /*.stream_get_position =*/ wasapi_stream_get_position, /*.stream_get_latency =*/ wasapi_stream_get_latency, /*.stream_set_volume =*/ wasapi_stream_set_volume, - /*.stream_set_panning =*/ NULL, /*.stream_get_current_device =*/ NULL, /*.stream_device_destroy =*/ NULL, /*.stream_register_device_changed_callback =*/ NULL, diff --git a/src/cubeb_winmm.c b/src/cubeb_winmm.c index fd5abe2..e064ca0 100644 --- a/src/cubeb_winmm.c +++ b/src/cubeb_winmm.c @@ -1060,7 +1060,6 @@ static struct cubeb_ops const winmm_ops = { /*.stream_get_position =*/ winmm_stream_get_position, /*.stream_get_latency = */ winmm_stream_get_latency, /*.stream_set_volume =*/ winmm_stream_set_volume, - /*.stream_set_panning =*/ NULL, /*.stream_get_current_device =*/ NULL, /*.stream_device_destroy =*/ NULL, /*.stream_register_device_changed_callback=*/ NULL, diff --git a/test/test_audio.cpp b/test/test_audio.cpp index 98ba197..ea1b999 100644 --- a/test/test_audio.cpp +++ b/test/test_audio.cpp @@ -148,7 +148,7 @@ int run_test(int num_channels, int sampling_rate, int is_float) return r; } -int run_panning_volume_test(int is_float) +int run_volume_test(int is_float) { int r = CUBEB_OK; @@ -203,29 +203,17 @@ int run_panning_volume_test(int is_float) 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); - } - return r; } -TEST(cubeb, run_panning_volume_test_short) +TEST(cubeb, run_volume_test_short) { - ASSERT_EQ(run_panning_volume_test(0), CUBEB_OK); + ASSERT_EQ(run_volume_test(0), CUBEB_OK); } -TEST(cubeb, run_panning_volume_test_float) +TEST(cubeb, run_volume_test_float) { - ASSERT_EQ(run_panning_volume_test(1), CUBEB_OK); + ASSERT_EQ(run_volume_test(1), CUBEB_OK); } TEST(cubeb, run_channel_rate_test) diff --git a/test/test_sanity.cpp b/test/test_sanity.cpp index caebe1b..56099d2 100644 --- a/test/test_sanity.cpp +++ b/test/test_sanity.cpp @@ -215,7 +215,7 @@ TEST(cubeb, configure_stream) params.format = STREAM_FORMAT; params.rate = STREAM_RATE; - params.channels = 2; // panning + params.channels = 2; params.layout = CUBEB_LAYOUT_STEREO; params.prefs = CUBEB_STREAM_PREF_NONE; @@ -227,9 +227,6 @@ TEST(cubeb, configure_stream) r = cubeb_stream_set_volume(stream, 1.0f); ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED); - r = cubeb_stream_set_panning(stream, 0.0f); - ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED); - cubeb_stream_destroy(stream); cubeb_destroy(ctx); } @@ -247,7 +244,7 @@ TEST(cubeb, configure_stream_undefined_layout) params.format = STREAM_FORMAT; params.rate = STREAM_RATE; - params.channels = 2; // panning + params.channels = 2; params.layout = CUBEB_LAYOUT_UNDEFINED; params.prefs = CUBEB_STREAM_PREF_NONE;