From 7d92b0609093a047ce4b113d77ccd3cc78325e8f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 15 Nov 2018 19:56:13 -0700 Subject: sound: Add sample rate as a parameter for square wave At present this value is hard-coded in the function that generates a square wave. Since sample rates vary between different hardware, it makes more sense to have this as a parameter. Update the function and its users. Signed-off-by: Simon Glass --- drivers/sound/sound-i2s.c | 3 ++- drivers/sound/sound.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/sound/sound-i2s.c b/drivers/sound/sound-i2s.c index 9f09e3bf930..f0f0b79bc52 100644 --- a/drivers/sound/sound-i2s.c +++ b/drivers/sound/sound-i2s.c @@ -185,7 +185,8 @@ int sound_play(uint32_t msec, uint32_t frequency) return -1; } - sound_create_square_wave((unsigned short *)data, + sound_create_square_wave(g_i2stx_pri.samplingrate, + (unsigned short *)data, data_size / sizeof(unsigned short), frequency); diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 6c1eb4c19cc..4f0ad0d8f0d 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -7,11 +7,11 @@ #include #include -void sound_create_square_wave(unsigned short *data, int size, uint32_t freq) +void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, + uint freq) { - const int sample = 48000; const unsigned short amplitude = 16000; /* between 1 and 32767 */ - const int period = freq ? sample / freq : 0; + const int period = freq ? sample_rate / freq : 0; const int half = period / 2; assert(freq); -- cgit v1.2.3