static void test_configure_stream(void) { int r; cubeb * ctx; cubeb_stream * stream; cubeb_stream_params params; BEGIN_TEST; r = cubeb_init(&ctx, "test_sanity"); assert(r == 0 && ctx); params.format = STREAM_FORMAT; params.rate = STREAM_RATE; params.channels = 2; // panning r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY, test_data_callback, test_state_callback, &dummy); assert(r == 0 && stream); r = cubeb_stream_set_volume(stream, 1.0f); assert(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED); r = cubeb_stream_set_panning(stream, 0.0f); assert(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED); cubeb_stream_destroy(stream); cubeb_destroy(ctx); END_TEST; }
TEST(cubeb, configure_stream) { int r; cubeb * ctx; cubeb_stream * stream; cubeb_stream_params params; r = common_init(&ctx, "test_sanity"); ASSERT_EQ(r, CUBEB_OK); ASSERT_NE(ctx, nullptr); params.format = STREAM_FORMAT; params.rate = STREAM_RATE; params.channels = 2; // panning params.layout = CUBEB_LAYOUT_STEREO; r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY, test_data_callback, test_state_callback, &dummy); ASSERT_EQ(r, CUBEB_OK); ASSERT_NE(stream, nullptr); 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); }
void AudioStream::SetVolume(double aVolume) { MOZ_ASSERT(aVolume >= 0.0 && aVolume <= 1.0, "Invalid volume"); if (cubeb_stream_set_volume(mCubebStream.get(), aVolume * CubebUtils::GetVolumeScale()) != CUBEB_OK) { NS_WARNING("Could not change volume on cubeb stream."); } }
int run_panning_volume_test(int is_float) { int r = CUBEB_OK; cubeb *ctx = NULL; synth_state* synth = NULL; cubeb_stream *stream = NULL; const char * backend_id = NULL; r = cubeb_init(&ctx, "Cubeb audio test"); if (r != CUBEB_OK) { fprintf(stderr, "Error initializing cubeb library\n"); goto cleanup; } backend_id = cubeb_get_backend_id(ctx); if ((is_float && !supports_float32(backend_id)) || (!is_float && !supports_int16(backend_id))) { /* don't treat this as a test failure. */ goto cleanup; } cubeb_stream_params params; params.format = is_float ? CUBEB_SAMPLE_FLOAT32NE : 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; } r = cubeb_stream_init(ctx, &stream, "test tone", NULL, NULL, NULL, ¶ms, 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); 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 r; }
void CubebStream::SetVolume(int volume) { cubeb_stream_set_volume(m_stream, volume / 100.0f); }