diff options
author | Simon Glass <sjg@chromium.org> | 2018-11-15 19:56:13 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-11-29 09:30:05 -0700 |
commit | 7d92b0609093a047ce4b113d77ccd3cc78325e8f (patch) | |
tree | 4afa25f53b27bf4f76cac7e0a80ef8bb1de36242 /drivers/sound | |
parent | 03f11e87a86307903f40e74495936184063bab79 (diff) |
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 <sjg@chromium.org>
Diffstat (limited to 'drivers/sound')
-rw-r--r-- | drivers/sound/sound-i2s.c | 3 | ||||
-rw-r--r-- | drivers/sound/sound.c | 6 |
2 files changed, 5 insertions, 4 deletions
diff --git a/drivers/sound/sound-i2s.c b/drivers/sound/sound-i2s.c index 9f09e3bf93..f0f0b79bc5 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 6c1eb4c19c..4f0ad0d8f0 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -7,11 +7,11 @@ #include <common.h> #include <sound.h> -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); |