aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/sound/sound-uclass.c2
-rw-r--r--drivers/sound/sound.c11
-rw-r--r--include/sound.h11
3 files changed, 14 insertions, 10 deletions
diff --git a/drivers/sound/sound-uclass.c b/drivers/sound/sound-uclass.c
index 71e753c..2b83626 100644
--- a/drivers/sound/sound-uclass.c
+++ b/drivers/sound/sound-uclass.c
@@ -53,7 +53,7 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz)
}
sound_create_square_wave(i2s_uc_priv->samplingrate, data, data_size,
- frequency_hz);
+ frequency_hz, i2s_uc_priv->channels);
while (msecs >= 1000) {
ret = sound_play(dev, data, data_size);
diff --git a/drivers/sound/sound.c b/drivers/sound/sound.c
index 4f0ad0d..dd3f9db 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;
}
}
}
diff --git a/include/sound.h b/include/sound.h
index 02acefd..b7959cc 100644
--- a/include/sound.h
+++ b/include/sound.h
@@ -37,13 +37,14 @@ struct sound_uc_priv {
/**
* Generates square wave sound data for 1 second
*
- * @param sample_rate Sample rate in Hz
- * @param data data buffer pointer
- * @param size size of the buffer in bytes
- * @param freq frequency of the wave
+ * @sample_rate: Sample rate in Hz
+ * @data: data buffer pointer
+ * @size: size of the buffer in bytes
+ * @freq: frequency of the wave
+ * @channels: Number of channels to use
*/
void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
- uint freq);
+ uint freq, uint channels);
/*
* The sound uclass brings together a data transport (currently only I2C) and a