[U-Boot] [PATCH v2 21/22] dm: sandbox: Allow selection of sample rate and channels

Simon Glass sjg at chromium.org
Mon Dec 10 17:37:50 UTC 2018


At present these parameters are hard-coded in the sdl interface code.
Allow them to be specified by the driver instead.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 arch/sandbox/cpu/sdl.c         | 10 +++-------
 arch/sandbox/include/asm/sdl.h |  6 ++++--
 drivers/sound/sandbox.c        |  2 +-
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index 7eb2df7ddad..66de4040fc8 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -9,10 +9,6 @@
 #include <SDL/SDL.h>
 #include <asm/state.h>
 
-enum {
-	SAMPLE_RATE	= 22050,
-};
-
 /**
  * struct buf_info - a data buffer holding audio data
  *
@@ -285,7 +281,7 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
 	}
 }
 
-int sandbox_sdl_sound_init(void)
+int sandbox_sdl_sound_init(int rate, int channels)
 {
 	SDL_AudioSpec wanted;
 	int i;
@@ -297,9 +293,9 @@ int sandbox_sdl_sound_init(void)
 		return 0;
 
 	/* Set the audio format */
-	wanted.freq = SAMPLE_RATE;
+	wanted.freq = rate;
 	wanted.format = AUDIO_S16;
-	wanted.channels = 1;    /* 1 = mono, 2 = stereo */
+	wanted.channels = channels;
 	wanted.samples = 1024;  /* Good low-latency value for callback */
 	wanted.callback = sandbox_sdl_fill_audio;
 	wanted.userdata = NULL;
diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h
index 2799a8bee06..1027b59e732 100644
--- a/arch/sandbox/include/asm/sdl.h
+++ b/arch/sandbox/include/asm/sdl.h
@@ -71,9 +71,11 @@ int sandbox_sdl_sound_stop(void);
 /**
  * sandbox_sdl_sound_init() - set up the sound system
  *
+ * @rate:	Sample rate to use
+ * @channels:	Number of channels to use (1=mono, 2=stereo)
  * @return 0 if OK, -ENODEV if no sound is available
  */
-int sandbox_sdl_sound_init(void);
+int sandbox_sdl_sound_init(int rate, int channels);
 
 #else
 static inline int sandbox_sdl_init_display(int width, int height,
@@ -112,7 +114,7 @@ static inline int sandbox_sdl_sound_stop(void)
 	return -ENODEV;
 }
 
-static inline int sandbox_sdl_sound_init(void)
+int sandbox_sdl_sound_init(int rate, int channels)
 {
 	return -ENODEV;
 }
diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c
index 4a3b41dd002..a4f15088236 100644
--- a/drivers/sound/sandbox.c
+++ b/drivers/sound/sandbox.c
@@ -101,7 +101,7 @@ static int sandbox_i2s_probe(struct udevice *dev)
 	uc_priv->channels = 2;
 	uc_priv->id = 1;
 
-	return sandbox_sdl_sound_init();
+	return sandbox_sdl_sound_init(uc_priv->samplingrate, uc_priv->channels);
 }
 
 static int sandbox_sound_setup(struct udevice *dev)
-- 
2.20.0.rc2.403.gdbc3b29805-goog



More information about the U-Boot mailing list