summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-22 15:54:56 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-22 15:54:56 -0600
commitf485ee1c197bd29727218dbb68b48df47f816dda (patch)
tree65dca766843dc4befd19d5a83fd295d197d204fa /nuttx
parente793665a9bb98dcb75143f60bacdf958e5128f33 (diff)
downloadpx4-nuttx-f485ee1c197bd29727218dbb68b48df47f816dda.tar.gz
px4-nuttx-f485ee1c197bd29727218dbb68b48df47f816dda.tar.bz2
px4-nuttx-f485ee1c197bd29727218dbb68b48df47f816dda.zip
Rename pcm_decode.h to pcm.h since it will hold more than just decoding definitions. Fix some porting errors like idbg should auddbg, etc. Add wav file header and a few low-level wav utilities.
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/audio/pcm_decode.c49
-rw-r--r--nuttx/configs/sama5d4-ek/src/sam_wm8904.c6
-rw-r--r--nuttx/drivers/audio/wm8904.c18
-rw-r--r--nuttx/include/nuttx/audio/pcm.h (renamed from nuttx/include/nuttx/audio/pcm_decode.h)41
4 files changed, 97 insertions, 17 deletions
diff --git a/nuttx/audio/pcm_decode.c b/nuttx/audio/pcm_decode.c
index ba817a313..6cf7327fc 100644
--- a/nuttx/audio/pcm_decode.c
+++ b/nuttx/audio/pcm_decode.c
@@ -55,7 +55,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/audio/audio.h>
-#include <nuttx/audio/pcm_decode.h>
+#include <nuttx/audio/pcm.h>
#if defined(CONFIG_AUDIO) && defined(CONFIG_AUDIO_FORMAT_PCM)
@@ -99,6 +99,10 @@ struct pcm_decode_s
* Private Function Prototypes
****************************************************************************/
+#ifdef CONFIG_PCM_DEBUG
+static void pcm_dump(FAR const struct wav_header_s *wav)
+#endif
+
/* struct audio_lowerhalf_s methods *****************************************/
static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
@@ -178,6 +182,49 @@ static int pcm_release(FAR struct audio_lowerhalf_s *dev);
****************************************************************************/
/****************************************************************************
+ * Name: pcm_dump
+ *
+ * Description:
+ * Dump a WAV file header.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_PCM_DEBUG
+static void pcm_dump(FAR const struct wav_header_s *wav)
+{
+ printf( "Wave file header\n");
+ printf( " Chunk ID: 0x%08x\n", wav->chkid);
+ printf( " Chunk Size: %u\n", wav->chklen);
+ printf( " Format: 0x%08x\n", wav->format);
+ printf( " SubChunk ID: 0x%08x\n", wav->subchkid1);
+ printf( " Subchunk1 Size: %u\n", wav->subchklen1);
+ printf( " Audio Format: 0x%04x\n", wav->compression);
+ printf( " Num. Channels: %d\n", wav->nchannels);
+ printf( " Sample Rate: %u\n", wav->samprate);
+ printf( " Byte Rate: %u\n", wav->byterate);
+ printf( " Block Align: %d\n", wav->align);
+ printf( " Bits Per Sample: %d\n", wav->bpsamp);
+ printf( " Subchunk2 ID: 0x%08x\n", wav->subchkid2);
+ printf( " Subchunk2 Size: %u\n", wav->subchklen2);
+}
+#endif
+
+/****************************************************************************
+ * Name: pcm_validwav
+ *
+ * Description:
+ * Return true if this is a valid WAV file header
+ *
+ ****************************************************************************/
+
+static inline bool pcm_validwav(FAR const struct wav_header_s *wav)
+{
+ return (wav->chkid == WAV_CHUNKID &&
+ wav->format == WAV_FORMAT &&
+ wav->subchklen1 == WAV_SUBCHKLEN1);
+}
+
+/****************************************************************************
* Name: pcm_getcaps
*
* Description:
diff --git a/nuttx/configs/sama5d4-ek/src/sam_wm8904.c b/nuttx/configs/sama5d4-ek/src/sam_wm8904.c
index 012d33f82..d10fa38f9 100644
--- a/nuttx/configs/sama5d4-ek/src/sam_wm8904.c
+++ b/nuttx/configs/sama5d4-ek/src/sam_wm8904.c
@@ -47,8 +47,8 @@
#include <nuttx/i2c.h>
#include <nuttx/audio/i2s.h>
+#include <nuttx/audio/pcm.h>
#include <nuttx/audio/wm8904.h>
-#include <nuttx/audio/pcm_decode.h>
#include <arch/board/board.h>
@@ -152,13 +152,13 @@ static int wm8904_attach(FAR const struct wm8904_lower_s *lower,
* new handler will called via wm8904_interrupt() when the interrupt occurs.
*/
- ivdbg("Attaching %p\n", isr);
+ audvdbg("Attaching %p\n", isr);
g_mxtinfo.handler = isr;
g_mxtinfo.arg = arg;
}
else
{
- ivdbg("Detaching %p\n", g_mxtinfo.handler);
+ audvdbg("Detaching %p\n", g_mxtinfo.handler);
wm8904_enable(lower, false);
g_mxtinfo.handler = NULL;
g_mxtinfo.arg = NULL;
diff --git a/nuttx/drivers/audio/wm8904.c b/nuttx/drivers/audio/wm8904.c
index 0ebb85a09..f09910732 100644
--- a/nuttx/drivers/audio/wm8904.c
+++ b/nuttx/drivers/audio/wm8904.c
@@ -49,6 +49,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
+
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
@@ -294,16 +295,16 @@ static uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr)
#ifdef CONFIG_I2C_RESET
/* Perhaps the I2C bus is locked up? Try to shake the bus free */
- idbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret);
+ auddbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret);
ret = up_i2creset(priv->i2c);
if (ret < 0)
{
- idbg("ERROR: up_i2creset failed: %d\n", ret);
+ auddbg("ERROR: up_i2creset failed: %d\n", ret);
break;
}
#else
- idbg("ERROR: I2C_TRANSFER failed: %d\n", ret);
+ auddbg("ERROR: I2C_TRANSFER failed: %d\n", ret);
#endif
}
else
@@ -319,7 +320,7 @@ static uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr)
return regval;
}
- ivdbg("retries=%d regaddr=%04x\n", retries, regaddr);
+ audvdbg("retries=%d regaddr=%02x\n", retries, regaddr);
}
/* No error indication is returned on a failure... just return zero */
@@ -375,16 +376,16 @@ static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr,
#ifdef CONFIG_I2C_RESET
/* Perhaps the I2C bus is locked up? Try to shake the bus free */
- idbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret);
+ auddbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret);
ret = up_i2creset(priv->i2c);
if (ret < 0)
{
- idbg("ERROR: up_i2creset failed: %d\n", ret);
+ auddbg("ERROR: up_i2creset failed: %d\n", ret);
break;
}
#else
- idbg("ERROR: I2C_TRANSFER failed: %d\n", ret);
+ auddbg("ERROR: I2C_TRANSFER failed: %d\n", ret);
#endif
}
else
@@ -397,7 +398,7 @@ static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr,
return;
}
- ivdbg("retries=%d regaddr=%04x\n", retries, regaddr);
+ audvdbg("retries=%d regaddr=%02x\n", retries, regaddr);
}
}
@@ -1792,6 +1793,7 @@ FAR struct audio_lowerhalf_s *
/* Initialize I2C */
+ auddbg("address=%02x frequency=%d\n", lower->address, lower->frequency);
I2C_SETFREQUENCY(i2c, lower->frequency);
I2C_SETADDRESS(i2c, lower->address, 7);
diff --git a/nuttx/include/nuttx/audio/pcm_decode.h b/nuttx/include/nuttx/audio/pcm.h
index 300c8c908..33c5de0de 100644
--- a/nuttx/include/nuttx/audio/pcm_decode.h
+++ b/nuttx/include/nuttx/audio/pcm.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * include/nuttx/audio/pcm_decode.h
+ * include/nuttx/audio/pcm.h
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -33,8 +33,8 @@
*
****************************************************************************/
-#ifndef __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H
-#define __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H
+#ifndef __INCLUDE_NUTTX_AUDIO_PCM_H
+#define __INCLUDE_NUTTX_AUDIO_PCM_H
/****************************************************************************
* Included Files
@@ -62,15 +62,46 @@
#endif
#ifndef CONFIG_SCHED_WORKQUEUE
-# error CONFIG_SCHED_WORKQUEUE is required by the PCM driver
+# error CONFIG_SCHED_WORKQUEUE is required by the PCM decoder
#endif
/* Default configuration values */
+/* WAVE Header Definitions **************************************************/
+/* All values are little endian */
+
+#define WAV_CHUNKID 0x46464952 /* "RIFF" */
+#define WAV_FORMAT 0x45564157 /* "WAVE" */
+#define WAV_SUBCHKID1 0x20746d66 /* "fmt " */
+#define WAV_SUBCHKLEN1 16 /* Size of a PCM subchunk */
+#define WAV_COMPRESSION 1 /* Linear quantization */
+#define WAV_MONO 1 /* nchannels=1 */
+#define WAV_STEREO 2 /* nchannels=2 */
+#define WAV_DATA 0x61746164 /* "data"
+
/****************************************************************************
* Public Types
****************************************************************************/
+/* Standard WAV file header format */
+
+struct wav_header_s
+{
+ uint32_t chkid; /* Contains the letters "RIFF" in ASCII form. */
+ uint32_t chklen; /* Size of the rest of the following chunk */
+ uint32_t format; /* Contains the letters "WAVE" */
+ uint32_t subchkid1; /* Contains the letters "fmt " */
+ uint32_t subchklen1; /* Size of the following subchunk (16 for PCM) */
+ uint16_t compression; /* PCM=1 (i.e. Linear quantization) */
+ uint16_t nchannels; /* Mono=1, Stereo=2 */
+ uint32_t samprate; /* 8000, 44100, ... */
+ uint32_t byterate; /* samprate * nchannels * bpsamp / 8 */
+ uint16_t align; /* nchannels * bpsamp / 8 */
+ uint16_t bpsamp; /* Bits per sample: 8 bits = 8, 16 bits = 16 */
+ uint32_t subchkid2; /* Contains the letters "data" */
+ uint32_t subchklen2; /* Number of bytes in the data */
+};
+
/****************************************************************************
* Public Data
****************************************************************************/
@@ -115,4 +146,4 @@ FAR struct audio_lowerhalf_s *
#endif
#endif /* CONFIG_AUDIO_FORMAT_PCM */
-#endif /* __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H */
+#endif /* __INCLUDE_NUTTX_AUDIO_PCM_H */