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.

This commit is contained in:
Gregory Nutt 2014-07-22 15:54:56 -06:00
parent 9f5636ffa1
commit d7a9633dcd
4 changed files with 97 additions and 17 deletions

View File

@ -55,7 +55,7 @@
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/audio/audio.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) #if defined(CONFIG_AUDIO) && defined(CONFIG_AUDIO_FORMAT_PCM)
@ -99,6 +99,10 @@ struct pcm_decode_s
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_PCM_DEBUG
static void pcm_dump(FAR const struct wav_header_s *wav)
#endif
/* struct audio_lowerhalf_s methods *****************************************/ /* struct audio_lowerhalf_s methods *****************************************/
static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type, static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
@ -177,6 +181,49 @@ static int pcm_release(FAR struct audio_lowerhalf_s *dev);
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* 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 * Name: pcm_getcaps
* *

View File

@ -47,8 +47,8 @@
#include <nuttx/i2c.h> #include <nuttx/i2c.h>
#include <nuttx/audio/i2s.h> #include <nuttx/audio/i2s.h>
#include <nuttx/audio/pcm.h>
#include <nuttx/audio/wm8904.h> #include <nuttx/audio/wm8904.h>
#include <nuttx/audio/pcm_decode.h>
#include <arch/board/board.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. * 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.handler = isr;
g_mxtinfo.arg = arg; g_mxtinfo.arg = arg;
} }
else else
{ {
ivdbg("Detaching %p\n", g_mxtinfo.handler); audvdbg("Detaching %p\n", g_mxtinfo.handler);
wm8904_enable(lower, false); wm8904_enable(lower, false);
g_mxtinfo.handler = NULL; g_mxtinfo.handler = NULL;
g_mxtinfo.arg = NULL; g_mxtinfo.arg = NULL;

View File

@ -49,6 +49,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.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 #ifdef CONFIG_I2C_RESET
/* Perhaps the I2C bus is locked up? Try to shake the bus free */ /* 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); ret = up_i2creset(priv->i2c);
if (ret < 0) if (ret < 0)
{ {
idbg("ERROR: up_i2creset failed: %d\n", ret); auddbg("ERROR: up_i2creset failed: %d\n", ret);
break; break;
} }
#else #else
idbg("ERROR: I2C_TRANSFER failed: %d\n", ret); auddbg("ERROR: I2C_TRANSFER failed: %d\n", ret);
#endif #endif
} }
else else
@ -319,7 +320,7 @@ static uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr)
return regval; 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 */ /* 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 #ifdef CONFIG_I2C_RESET
/* Perhaps the I2C bus is locked up? Try to shake the bus free */ /* 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); ret = up_i2creset(priv->i2c);
if (ret < 0) if (ret < 0)
{ {
idbg("ERROR: up_i2creset failed: %d\n", ret); auddbg("ERROR: up_i2creset failed: %d\n", ret);
break; break;
} }
#else #else
idbg("ERROR: I2C_TRANSFER failed: %d\n", ret); auddbg("ERROR: I2C_TRANSFER failed: %d\n", ret);
#endif #endif
} }
else else
@ -397,7 +398,7 @@ static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr,
return; 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 */ /* Initialize I2C */
auddbg("address=%02x frequency=%d\n", lower->address, lower->frequency);
I2C_SETFREQUENCY(i2c, lower->frequency); I2C_SETFREQUENCY(i2c, lower->frequency);
I2C_SETADDRESS(i2c, lower->address, 7); I2C_SETADDRESS(i2c, lower->address, 7);

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* include/nuttx/audio/pcm_decode.h * include/nuttx/audio/pcm.h
* *
* Copyright (C) 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -33,8 +33,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H #ifndef __INCLUDE_NUTTX_AUDIO_PCM_H
#define __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H #define __INCLUDE_NUTTX_AUDIO_PCM_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -62,15 +62,46 @@
#endif #endif
#ifndef CONFIG_SCHED_WORKQUEUE #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 #endif
/* Default configuration values */ /* 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 * 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 * Public Data
****************************************************************************/ ****************************************************************************/
@ -115,4 +146,4 @@ FAR struct audio_lowerhalf_s *
#endif #endif
#endif /* CONFIG_AUDIO_FORMAT_PCM */ #endif /* CONFIG_AUDIO_FORMAT_PCM */
#endif /* __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H */ #endif /* __INCLUDE_NUTTX_AUDIO_PCM_H */