Audio: Add a NULL audio device that can be used to simply unit-level testing of audio decoders

This commit is contained in:
Gregory Nutt
2014-07-23 10:12:32 -06:00
parent 78f56be4c1
commit ca7d7c34ce
11 changed files with 1185 additions and 15 deletions
+4
View File
@@ -84,6 +84,10 @@ endif
endif
endif
ifeq ($(CONFIG_AUDIO_NULL),y)
CSRCS += sam_audio_null.c
endif
ifeq ($(CONFIG_SAMA5_HSMCI0),y)
CSRCS += sam_hsmci.c
else
+168
View File
@@ -0,0 +1,168 @@
/************************************************************************************
* configs/sama5d4-ek/src/sam_audio_null.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <debug.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/audio/audio.h>
#include <nuttx/audio/pcm.h>
#include <nuttx/audio/audio_null.h>
#include "sama5d4-ek.h"
#ifdef HAVE_AUDIO_NULL
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_audio_null_initialize
*
* Description:
* Set up to use the NULL audio device for PCM unit-level testing.
*
* Input Parameters:
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int sam_audio_null_initialize(int minor)
{
FAR struct audio_lowerhalf_s *nullaudio;
FAR struct audio_lowerhalf_s *pcm;
static bool initialized = false;
char devname[12];
int ret;
auddbg("minor %d\n", minor);
DEBUGASSERT(minor >= 0 && minor <= 25);
/* Have we already initialized? Since we never uninitialize we must prevent
* multiple initializations. This is necessary, for example, when the
* touchscreen example is used as a built-in application in NSH and can be
* called numerous time. It will attempt to initialize each time.
*/
if (!initialized)
{
/* Get a null audio interface
*/
nullaudio = audio_null_initialize();
if (!nullaudio)
{
auddbg("Failed to get the NULL audio interface\n");
ret = -ENODEV;
goto errout;
}
/* No we can embed the null audio interface into a PCM decoder
* instance so that we will have a PCM front end for the NULL
* audio driver.
*/
pcm = pcm_decode_initialize(nullaudio);
if (!pcm)
{
auddbg("ERROR: Failed create the PCM decoder\n");
ret = -ENODEV;
goto errout_with_nullaudio;
}
/* Create a device name */
snprintf(devname, 12, "pcm%d", minor);
/* Finally, we can register the PCM/NULL audio device. */
ret = audio_register(devname, pcm);
if (ret < 0)
{
auddbg("ERROR: Failed to register /dev/%s device: %d\n", devname, ret);
goto errout_with_pcm;
}
/* Now we are initialized */
initialized = true;
}
return OK;
/* Error exits. Unfortunately there is no mechanism in place now to
* recover resources from most errors on initialization failures.
*/
errout_with_nullaudio:
errout_with_pcm:
errout:
return ret;
}
#endif /* HAVE_AUDIO_NULL */
+11 -1
View File
@@ -158,7 +158,7 @@ int nsh_archinitialize(void)
#endif
#ifdef HAVE_WM8904
/* Start the USB Monitor */
/* Configure WM8904 audio */
ret = sam_wm8904_initialize(0);
if (ret != OK)
@@ -167,6 +167,16 @@ int nsh_archinitialize(void)
}
#endif
#ifdef HAVE_AUDIO_NULL
/* Configure the NULL audio device */
ret = sam_audio_null_initialize(0);
if (ret != OK)
{
message("ERROR: Failed to initialize the NULL audio device: %d\n", ret);
}
#endif
/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.
+1 -1
View File
@@ -334,7 +334,7 @@ int sam_wm8904_initialize(int minor)
return OK;
/* Error exits. Unfortunately there is no mechanism in place now to
* recover from most errors on initialization failures.
* recover resources from most errors on initialization failures.
*/
errout_with_pcm:
+38 -1
View File
@@ -65,6 +65,7 @@
#define HAVE_NETWORK 1
#define HAVE_MAXTOUCH 1
#define HAVE_WM8904 1
#define HAVE_AUDIO_NULL 1
/* HSMCI */
/* Can't support MMC/SD if the card interface(s) are not enable */
@@ -317,7 +318,7 @@
#endif
/* Audio */
/* Default configuration values */
/* PCM/WM8904 driver */
#ifndef CONFIG_AUDIO_WM8904
# undef HAVE_WM8904
@@ -351,6 +352,23 @@
# endif
#endif
/* PCM/null driver */
#ifndef CONFIG_AUDIO_NULL
# undef HAVE_AUDIO_NULL
#endif
#ifdef HAVE_WM8904
# undef HAVE_AUDIO_NULL
#endif
#ifdef HAVE_AUDIO_NULL
# ifndef CONFIG_AUDIO_FORMAT_PCM
# warning CONFIG_AUDIO_FORMAT_PCM is required for audio support
# undef HAVE_AUDIO_NULL
# endif
#endif
/* LEDs *****************************************************************************/
/* There are 3 LEDs on the SAMA5D4-EK:
*
@@ -925,6 +943,25 @@ int nsh_archinitialize(void);
int sam_wm8904_initialize(int minor);
#endif /* HAVE_WM8904 */
/****************************************************************************
* Name: sam_audio_null_initialize
*
* Description:
* Set up to use the NULL audio device for PCM unit-level testing.
*
* Input Parameters:
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
#ifdef HAVE_AUDIO_NULL
int sam_audio_null_initialize(int minor);
#endif /* HAVE_AUDIO_NULL */
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_SAMA5D4_EK_SRC_SAMA5D4_EK_H */
+52
View File
@@ -106,5 +106,57 @@ config AUDIO_WM8904
that dependency is not explicit here.
if AUDIO_WM8904
config WM8904_INITVOLUME
int "WM8904 initial volume setting"
default 250
config WM8904_INFLIGHT
int "WM8904 maximum in-flight audio buffers"
default 2
config WM8904_MSG_PRIO
int "WM8904 message priority"
default 1
config WM8904_BUFFER_SIZE
int "WM8904 preferred buffer size"
default 8192
config WM8904_NUM_BUFFERS
int "WM8904 preferred number of buffers"
default 4
config WM8904_WORKER_STACKSIZE
int "WM8904 worker thread stack size"
default 768
endif # AUDIO_WM8904
config AUDIO_NULL
bool "NULL audio device"
default n
depends on AUDIO
---help---
A do-nothinig audio device driver to simplify testing of audio
decoders.
if AUDIO_NULL
config AUDIO_NULL_MSG_PRIO
int "Null audio device message priority"
default 1
config UDIO_NULL_BUFFER_SIZE
int "Null audio device preferred buffer size"
default 8192
config AUDIO_NULL_NUM_BUFFERS
int "Null audio device preferred number of buffers"
default 4
config AUDIO_NULL_WORKER_STACKSIZE
int "Null audio device worker thread stack size"
default 768
endif # AUDIO_NULL
+4
View File
@@ -47,6 +47,10 @@ ifeq ($(CONFIG_AUDIO_WM8904),y)
CSRCS += wm8904.c
endif
ifeq ($(CONFIG_AUDIO_NULL),y)
CSRCS += audio_null.c
endif
ifeq ($(CONFIG_AUDIO_I2SCHAR),y)
CSRCS += i2schar.c
endif
File diff suppressed because it is too large Load Diff
+4 -9
View File
@@ -95,7 +95,7 @@ struct wm8904_dev_s
* "half" that is referred to as "lower".
*/
struct audio_lowerhalf_s dev; /* WM8904 audio lower half (this drive) */
struct audio_lowerhalf_s dev; /* WM8904 audio lower half (this device) */
/* Our specific driver data goes here */
@@ -181,15 +181,10 @@ static int wm8904_stop(FAR struct audio_lowerhalf_s *dev);
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8904_pause(FAR struct audio_lowerhalf_s *dev,
FAR void* session);
#else
static int wm8904_pause(FAR struct audio_lowerhalf_s *dev);
#endif
#endif
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8904_resume(FAR struct audio_lowerhalf_s *dev,
FAR void* session);
#else
static int wm8904_pause(FAR struct audio_lowerhalf_s *dev);
static int wm8904_resume(FAR struct audio_lowerhalf_s *dev);
#endif
#endif
@@ -1755,8 +1750,8 @@ static void wm8904_audio_input(FAR struct wm8904_dev_s *priv)
* lower - Persistent board configuration data
*
* Returned Value:
* A new lower half audio interface is returned for the WM8904 device is
* returned on success; NULL is returned on failure.
* A new lower half audio interface for the WM8904 device is returned on
* success; NULL is returned on failure.
*
****************************************************************************/
+136
View File
@@ -0,0 +1,136 @@
/****************************************************************************
* include/nuttx/audio/audio_null.h
* A do-nothinig audio device driver to simplify testing of audio decoders.
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_AUDIO_AUDIO_NULL_H
#define __INCLUDE_NUTTX_AUDIO_AUDIO_NULL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/irq.h>
#ifdef CONFIG_AUDIO_NULL
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************
*
* CONFIG_AUDIO_NULL - Enabled NULL audio device support
* CONFIG_AUDIO_NULL_MSG_PRIO - Priority of messages sent to the NULL audio
* device worker thread.
* CONFIG_AUDIO_NULL_BUFFER_SIZE - Preferred buffer size
* CONFIG_AUDIO_NULL_NUM_BUFFERS - Preferred number of buffers
* CONFIG_AUDIO_NULL_WORKER_STACKSIZE - Stack size to use when creating the
* NULL audio device worker thread.
*/
/* Pre-requisites */
#ifndef CONFIG_AUDIO
# error CONFIG_AUDIO is required for audio subsystem support
#endif
/* Default configuration values */
#ifndef CONFIG_AUDIO_NULL_MSG_PRIO
# define CONFIG_AUDIO_NULL_MSG_PRIO 1
#endif
#ifndef CONFIG_AUDIO_NULL_BUFFER_SIZE
# define CONFIG_AUDIO_NULL_BUFFER_SIZE 8192
#endif
#ifndef CONFIG_AUDIO_NULL_NUM_BUFFERS
# define CONFIG_AUDIO_NULL_NUM_BUFFERS 4
#endif
#ifndef CONFIG_AUDIO_NULL_WORKER_STACKSIZE
# define CONFIG_AUDIO_NULL_WORKER_STACKSIZE 768
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: audio_null_initialize
*
* Description:
* Initialize the null audio device.
*
* Input Parameters:
* i2c - An I2C driver instance
* i2s - An I2S driver instance
* lower - Persistent board configuration data
*
* Returned Value:
* A new lower half audio interface for the NULL audio device is returned
* on success; NULL is returned on failure.
*
****************************************************************************/
struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */
FAR struct audio_lowerhalf_s *audio_null_initialize(void);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_AUDIO_NULL */
#endif /* __INCLUDE_NUTTX_AUDIO_AUDIO_NULL_H */
+3 -3
View File
@@ -93,7 +93,7 @@
/* Default configuration values */
#ifndef CONFIG_WM8904_INITVOLUME
# define CONFIG_WM8904_INITVOLUME 250
# define CONFIG_WM8904_INITVOLUME 250
#endif
#ifndef CONFIG_WM8904_INFLIGHT
@@ -199,8 +199,8 @@ extern "C"
* lower - Persistent board configuration data
*
* Returned Value:
* A new lower half audio interface is returned for the WM8904 device is
* returned on success; NULL is returned on failure.
* A new lower half audio interface for the WM8904 device is returned on
* success; NULL is returned on failure.
*
****************************************************************************/