jerpelea commented on a change in pull request #2282:
URL: https://github.com/apache/incubator-nuttx/pull/2282#discussion_r526012405



##########
File path: drivers/audio/cxd56_src.c
##########
@@ -0,0 +1,607 @@
+/****************************************************************************
+ * drivers/audio/cxd56_src.c
+ *
+ *   Copyright 2020 Sony Semiconductor Solutions Corporation
+ *
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <math.h>
+#include <queue.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/mqueue.h>
+
+#include "cxd56.h"
+#include "cxd56_src.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* For debugging: dump pre/post SRC data to sdcard */
+
+/* #define DUMP_DATA */
+
+/* Note: 24 bit samples not currently supported by SRC */
+
+#define BUFFER_SAMPLES  (CONFIG_CXD56_AUDIO_BUFFER_SIZE / 2)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+enum cxd56_srcstate_e
+{
+  CXD56_SRC_OFF,
+  CXD56_SRC_RUNNING,
+  CXD56_SRC_STOPPING,
+  CXD56_SRC_STOPPED
+};
+
+struct cxd56_srcdata_s
+{
+  enum cxd56_srcstate_e state;
+
+  float float_in[BUFFER_SAMPLES];
+  float float_out[BUFFER_SAMPLES];
+  int float_in_offset;
+
+  SRC_DATA src_data;
+  SRC_STATE *src_state;
+
+  struct dq_queue_s *inq;
+  struct dq_queue_s *outq;
+
+  char mqname[32];
+  mqd_t mq;
+  sem_t pendsem;
+  pthread_t threadid;
+
+  uint8_t bytewidth;
+  uint8_t channels;
+
+  float buf_count;
+  float buf_increment;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct cxd56_srcdata_s g_src;
+
+#ifdef DUMP_DATA
+static char *dump_name_pre  = "/mnt/sd0/dump/nx_player_dump_pre.pcm";
+static char *dump_name_post = "/mnt/sd0/dump/nx_player_dump_post.pcm";
+int dump_file_pre = -1;
+int dump_file_post = -1;
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+extern void src_short_to_float_array (const short *in, float *out, int len);
+extern void src_float_to_short_array (const float *in, short *out, int len);
+extern void src_int_to_float_array (const int *in, float *out, int len);
+extern void src_float_to_int_array (const float *in, int *out, int len);
+
+static struct ap_buffer_s *cxd56_src_get_apb()
+{
+  struct ap_buffer_s *src_apb;
+  irqstate_t flags;
+
+  flags = spin_lock_irqsave();
+
+  if (dq_count(g_src.inq) == 0)
+    {
+      size_t bufsize = sizeof(struct ap_buffer_s) +
+                              CONFIG_CXD56_AUDIO_BUFFER_SIZE;
+
+      spin_unlock_irqrestore(flags);
+
+      src_apb = kmm_zalloc(bufsize);
+
+      flags = spin_lock_irqsave();
+
+      if (!src_apb)
+        {
+          auderr("ERROR: Couldn't allocate SRC APB (size %d)\n", bufsize);
+
+          goto errorout_with_lock;
+        }
+
+      src_apb->nmaxbytes = CONFIG_CXD56_AUDIO_BUFFER_SIZE;
+      src_apb->nbytes = 0;
+      src_apb->samp = (FAR uint8_t *)(&src_apb->samp + 1);
+    }
+  else
+    {
+      src_apb = (struct ap_buffer_s *) dq_get(g_src.inq);
+    }
+
+  src_apb->flags = 0;
+
+  spin_unlock_irqrestore(flags);
+
+  return src_apb;
+
+errorout_with_lock:

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to