1
0
Fork 0
forked from nuttx/nuttx-update

nuttx/audio: add fake audio driver.

The fake audio driver aims to easily simulate the functions of 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.

Signed-off-by: yaojingwei <yaojingwei@xiaomi.com>
This commit is contained in:
yaojingwei 2024-11-11 11:23:47 +08:00 committed by Alan C. Assis
parent a58d6552e6
commit bbd6931d61
7 changed files with 1262 additions and 0 deletions

View file

@ -26,6 +26,7 @@
#include <nuttx/arch.h>
#include <nuttx/audio/audio.h>
#include <nuttx/audio/audio_fake.h>
#include <nuttx/kthread.h>
#include <nuttx/motor/foc/foc_dummy.h>
#include <nuttx/mtd/mtd.h>
@ -298,6 +299,12 @@ void up_initialize(void)
audio_register("mixer", sim_audio_initialize(false, false));
#ifdef CONFIG_AUDIO_FAKE
/* Register fake audio driver */
audio_fake_initialize();
#endif
#endif
#ifdef CONFIG_SIM_USB_DEV

View file

@ -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_FAKE_AUDIO_DEVICE_PARAMS" # Arguments for the fake audio device
# NxWidgets/NxWM
"CONFIG_NXWM_BACKGROUND_IMAGE" # Name of bitmap image class
"CONFIG_NXWM_CALIBRATION_ICON" # Name of bitmap image class

View file

@ -518,4 +518,52 @@ config AUDIO_DMA
depends on AUDIO
depends on DMA
config AUDIO_FAKE
bool "Fake audio device"
default n
depends on AUDIO
---help---
A fake audio device driver to simplify testing of audio
capture and playback.
if AUDIO_FAKE
config FAKE_AUDIO_DEVICE_PARAMS
string "fake audio device params"
default ""
---help---
This is a params for fake audio device. The format like:
{dev_name, playback, sample_rates[4], channels, format[4], period_time, periods}.
- dev_name (string): pcm2c or pcm2p or others.
- playback (bool): true or false.
- 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", false, {8000, 16000, 44100}, {1, 2}, {16}, 100, 4},
{"pcm2p", true, {8000, 16000, 44100}, {1, 2}, {16}, 100, 4},
config FAKE_AUDIO_DATA_PATH
string "fake 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.
config AUDIO_FAKE_MSG_PRIO
int "Fake audio device message priority"
default 1
config AUDIO_FAKE_WORKER_STACKSIZE
int "Fake audio device worker thread stack size"
default 768
endif # AUDIO_FAKE
endif # DRIVERS_AUDIO

View file

@ -87,6 +87,10 @@ ifeq ($(CONFIG_AUDIO_NULL),y)
CSRCS += audio_null.c
endif
ifeq ($(CONFIG_AUDIO_FAKE),y)
CSRCS += audio_fake.c
endif
ifeq ($(CONFIG_AUDIO_TONE),y)
CSRCS += tone.c
endif

1149
drivers/audio/audio_fake.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,52 @@
/****************************************************************************
* include/nuttx/audio/audio_fake.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_AUDIO_AUDIO_FAKE_H
#define __INCLUDE_NUTTX_AUDIO_AUDIO_FAKE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_AUDIO_FAKE
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
int audio_fake_initialize(void);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_AUDIO_FAKE */
#endif /* __INCLUDE_NUTTX_AUDIO_AUDIO_FAKE_H */

View file

@ -65,6 +65,7 @@ static const char *dequote_list[] =
"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_FAKE_AUDIO_DEVICE_PARAMS", /* Arguments for the fake audio device */
/* NxWidgets/NxWM */