diff options
author | Simon Glass <sjg@chromium.org> | 2018-12-10 10:37:51 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-12-13 16:37:10 -0700 |
commit | f987177db9c988142032ed8142a093cce2378a90 (patch) | |
tree | 9d4f5d9b057a749742e9dcead3cfa41c4ddae5ea /drivers/sound/sound.c | |
parent | e221cdcf44c80a6de78fd9285c5325db231ed20c (diff) | |
download | u-boot-f987177db9c988142032ed8142a093cce2378a90.tar.gz |
dm: sound: Use the correct number of channels for sound
At present the 'beep' sound generates a waveform for only one channel even
if two are being used. This means that the beep is twice the frequency it
should be. Correct this by making it a parameter.
The fix in a previous commit was correct for sandbox but not for other
boards.
Fixes: 03f11e87a8 ("sound: Correct data output in sound_create_square_wave()")
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/sound/sound.c')
-rw-r--r-- | drivers/sound/sound.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c index 4f0ad0d8f0..dd3f9db4f7 100644 --- a/drivers/sound/sound.c +++ b/drivers/sound/sound.c @@ -8,7 +8,7 @@ #include <sound.h> void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, - uint freq) + uint freq, uint channels) { const unsigned short amplitude = 16000; /* between 1 and 32767 */ const int period = freq ? sample_rate / freq : 0; @@ -21,14 +21,17 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size, size--; while (size) { - int i; + int i, j; + for (i = 0; size && i < half; i++) { size -= 2; - *data++ = amplitude; + for (j = 0; j < channels; j++) + *data++ = amplitude; } for (i = 0; size && i < period - half; i++) { size -= 2; - *data++ = -amplitude; + for (j = 0; j < channels; j++) + *data++ = -amplitude; } } } |