Output the audio signal (*.bin) with filtering by IIR filter in the SD card using onboard CODEC. For *.wav file, F746_SD_WavPlayer and F746_SD_GraphicEqualiser are published on mbed. SD カードのオーディオ信号 (*.bin) を遮断周波数可変の IIR フィルタを通して,ボードに搭載されているCODEC で出力する.*.wav 形式のファイル用には,F746_SD_WavPlayer と F746_SD_GraphicEqualiser を mbed で公開している.

Dependencies:   BSP_DISCO_F746NG_patch_fixed F746_GUI LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sai_io_o.cpp Source File

sai_io_o.cpp

00001 //-----------------------------------------------------------
00002 //  SiaIO class for output
00003 //  2016/02/16, Copyright (c) 2016 MIKAMI, Naoki
00004 //-----------------------------------------------------------
00005 
00006 #include "sai_io_o.hpp"
00007 
00008 namespace Mikami
00009 {
00010     SaiIO_O::SaiIO_O(int size, int fs) : FS_(fs), tmpIndex_(0)
00011     {
00012         nData_ = size;
00013         bufferSize_ = (size*2)*2;
00014         outBuffer_ = new int16_t[(size*2)*2];
00015         tmp_ = new int16_t[size*2];
00016         xferred_ = false;
00017     }
00018     SaiIO_O::~SaiIO_O()
00019     {
00020         delete[] tmp_;
00021         delete[] outBuffer_;
00022     }
00023 
00024     void SaiIO_O::InitCodecOut()
00025     {
00026         if (BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, VOLUME_OUT_, FS_) == AUDIO_ERROR)
00027             ErrorTrap();
00028         for (int n=0; n<bufferSize_; n++) outBuffer_[n] = 0;
00029         for (int n=0; n<nData_*2; n++) tmp_[n] = 0;
00030 
00031         NVIC_SetVector(AUDIO_OUT_SAIx_DMAx_IRQ, (uint32_t)AUDIO_OUT_SAIx_DMAx_IRQHandler);
00032         BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
00033 
00034         if (BSP_AUDIO_OUT_Play((uint16_t *)outBuffer_,
00035                                bufferSize_*AUDIODATA_SIZE) == AUDIO_ERROR)
00036             ErrorTrap();
00037     }
00038 
00039     bool SaiIO_O::IsXferred()
00040     {
00041         if (xferred_)
00042         {
00043             tmpIndex_ = 0;
00044             return true;
00045         }
00046         else
00047             return false;
00048     }
00049 
00050     void SaiIO_O::Output(int16_t xL, int16_t xR)
00051     {
00052         tmp_[tmpIndex_++] = xL; // Left
00053         tmp_[tmpIndex_++] = xR; // Right
00054     }
00055     
00056     void SaiIO_O::ErrorTrap()
00057     {
00058         DigitalOut led1(LED1);
00059         fprintf(stderr, "\r\n### ERROR\r\n");
00060         while(true)
00061         {
00062             led1 = !led1;
00063             wait_ms(250);
00064         }
00065     }
00066 
00067     void SaiIO_O::FillBuffer(uint32_t offset)
00068     {
00069         int k = offset;
00070         for (int n=0; n<nData_*2; n++)
00071              outBuffer_[k++] = tmp_[n];
00072         xferred_ = true;
00073     }
00074 
00075     // Instances for static variables
00076     int32_t SaiIO_O::nData_;
00077     int32_t SaiIO_O::bufferSize_;
00078     int16_t* SaiIO_O::outBuffer_;
00079     int16_t* SaiIO_O::tmp_;       
00080     __IO bool SaiIO_O::xferred_;
00081 }
00082 
00083