audiotestsrc: Fix incorrect start of tick waveform

Make sure ticks start with an accumulator value of 0 by incrementing it
after filling in samples instead of before and by resetting the accumulator
every time a tick begins. This prevents it from being discontinuous at the
beginning of the tick.

https://bugzilla.gnome.org/show_bug.cgi?id=774050
This commit is contained in:
Carlos Rafael Giani 2016-09-02 15:23:18 +02:00 committed by Tim-Philipp Müller
parent 7c0c59ccdf
commit a257a177c3

View file

@ -735,7 +735,7 @@ static const ProcessFunc sine_table_funcs[] = {
static void \ static void \
gst_audio_test_src_create_tick_##type (GstAudioTestSrc * src, g##type * samples) \ gst_audio_test_src_create_tick_##type (GstAudioTestSrc * src, g##type * samples) \
{ \ { \
gint i, c, channels, samplerate; \ gint i, c, channels, samplerate, samplemod; \
gdouble step, scl; \ gdouble step, scl; \
\ \
channels = GST_AUDIO_INFO_CHANNELS (&src->info); \ channels = GST_AUDIO_INFO_CHANNELS (&src->info); \
@ -744,17 +744,20 @@ gst_audio_test_src_create_tick_##type (GstAudioTestSrc * src, g##type * samples)
scl = 1024.0 / M_PI_M2; \ scl = 1024.0 / M_PI_M2; \
\ \
for (i = 0; i < src->generate_samples_per_buffer; i++) { \ for (i = 0; i < src->generate_samples_per_buffer; i++) { \
src->accumulator += step; \ samplemod = (src->next_sample + i) % samplerate; \
if (src->accumulator >= M_PI_M2) \ if (samplemod == 0) { \
src->accumulator -= M_PI_M2; \ src->accumulator = 0; \
\ } else if (samplemod < 1600) { \
if ((src->next_sample + i)%samplerate < 1600) { \
for (c = 0; c < channels; ++c) \ for (c = 0; c < channels; ++c) \
samples[(i * channels) + c] = (g##type) scale * src->wave_table[(gint) (src->accumulator * scl)]; \ samples[(i * channels) + c] = (g##type) scale * src->wave_table[(gint) (src->accumulator * scl)]; \
} else { \ } else { \
for (c = 0; c < channels; ++c) \ for (c = 0; c < channels; ++c) \
samples[(i * channels) + c] = 0; \ samples[(i * channels) + c] = 0; \
} \ } \
\
src->accumulator += step; \
if (src->accumulator >= M_PI_M2) \
src->accumulator -= M_PI_M2; \
} \ } \
} }