Pull request for sound-2023-01-rc4
* Avoid endless loop and amend unit test * Add man-page for the sound command * Fix sandbox sound driver -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEbcT5xx8ppvoGt20zxIHbvCwFGsQFAmOOWpMACgkQxIHbvCwF GsRG5RAAiv0if+7vgU4oqzL1LI7gSRJg4ORHqOhtCSK+7qNanGDKRuPcAjN++Tt2 Cw5uOYFkaU9oGd2HgnfkxkDNr2S85ANQyPSE22GHa0jwoQSQtI7SBtFvawN6unsz h5w01oGxh4IIwtN6lpYnDp3mR8T/tsNsX2zh9WMpa0DURvnJIvRC34fhhoHRht3m CUtC23BA04NVWRxg26PD8XFeAVQlmD4s/yeYDTAe1BZG04r4tJGTq1tld/fV3rr6 1toT4RqzVBxamZBh7Q1hklPwa3i9P4HWDZ/6Qe3uccpQdeTpvYxKjmN+w6a4nNnd 7C50Qvu+iWJtxu0DVxjeVg1DFTjnp9sMk5zJBg9ZZNgGRvdA+92C/JfXA+XCmPbZ hpMjjtLqqVmsgLEuMzb9awUfqrpJVSPBnhqsuWSZGBfjlbkV+QHDfkVuuMjHhaSC zzNd8ZUazgywrbsQdc+zOpvXD5QPpn1qUadoXjehxepWA60Ba0lKPMzPNtG1nvmY lCXPXzOuu2KBSzytTLGfdStYjwqpA6LbbzYRkW/dIX+WO5GbxJCVt8ej7J7n34zM +mIeFyx/vh8wavFwIR4ZO59DoKRbeHJOZ8f0tkT6iOOkWEf7DQdWREFYniTflDVD h0QmPnJqsgpsjscx8HLJCMYY+HuzM5mcXzn4Hz/+s7taCdC7cl4= =eOd2 -----END PGP SIGNATURE----- Merge tag 'sound-2023-01-rc4' of https://source.denx.de/u-boot/custodians/u-boot-efi Pull request for sound-2023-01-rc4 * Avoid endless loop and amend unit test * Add man-page for the sound command * Fix sandbox sound driver
This commit is contained in:
commit
14f2d087a3
@ -441,7 +441,6 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
|
||||
{
|
||||
struct buf_info *buf;
|
||||
int avail;
|
||||
bool have_data = false;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
@ -453,10 +452,9 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
|
||||
}
|
||||
if (avail > len)
|
||||
avail = len;
|
||||
have_data = true;
|
||||
|
||||
SDL_MixAudio(stream, buf->data + buf->pos, avail,
|
||||
SDL_MIX_MAXVOLUME);
|
||||
memcpy(stream, buf->data + buf->pos, avail);
|
||||
stream += avail;
|
||||
buf->pos += avail;
|
||||
len -= avail;
|
||||
|
||||
@ -466,7 +464,8 @@ void sandbox_sdl_fill_audio(void *udata, Uint8 *stream, int len)
|
||||
else
|
||||
break;
|
||||
}
|
||||
sdl.stopping = !have_data;
|
||||
memset(stream, 0, len);
|
||||
sdl.stopping = !!len;
|
||||
}
|
||||
|
||||
int sandbox_sdl_sound_init(int rate, int channels)
|
||||
@ -484,7 +483,7 @@ int sandbox_sdl_sound_init(int rate, int channels)
|
||||
wanted.freq = rate;
|
||||
wanted.format = AUDIO_S16;
|
||||
wanted.channels = channels;
|
||||
wanted.samples = 1024; /* Good low-latency value for callback */
|
||||
wanted.samples = 960; /* Good low-latency value for callback */
|
||||
wanted.callback = sandbox_sdl_fill_audio;
|
||||
wanted.userdata = NULL;
|
||||
|
||||
|
@ -188,6 +188,16 @@ int sandbox_get_setup_called(struct udevice *dev);
|
||||
*/
|
||||
int sandbox_get_sound_active(struct udevice *dev);
|
||||
|
||||
/**
|
||||
* sandbox_get_sound_count() - Read back the count of the sound data so far
|
||||
*
|
||||
* This data is provided to the sandbox driver by the sound play() method.
|
||||
*
|
||||
* @dev: Device to check
|
||||
* Return: count of audio data
|
||||
*/
|
||||
int sandbox_get_sound_count(struct udevice *dev);
|
||||
|
||||
/**
|
||||
* sandbox_get_sound_sum() - Read back the sum of the sound data so far
|
||||
*
|
||||
|
@ -86,5 +86,5 @@ U_BOOT_CMD(
|
||||
sound, 4, 1, do_sound,
|
||||
"sound sub-system",
|
||||
"init - initialise the sound driver\n"
|
||||
"sound play [len] [freq] - play a sound for len ms at freq hz\n"
|
||||
"sound play [len [freq]] - play a sound for len ms at freq Hz\n"
|
||||
);
|
||||
|
41
doc/usage/cmd/sound.rst
Normal file
41
doc/usage/cmd/sound.rst
Normal file
@ -0,0 +1,41 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0+
|
||||
.. Copyright 2022, Heinrich Schuchardt <xypron.glpk@gmx.de>
|
||||
|
||||
sound command
|
||||
=============
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
sound init
|
||||
sound play [len [freq]]
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
The *sound* command is used to play a beep sound.
|
||||
|
||||
sound init
|
||||
initializes the sound driver.
|
||||
|
||||
sound play
|
||||
plays a square wave sound. It does not depend on previously calling
|
||||
*sound init*.
|
||||
|
||||
len
|
||||
duration of the sound in ms, defaults to 1000 ms
|
||||
|
||||
freq
|
||||
frequency of the sound in Hz, defaults to 400 Hz
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The sound command is enabled by CONFIG_CMD_SOUND=y.
|
||||
|
||||
Return value
|
||||
------------
|
||||
|
||||
The return value $? is 0 (true) if the command succeeds, 1 (false) otherwise.
|
@ -73,6 +73,7 @@ Shell commands
|
||||
cmd/scp03
|
||||
cmd/setexpr
|
||||
cmd/size
|
||||
cmd/sound
|
||||
cmd/temperature
|
||||
cmd/tftpput
|
||||
cmd/true
|
||||
|
@ -29,6 +29,7 @@ struct sandbox_i2s_priv {
|
||||
struct sandbox_sound_priv {
|
||||
int setup_called; /* Incremented when setup() method is called */
|
||||
bool active; /* TX data is being sent */
|
||||
int count; /* Use to count the provided audio data */
|
||||
int sum; /* Use to sum the provided audio data */
|
||||
bool allow_beep; /* true to allow the start_beep() interface */
|
||||
int frequency_hz; /* Beep frequency if active, else 0 */
|
||||
@ -68,6 +69,13 @@ int sandbox_get_sound_active(struct udevice *dev)
|
||||
return priv->active;
|
||||
}
|
||||
|
||||
int sandbox_get_sound_count(struct udevice *dev)
|
||||
{
|
||||
struct sandbox_sound_priv *priv = dev_get_priv(dev);
|
||||
|
||||
return priv->count;
|
||||
}
|
||||
|
||||
int sandbox_get_sound_sum(struct udevice *dev)
|
||||
{
|
||||
struct sandbox_sound_priv *priv = dev_get_priv(dev);
|
||||
@ -168,6 +176,7 @@ static int sandbox_sound_play(struct udevice *dev, void *data, uint data_size)
|
||||
|
||||
for (i = 0; i < data_size; i++)
|
||||
priv->sum += ((uint8_t *)data)[i];
|
||||
priv->count += data_size;
|
||||
|
||||
return i2s_tx_data(uc_priv->i2s, data, data_size);
|
||||
}
|
||||
|
@ -15,7 +15,10 @@ void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
|
||||
const int period = freq ? sample_rate / freq : 0;
|
||||
const int half = period / 2;
|
||||
|
||||
assert(freq);
|
||||
if (!half) {
|
||||
memset(data, 0, size);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure we don't overflow our buffer */
|
||||
if (size % 2)
|
||||
|
@ -26,8 +26,19 @@ static int dm_test_sound(struct unit_test_state *uts)
|
||||
ut_asserteq(0, sandbox_get_setup_called(dev));
|
||||
|
||||
ut_assertok(sound_beep(dev, 1, 100));
|
||||
ut_asserteq(48, sandbox_get_sound_count(dev));
|
||||
ut_asserteq(4560, sandbox_get_sound_sum(dev));
|
||||
ut_assertok(sound_beep(dev, 1, 100));
|
||||
ut_asserteq(96, sandbox_get_sound_count(dev));
|
||||
ut_asserteq(9120, sandbox_get_sound_sum(dev));
|
||||
ut_assertok(sound_beep(dev, 1, -100));
|
||||
ut_asserteq(144, sandbox_get_sound_count(dev));
|
||||
ut_asserteq(9120, sandbox_get_sound_sum(dev));
|
||||
ut_assertok(sound_beep(dev, 1, 0));
|
||||
ut_asserteq(192, sandbox_get_sound_count(dev));
|
||||
ut_asserteq(9120, sandbox_get_sound_sum(dev));
|
||||
ut_assertok(sound_beep(dev, 1, INT_MAX));
|
||||
ut_asserteq(240, sandbox_get_sound_count(dev));
|
||||
ut_asserteq(9120, sandbox_get_sound_sum(dev));
|
||||
ut_asserteq(false, sandbox_get_sound_active(dev));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user