Skip to content

Commit

Permalink
nuttx/audio: improve null audio driver.
Browse files Browse the repository at this point in the history
This patch aims to enhance the null audio driver through reading and writing files.
With it, you can conveniently customize and define various capture or playback audio drivers
for debugging or automated testing.

Change-Id: If39eb9db4bbfdf31ab313346b42242b8a125388c
Signed-off-by: yaojingwei <yaojingwei@xiaomi.com>
  • Loading branch information
yaojingwei committed Dec 13, 2024
1 parent 5cdc6c7 commit 7337e03
Show file tree
Hide file tree
Showing 6 changed files with 731 additions and 32 deletions.
7 changes: 7 additions & 0 deletions arch/sim/src/sim/sim_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <nuttx/arch.h>
#include <nuttx/audio/audio.h>
#include <nuttx/audio/audio_null.h>
#include <nuttx/kthread.h>
#include <nuttx/motor/foc/foc_dummy.h>
#include <nuttx/mtd/mtd.h>
Expand Down Expand Up @@ -298,6 +299,12 @@ void up_initialize(void)

audio_register("mixer", sim_audio_initialize(false, false));

#if defined(CONFIG_AUDIO_NULL) && defined(CONFIG_AUDIO_NULL_DEVICE_PARAMS)
/* Register null audio driver */

null_audio_register();
#endif

#endif

#ifdef CONFIG_SIM_USB_DEV
Expand Down
1 change: 1 addition & 0 deletions cmake/nuttx_mkconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set(DEQUOTELIST
"CONFIG_TTY_LAUNCH_ENTRYPOINT" # Name of entry point from tty launch
"CONFIG_TTY_LAUNCH_ARGS" # Argument list of entry point from tty launch
"CONFIG_BOARD_MEMORY_RANGE" # Memory range for board
"CONFIG_AUDIO_NULL_DEVICE_PARAMS" # Arguments for the null audio device
# NxWidgets/NxWM
"CONFIG_NXWM_BACKGROUND_IMAGE" # Name of bitmap image class
"CONFIG_NXWM_CALIBRATION_ICON" # Name of bitmap image class
Expand Down
27 changes: 27 additions & 0 deletions drivers/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,33 @@ config AUDIO_NULL_WORKER_STACKSIZE
int "Null audio device worker thread stack size"
default 768

config AUDIO_NULL_DEVICE_PARAMS
string "Null audio device params"
default ""
---help---
This is a params for null audio device. The params is following format:
{dev_name, mode, sample_rates[4], channels, format[4], period_time, periods}.

- dev_name (string): pcm2c or pcm2p or others.
- mode (string): playback or capture.
- sample_rates(uint32 array): {16000, 32000}.
- channels (uint8, {min_chan, max_chan}): {1, 2}.
- format(uint8 array): {8,16,32}.
- period_time(uint32): 100, unit ms.
- periods (uint32): 4, buffer cnt.
e.g:
{"pcm2c", "capture", {8000, 16000, 44100}, {1, 2}, {16}, 100, 4},
{"pcm2p", "playback", {8000, 16000, 44100}, {1, 2}, {16}, 100, 4},

config AUDIO_NULL_DATA_PATH
string "Null audio device data path"
default "/data/"
---help---
This dir is used to store the audio file for virtual capture or playback device.
The filename for capture device should comply with the format "devname_samplerate_channels_format.pcm".
e.g: pcm2c_16000_2_16.pcm.
The filename format of playback device is the same as capture device.
e.g: pcm2p_16000_2_16.pcm.
endif # AUDIO_NULL

config AUDIO_I2S
Expand Down
Loading

0 comments on commit 7337e03

Please sign in to comment.