diff options
author | sanine <sanine.not@pm.me> | 2022-08-30 23:46:40 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-08-30 23:46:40 -0500 |
commit | eb4e4cab2d3f24ee7f8d0be7149162084fe98392 (patch) | |
tree | 37affdd321ee4f14965eb98000ae82a051efba40 /src/channel.test.c | |
parent | 489c3771e648d412cab283c660996c880149315d (diff) |
add mono panning
Diffstat (limited to 'src/channel.test.c')
-rw-r--r-- | src/channel.test.c | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/src/channel.test.c b/src/channel.test.c index 427fd63..150adb9 100644 --- a/src/channel.test.c +++ b/src/channel.test.c @@ -336,20 +336,71 @@ void test_channel_get_next_sample_mono() float l, r; + const float gain = 0.7071; /* constant-power panning center gain */ + lily_store_value(mock_p_mutex_trylock, pboolean, TRUE); channel_get_next_sample(&l, &r, &chan); lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1); lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1); lily_assert_int_equal(chan.pos, 1); - lily_assert_float_equal(l, 0.0f, 0.1f); - lily_assert_float_equal(r, 0.0f, 0.1f); + lily_assert_float_equal(l, gain * 0.0f, 0.1f); + lily_assert_float_equal(r, gain * 0.0f, 0.1f); lily_store_value(mock_p_mutex_trylock, pboolean, TRUE); channel_get_next_sample(&l, &r, &chan); lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 2); lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 2); lily_assert_int_equal(chan.pos, 2); + lily_assert_float_equal(l, gain * 0.5f, 0.1f); + lily_assert_float_equal(r, gain * 0.5f, 0.1f); + + lily_store_value(mock_p_mutex_trylock, pboolean, TRUE); + channel_get_next_sample(&l, &r, &chan); + lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 3); + lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 3); + lily_assert_int_equal(chan.pos, 0); + lily_assert_int_equal(chan.active, false); + lily_assert_float_equal(l, gain * 1.0f, 0.1f); + lily_assert_float_equal(r, gain * 1.0f, 0.1f); +} + + +void test_channel_get_next_sample_mono_panned() +{ + lily_mock_use(&mock_p_mutex_trylock); + lily_mock_use(&mock_p_mutex_unlock); + + struct channel_t chan; + chan.active = true; + chan.paused = false; + chan.volume = 255; + chan.pan_left = -128; + chan.pan_right = 128; + float audio[] = { 0.0, 0.5, 1.0 }; + chan.sound.left = audio; + chan.sound.right = NULL; + chan.sound.mono = true; + chan.sound.len = 3; + chan.pos = 0; + + float l, r; + + const float gain = 0.7071; /* constant-power panning center gain */ + + lily_store_value(mock_p_mutex_trylock, pboolean, TRUE); + channel_get_next_sample(&l, &r, &chan); + lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 1); + lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 1); + lily_assert_int_equal(chan.pos, 1); lily_assert_float_equal(l, 0.0f, 0.1f); + lily_assert_float_equal(r, gain * 0.0f, 0.1f); + + lily_store_value(mock_p_mutex_trylock, pboolean, TRUE); + channel_get_next_sample(&l, &r, &chan); + lily_assert_int_equal(mock_p_mutex_trylock->n_calls, 2); + lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 2); + lily_assert_int_equal(chan.pos, 2); + lily_assert_float_equal(l, 0.5f, 0.1f); lily_assert_float_equal(r, 0.0f, 0.1f); lily_store_value(mock_p_mutex_trylock, pboolean, TRUE); @@ -358,7 +409,7 @@ void test_channel_get_next_sample_mono() lily_assert_int_equal(mock_p_mutex_unlock->n_calls, 3); lily_assert_int_equal(chan.pos, 0); lily_assert_int_equal(chan.active, false); - lily_assert_float_equal(l, 0.0f, 0.1f); + lily_assert_float_equal(l, 1.0f, 0.1f); lily_assert_float_equal(r, 0.0f, 0.1f); } @@ -379,6 +430,7 @@ void suite_channel() lily_run_test(test_channel_get_next_sample_nolock); lily_run_test(test_channel_get_next_sample_volume_0); lily_run_test(test_channel_get_next_sample_mono); + lily_run_test(test_channel_get_next_sample_mono_panned); lily_mock_destroy(mock_p_mutex_new); } |