summaryrefslogtreecommitdiff
path: root/nuttx/audio
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-22 11:54:13 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-22 11:54:13 -0600
commitcae177b59da01dc14732e18542445ce166753b70 (patch)
tree9bb30f644a084d3f8299642c9763811a35b9d66a /nuttx/audio
parentd1b503397b59eb9826f07b1b6c526e6a3ad96d79 (diff)
downloadnuttx-cae177b59da01dc14732e18542445ce166753b70.tar.gz
nuttx-cae177b59da01dc14732e18542445ce166753b70.tar.bz2
nuttx-cae177b59da01dc14732e18542445ce166753b70.zip
Add new framework for the PCM decoder. It is now a 'front end' for lower-level drivers like the WM8904 that performs the PCM decoding from end
Diffstat (limited to 'nuttx/audio')
-rw-r--r--nuttx/audio/Makefile2
-rw-r--r--nuttx/audio/README.txt12
-rw-r--r--nuttx/audio/pcm.c94
-rw-r--r--nuttx/audio/pcm_decode.c564
4 files changed, 571 insertions, 101 deletions
diff --git a/nuttx/audio/Makefile b/nuttx/audio/Makefile
index b95e3900b..33b3a26a7 100644
--- a/nuttx/audio/Makefile
+++ b/nuttx/audio/Makefile
@@ -50,7 +50,7 @@ VPATH = .
# the appropriate paths to the VPATH variable
ifeq ($(CONFIG_AUDIO_FORMAT_PCM),y)
- CSRCS += pcm.c
+ CSRCS += pcm_decode.c
endif
AOBJS = $(ASRCS:.S=$(OBJEXT))
diff --git a/nuttx/audio/README.txt b/nuttx/audio/README.txt
index be86cacb0..85ab2e1a3 100644
--- a/nuttx/audio/README.txt
+++ b/nuttx/audio/README.txt
@@ -17,12 +17,12 @@ This directory holds the NuttX audio subsystem upper-half. The upper-half provi
a common interface for applications to interface with and also defines a bind
layer for specific lower-half audio device drivers.
- audio.c - The upper-half driver that binds to a lower-half driver from the
- drivers/audio subdirectory. For each attached audio device, there
- will be an instance of this upper-half driver bound to the
- instance of the lower half driver context.
- pcm.c - Routines to manage PCM / WAV type data. Currently just a placeholder.
- README - This file!
+ audio.c - The upper-half driver that binds to a lower-half driver from the
+ drivers/audio subdirectory. For each attached audio device, there
+ will be an instance of this upper-half driver bound to the
+ instance of the lower half driver context.
+ pcm_decode.c - Routines to decode PCM / WAV type data.
+ README - This file!
Portions of the the audio system interface have application interfaces. Those
portions reside in the nuttx/libc/audio directory where the will be built for
diff --git a/nuttx/audio/pcm.c b/nuttx/audio/pcm.c
deleted file mode 100644
index aeb1b7b64..000000000
--- a/nuttx/audio/pcm.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
- * audio/pcm.c
- *
- * Copyright (C) 2013 Ken Pettit. All rights reserved.
- * Author: Ken Pettit <pettitkd@gmail.com>
- *
- * 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 <sys/types.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <semaphore.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/audio/audio.h>
-
-#if defined(CONFIG_AUDIO) && defined(CONFIG_AUDIO_FORMAT_PCM)
-
-/****************************************************************************
- * Preprocessor Definitions
- ****************************************************************************/
-
-/* Configuration ************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Variables
- ****************************************************************************/
-
-/****************************************************************************
- * Public Variables
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: audio_pcm_init
- *
- * Initialized the Audio PCM library.
- *
- ****************************************************************************/
-
-int audio_pcm_initialize(void)
-{
- /* Initialze the Audio PCM routines */
-
- return OK;
-}
-
-#endif /* CONFIG_AUDIO && CONFIG_AUDIO_FORMAT_PCM */
-
diff --git a/nuttx/audio/pcm_decode.c b/nuttx/audio/pcm_decode.c
new file mode 100644
index 000000000..ba817a313
--- /dev/null
+++ b/nuttx/audio/pcm_decode.c
@@ -0,0 +1,564 @@
+/****************************************************************************
+ * audio/pcm_decode.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Based on the original audio framework from:
+ *
+ * Author: Ken Pettit <pettitkd@gmail.com>
+ *
+ * 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 <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <semaphore.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/pcm_decode.h>
+
+#if defined(CONFIG_AUDIO) && defined(CONFIG_AUDIO_FORMAT_PCM)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+/* This structure describes the internal state of the PCM decoder */
+
+struct pcm_decode_s
+{
+ /* This is is our our appearance to the outside world. This *MUST* be the
+ * first element of the structure so that we can freely cast between types
+ * struct audio_lowerhalf and struct pcm_decode_s.
+ */
+
+ struct audio_lowerhalf_s export;
+
+ /* These are our operations that intervene between the player application
+ * and the lower level driver. Unlike the ops in the struct
+ * audio_lowerhalf_s, these are writeable because we need to customize a
+ * few of the methods based upon what is supported by the the lower level
+ * driver.
+ */
+
+ struct audio_ops_s ops;
+
+ /* This is the contained, low-level DAC-type device and will receive the
+ * decoded PCM audio data.
+ */
+
+ FAR struct audio_lowerhalf_s *lower;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* struct audio_lowerhalf_s methods *****************************************/
+
+static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
+ FAR struct audio_caps_s *caps);
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_configure(FAR struct audio_lowerhalf_s *dev,
+ FAR void *session, FAR const struct audio_caps_s *caps);
+#else
+static int pcm_configure(FAR struct audio_lowerhalf_s *dev,
+ FAR const struct audio_caps_s *caps);
+#endif
+
+static int pcm_shutdown(FAR struct audio_lowerhalf_s *dev);
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_start(FAR struct audio_lowerhalf_s *dev, FAR void *session);
+#else
+static int pcm_start(FAR struct audio_lowerhalf_s *dev);
+#endif
+
+#ifndef CONFIG_AUDIO_EXCLUDE_STOP
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_stop(FAR struct audio_lowerhalf_s *dev, FAR void *session);
+#else
+static int pcm_stop(FAR struct audio_lowerhalf_s *dev);
+#endif
+#endif
+
+#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_pause(FAR struct audio_lowerhalf_s *dev, FAR void *session);
+#else
+static int pcm_pause(FAR struct audio_lowerhalf_s *dev);
+#endif
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_resume(FAR struct audio_lowerhalf_s *dev, FAR void *session);
+#else
+static int pcm_resume(FAR struct audio_lowerhalf_s *dev);
+#endif
+#endif
+
+static int pcm_allocbuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct audio_buf_desc_s *apb);
+static int pcm_freebuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct audio_buf_desc_s *apb);
+static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct ap_buffer_s *apb);
+static int pcm_cancelbuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct ap_buffer_s *apb);
+static int pcm_ioctl(FAR struct audio_lowerhalf_s *dev,
+ int cmd, unsigned long arg);
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_reserve(FAR struct audio_lowerhalf_s *dev, FAR void **session);
+#else
+static int pcm_reserve(FAR struct audio_lowerhalf_s *dev);
+#endif
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_release(FAR struct audio_lowerhalf_s *dev, FAR void *session);
+#else
+static int pcm_release(FAR struct audio_lowerhalf_s *dev);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pcm_getcaps
+ *
+ * Description:
+ * This method is called to retrieve the lower-half device capabilities.
+ * It will be called with device type AUDIO_TYPE_QUERY to request the
+ * overall capabilities, such as to determine the types of devices supported
+ * audio formats supported, etc. Then it may be called once or more with
+ * reported supported device types to determine the specific capabilities
+ * of that device type (such as MP3 encoder, WMA encoder, PCM output, etc.).
+ *
+ ****************************************************************************/
+
+static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
+ FAR struct audio_caps_s *caps)
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_configure
+ *
+ * Description:
+ * This method is called to bind the lower-level driver to the upper-level
+ * driver and to configure the driver for a specific mode of
+ * operation defined by the parameters selected in supplied device caps
+ * structure. The lower-level device should perform any initialization
+ * needed to prepare for operations in the specified mode. It should not,
+ * however, process any audio data until the start method is called.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_configure(FAR struct audio_lowerhalf_s *dev,
+ FAR void *session, FAR const struct audio_caps_s *caps)
+#else
+static int pcm_configure(FAR struct audio_lowerhalf_s *dev,
+ FAR const struct audio_caps_s *caps)
+#endif
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_shutdown
+ *
+ * Description:
+ * This method is called when the driver is closed. The lower half driver
+ * should stop processing audio data, including terminating any active
+ * output generation. It should also disable the audio hardware and put
+ * it into the lowest possible power usage state.
+ *
+ * Any enqueued Audio Pipeline Buffers that have not been processed / dequeued
+ * should be dequeued by this function.
+ *
+ ****************************************************************************/
+
+static int pcm_shutdown(FAR struct audio_lowerhalf_s *dev)
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_start
+ *
+ * Description:
+ * Start audio streaming in the configured mode. For input and synthesis
+ * devices, this means it should begin sending streaming audio data. For output
+ * or processing type device, it means it should begin processing of any enqueued
+ * Audio Pipeline Buffers.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_start(FAR struct audio_lowerhalf_s *dev, FAR void *session)
+#else
+static int pcm_start(FAR struct audio_lowerhalf_s *dev)
+#endif
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_stop
+ *
+ * Description:
+ * Stop audio streaming and/or processing of enqueued Audio Pipeline
+ * Buffers
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_AUDIO_EXCLUDE_STOP
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_stop(FAR struct audio_lowerhalf_s *dev, FAR void *session)
+#else
+static int pcm_stop(FAR struct audio_lowerhalf_s *dev)
+#endif
+#endif
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_pause
+ *
+ * Description:
+ * Pause the audio stream. Should keep current playback context active
+ * in case a resume is issued. Could be called and then followed by a stop.
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_pause(FAR struct audio_lowerhalf_s *dev, FAR void *session)
+#else
+static int pcm_pause(FAR struct audio_lowerhalf_s *dev)
+#endif
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_resume
+ *
+ * Description:
+ * Resumes audio streaming after a pause.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_resume(FAR struct audio_lowerhalf_s *dev, FAR void *session)
+#else
+static int pcm_resume(FAR struct audio_lowerhalf_s *dev)
+#endif
+#endif
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_allocbuffer
+ *
+ * Description:
+ * Allocate an audio pipeline buffer. This routine provides the
+ * lower-half driver with the opportunity to perform special buffer
+ * allocation if needed, such as allocating from a specific memory
+ * region (DMA-able, etc.). If not supplied, then the top-half
+ * driver will perform a standard kumalloc using normal user-space
+ * memory region.
+ *
+ ****************************************************************************/
+
+static int pcm_allocbuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct audio_buf_desc_s *apb)
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+ FAR struct audio_lowerhalf_s *lower;
+
+ DEBUGASSERT(priv);
+
+ /* Defer the operation to the lower device driver */
+
+ lower = priv->lower;
+ DEBUGASSERT(lower && lower->ops->allocbuffer);
+ return lower->ops->allocbuffer(lower, apb);
+}
+
+/****************************************************************************
+ * Name: pcm_freebuffer
+ *
+ * Description:
+ * Free an audio pipeline buffer. If the lower-level driver
+ * provides an allocbuffer routine, it should also provide the
+ * freebuffer routine to perform the free operation.
+ *
+ ****************************************************************************/
+
+static int pcm_freebuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct audio_buf_desc_s *apb)
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+ FAR struct audio_lowerhalf_s *lower;
+
+ DEBUGASSERT(priv);
+
+ /* Defer the operation to the lower device driver */
+
+ lower = priv->lower;
+ DEBUGASSERT(lower && lower->ops->freebuffer);
+ return lower->ops->freebuffer(lower, apb);
+}
+
+/****************************************************************************
+ * Name: pcm_enqueuebuffer
+ *
+ * Description:
+ * Enqueue a buffer for processing. This is a non-blocking enqueue operation.
+ * If the lower-half driver's buffer queue is full, then it should return an
+ * error code of -ENOMEM, and the upper-half driver can decide to either block
+ * the calling thread or deal with it in a non-blocking manner.
+ *
+ * For each call to enqueuebuffer, the lower-half driver must call
+ * audio_dequeuebuffer when it is finished processing the bufferr, passing the
+ * previously enqueued apb and a dequeue status so that the upper-half driver
+ * can decide if a waiting thread needs to be release, if the dequeued buffer
+ * should be passed to the next block in the Audio Pipeline, etc.
+ *
+ ****************************************************************************/
+
+static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct ap_buffer_s *apb)
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_cancelbuffer
+ *
+ * Description:
+ * Cancel a previously enqueued buffer.
+ *
+ ****************************************************************************/
+
+static int pcm_cancelbuffer(FAR struct audio_lowerhalf_s *dev,
+ FAR struct ap_buffer_s *apb)
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_ioctl
+ *
+ * Description:
+ * Lower-half logic may support platform-specific ioctl commands.
+ *
+ ****************************************************************************/
+
+static int pcm_ioctl(FAR struct audio_lowerhalf_s *dev,
+ int cmd, unsigned long arg)
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_reserve
+ *
+ * Description:
+ * Reserve a session (may only be one per device or may be multiple) for
+ * use by a client. Client software can open audio devices and issue
+ * AUDIOIOC_GETCAPS calls freely, but other operations require a
+ * reservation. A session reservation will assign a context that must
+ * be passed with
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_reserve(FAR struct audio_lowerhalf_s *dev, FAR void **session)
+#else
+static int pcm_reserve(FAR struct audio_lowerhalf_s *dev)
+#endif
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: pcm_release
+ *
+ * Description:
+ * Release a session.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int pcm_release(FAR struct audio_lowerhalf_s *dev, FAR void *session)
+#else
+static int pcm_release(FAR struct audio_lowerhalf_s *dev)
+#endif
+{
+ FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
+#warning Missing logic
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pcm_decode_initialize
+ *
+ * Description:
+ * Initialize the PCM device. The PCM device accepts and contains a
+ * low-level audio DAC-type device. It then returns a new audio lower
+ * half interface at adds a PCM decoding from end to the low-level
+ * audio device
+ *
+ * Input Parameters:
+ * dev - A reference to the low-level audio DAC-type device to contain.
+ *
+ * Returned Value:
+ * On success, a new audio device instance is returned that wraps the
+ * low-level device and provides a PCM decoding front end. NULL is
+ * returned on failure.
+ *
+ ****************************************************************************/
+
+FAR struct audio_lowerhalf_s *
+ pcm_decode_initialize(FAR struct audio_lowerhalf_s *dev)
+{
+ FAR struct pcm_decode_s *priv;
+ FAR struct audio_ops_s *ops;
+
+ /* Allocate an instance of our private data structure */
+
+ priv = (FAR struct pcm_decode_s *)kzalloc(sizeof(struct pcm_decode_s));
+ if (!priv)
+ {
+ auddbg("ERROR: Failed to allocate driver structure\n");
+ return NULL;
+ }
+
+ /* Initialize our private data structure. Since kzalloc() was used for
+ * the allocation, we need to initialize only non-zero, non-NULL, non-
+ * false fields.
+ */
+
+ ops = &priv->ops;
+ ops->getcaps = pcm_getcaps;
+ ops->configure = pcm_configure;
+ ops->shutdown = pcm_shutdown;
+ ops->start = pcm_start;
+
+#ifndef CONFIG_AUDIO_EXCLUDE_STOP
+ ops->stop = pcm_stop;
+#endif
+
+#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
+ ops->pause = pcm_pause;
+ ops->resume = pcm_resume;
+#endif
+
+ if (dev->ops->allocbuffer)
+ {
+ DEBUGASSERT(dev->ops->freebuffer);
+ ops->allocbuffer = pcm_allocbuffer;
+ ops->freebuffer = pcm_freebuffer;
+ }
+
+ ops->enqueuebuffer = pcm_enqueuebuffer;
+ ops->cancelbuffer = pcm_cancelbuffer;
+ ops->ioctl = pcm_ioctl;
+ ops->reserve = pcm_reserve;
+ ops->release = pcm_release;
+
+ priv->export.ops = &priv->ops;
+ priv->export.priv = priv;
+ priv->lower = dev;
+
+ return &priv->export;
+}
+
+#endif /* CONFIG_AUDIO && CONFIG_AUDIO_FORMAT_PCM */
+