This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CC3200AUDBOOST: Playing .wav file from an SD card

Part Number: CC3200AUDBOOST
Other Parts Discussed in Thread: CC3200

Tool/software: Code Composer Studio

Update: I am now getting audio to play through my device after working with the code, however I cannot change the sample rate from 16000 while configuring the speakercodec and still get audio to play.

I have been attempting to play a .wav file from an SD card with the CC3200AudioBooster Pack addon but it does not output any sound. I have based my Speaker.c code off of code found in this post  and the Wifi-Audio example in the cc3200 sdk.When I debug this code the pRxBuffer fills and is forever stuck in the while loop waiting for it to empty. I can post the code from my main.c if that would help.

//*****************************************************************************
//                 GLOBAL VARIABLES -- Start
//*****************************************************************************
extern tUDPSocket g_UdpSock;
int g_iReceiveCount =0;
int g_iRetVal =0;
int iCount =0;

#define USERFILE        "trance.wav"
#define BUFFSIZE 100
unsigned char pBuffer[BUFFSIZE];

FIL fp;
FATFS fs;
FRESULT res;
DIR dir;
UINT Size;

extern unsigned long  g_ulStatus;
extern unsigned char g_ucSpkrStartFlag;
extern unsigned char g_uiPlayWaterMark;
extern unsigned char g_loopback;
extern tCircularBuffer *pRxBuffer;
//*****************************************************************************
//                 GLOBAL VARIABLES -- End
//*****************************************************************************

static void
ListDirectory()
{
    FILINFO fno;
    FRESULT res;
    unsigned long ulSize;
    tBoolean bIsInKB;

    for(;;)
    {
        res = f_readdir(&dir, &fno);           // Read a directory item
        if (res != FR_OK || fno.fname[0] == 0)
        {
        break;                                // Break on error or end of dir
        }
        ulSize = fno.fsize;
        bIsInKB = false;
        if(ulSize > 1024)
        {
            ulSize = ulSize/1024;
            bIsInKB = true;
        }
        Report("->%-15s%5d %-2s    %-5s\n\r",fno.fname,ulSize,\
                (bIsInKB == true)?"KB":"B",(fno.fattrib&AM_DIR)?"Dir":"File");
    }

}

void openFile(){
    Message("\n\rReading user file...\n\r");
    res = f_open(&fp,USERFILE,FA_READ);
    f_lseek(&fp,44);
}

void readFile(){
    if(res == FR_OK)
    {
        f_read(&fp,pBuffer,BUFFSIZE,&Size);
        Report("Read : %d Bytes\n\n\r",Size);
        Report("%s",pBuffer);
    }
    else
    {
        Report("Failed to open %s\n\r",USERFILE);
    }
}

void closeFile(){
    f_close(&fp);
}


//*****************************************************************************
//
//! Speaker Routine 
//!
//! \param pvParameters     Parameters to the task's entry function
//!
//! \return None
//
//*****************************************************************************
void Speaker( void *pvParameters )
{
    long iRetVal;
    f_mount(&fs,"0",1);
    res = f_opendir(&dir,"/");
    ListDirectory();
    //open file
    openFile();
    g_ucSpkrStartFlag = 1;
    while(1)
    {
      while(g_ucSpkrStartFlag)
      {
        // Read from file and discard wav header
        readFile();
        /* Wait to avoid buffer overflow as reading speed is faster than playback */
        while((IsBufferSizeFilled(pRxBuffer,PLAY_WATERMARK) == TRUE)){};
        if( Size > 0)
        {
          iRetVal = FillBuffer(pRxBuffer,(unsigned char*)pBuffer, Size);
          if(iRetVal < 0)
          {
            UART_PRINT("Unable to fill buffer");
            LOOP_FOREVER();
          }
        }
        else
        { // we reach at the of file
        //close file
        closeFile();
        // reopen the file
        openFile();
        }
        if(g_uiPlayWaterMark == 0)
        {
          if(IsBufferSizeFilled(pRxBuffer,PLAY_WATERMARK) == TRUE)
          {
            g_uiPlayWaterMark = 1;
          }
        }
        g_iReceiveCount++;
      }
      MAP_UtilsDelay(1000);
    }
}

  • This is my configuration from Main.c:

        //
        // Configure Audio Codec
        //     
        AudioCodecReset(AUDIO_CODEC_TI_3254, NULL);
        AudioCodecConfig(AUDIO_CODEC_TI_3254, AUDIO_CODEC_16_BIT, SAMPLERATE,
                          AUDIO_CODEC_STEREO, AUDIO_CODEC_SPEAKER_ALL,
                          AUDIO_CODEC_MIC_NONE);
    
        AudioCodecSpeakerVolCtrl(AUDIO_CODEC_TI_3254, AUDIO_CODEC_SPEAKER_ALL, 50);
       
        //
        // Initialize the Audio(I2S) Module
        //    
    
        AudioInit();
    
        //
        // Initialize the DMA Module
        //    
        UDMAInit();
        if(RecordPlay & I2S_MODE_TX)
        {
           UDMAChannelSelect(UDMA_CH5_I2S_TX, NULL);
            SetupPingPongDMATransferRx(pRxBuffer);
        }
        //if(RecordPlay == I2S_MODE_RX_TX)
        //{
        //    UDMAChannelSelect(UDMA_CH4_I2S_RX, NULL);
        //    SetupPingPongDMATransferTx(pRecordBuffer);
        //}
    
        //
        // Setup the Audio In/Out
        //     
        lRetVal = AudioSetupDMAMode(DMAPingPongCompleteAppCB_opt, \
                                     CB_EVENT_CONFIG_SZ, RecordPlay);
        if(lRetVal < 0)
        {
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }    
        AudioCaptureRendererConfigure(AUDIO_CODEC_16_BIT, SAMPLERATE, AUDIO_CODEC_STEREO, RecordPlay, 1);
    
        //
        // Start Audio Tx/Rx
        //     
        Audio_Start(RecordPlay);

  • Look at the implementation of AudioCaptureRendererConfigure, and you will see why

    -Aaron
  • I'm not sure I understand why is it hard coded to use 16khz? I have edited the function to run at my desired bit rate and it seems to work just fine playing at 44khz? Is there a reason it was hard set to 16khz?

    void AudioCaptureRendererConfigure(unsigned char bitsPerSample,
                                        unsigned short bitRate,
                                        unsigned char noOfChannels,
                                        unsigned char RxTx,
                                        unsigned char	dma)
    {
        unsigned long	bitClk;
        bitClk = bitsPerSample * bitRate * noOfChannels;
        if(dma)
        {
            if(bitsPerSample == 16)
            {
                MAP_PRCMI2SClockFreqSet(bitClk);
                MAP_I2SConfigSetExpClk(I2S_BASE,bitClk,bitClk,I2S_SLOT_SIZE_16|
                                        I2S_PORT_DMA);
            }
        }
        if(RxTx == I2S_MODE_RX_TX)
        {
            MAP_I2SSerializerConfig(I2S_BASE,I2S_DATA_LINE_1,I2S_SER_MODE_RX,
                                     I2S_INACT_LOW_LEVEL);
        }
        if(RxTx & I2S_MODE_TX)
        {
            MAP_I2SSerializerConfig(I2S_BASE,I2S_DATA_LINE_0,I2S_SER_MODE_TX,
                                     I2S_INACT_LOW_LEVEL);
        }
    }