diff mbox series

[U-Boot,3/4] sound: sandbox: Use the correct frequency

Message ID 20181116025615.221806-4-sjg@chromium.org
State Accepted
Commit 856b8f5629700fc329ea08b071ad04ecc377aea5
Delegated to: Simon Glass
Headers show
Series sound: Correct sound output on sandbox | expand

Commit Message

Simon Glass Nov. 16, 2018, 2:56 a.m. UTC
At present we request a particular frequency but we may not get the exact
same frequency in response. So use the actual frequency for generation of
the square wave. This ensures that the pitch remains accurate on all host
machines.

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

 arch/sandbox/cpu/sdl.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Simon Glass Nov. 29, 2018, 5:40 p.m. UTC | #1
At present we request a particular frequency but we may not get the exact
same frequency in response. So use the actual frequency for generation of
the square wave. This ensures that the pitch remains accurate on all host
machines.

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

 arch/sandbox/cpu/sdl.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Applied to u-boot-dm/master, thanks!
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index 36f1bf0c83b..c940a473d7c 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -9,6 +9,10 @@ 
 #include <sound.h>
 #include <asm/state.h>
 
+enum {
+	SAMPLE_RATE	= 22050,
+};
+
 static struct sdl_info {
 	SDL_Surface *screen;
 	int width;
@@ -18,6 +22,7 @@  static struct sdl_info {
 	uint frequency;
 	uint audio_pos;
 	uint audio_size;
+	uint sample_rate;
 	uint8_t *audio_data;
 	bool audio_active;
 	bool inited;
@@ -283,7 +288,7 @@  int sandbox_sdl_sound_init(void)
 	return 0;
 
 	/* Set the audio format */
-	wanted.freq = 22050;
+	wanted.freq = SAMPLE_RATE;
 	wanted.format = AUDIO_S16;
 	wanted.channels = 1;    /* 1 = mono, 2 = stereo */
 	wanted.samples = 1024;  /* Good low-latency value for callback */
@@ -309,6 +314,7 @@  int sandbox_sdl_sound_init(void)
 		goto err;
 	}
 	sdl.audio_active = true;
+	sdl.sample_rate = wanted.freq;
 
 	return 0;
 
@@ -322,7 +328,8 @@  int sandbox_sdl_sound_start(uint frequency)
 	if (!sdl.audio_active)
 		return -1;
 	sdl.frequency = frequency;
-	sound_create_square_wave(22050, (unsigned short *)sdl.audio_data,
+	sound_create_square_wave(sdl.sample_rate,
+				 (unsigned short *)sdl.audio_data,
 				 sdl.audio_size, frequency);
 	sdl.audio_pos = 0;
 	SDL_PauseAudio(0);