SAI_IO class for using CODEC (MW8994) as analog input and output. このライブラリを登録した際のプログラム:「F746_AudioIO_Demo」
Dependents: F746_SD_WavPlayer F746_SD_GraphicEqualizer_ren0620 Joerg_turbo_ede CW_Decoder_using_FFT_on_DiscoF746NG ... more
SAI_InOut.hpp
- Committer:
- MikamiUitOpen
- Date:
- 2016-05-09
- Revision:
- 1:48ed86c8430a
- Parent:
- 0:eade5d3ae0eb
- Child:
- 2:1aef7b703249
File content as of revision 1:48ed86c8430a:
//----------------------------------------------------------- // SiaIO class (Header) // 2016/05/09, Copyright (c) 2016 MIKAMI, Naoki //----------------------------------------------------------- #ifndef F746_SAI_IO_HPP #define F746_SAI_IO_HPP #include "mbed.h" #include "stm32746g_discovery_audio.h" #include "BSP_AudioIn_Overwrite.hpp" #include "BSP_AudioOut_Overwrite.hpp" namespace Mikami { class SaiIO { public: enum InOutBoth { INPUT, // input only OUTPUT, // output only BOTH }; // input and output // Constructor // inputDevice: INPUT_DEVICE_DIGITAL_MICROPHONE_2 or // INPUT_DEVICE_INPUT_LINE_1 // inputDevice == 0 : not use input device SaiIO(InOutBoth ioBoth, int size, int fs, uint16_t inputDevice = 0); ~SaiIO(); int32_t GetLength() { return nData_; } void StopAudioIn(); // sw = 0: DIGITAL_MICROPHONE_2 // 1: LINE_1 void SwitchInputDevice(int sw); bool IsCaptured(); void ResetCaptured() { captured_ = false; } void Input(int16_t &xL, int16_t &xR); void PlayOut(); bool IsXferred(); void ResetXferred() { xferred_ = false; } void Output(int16_t xL, int16_t xR); void Stop() { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); } void Pause(); void Resume(); // IF you use both input and output of SAI, // you can use following two functions. bool IsCompleted() { return IsCaptured() && IsXferred(); } void Reset() { captured_ = false; xferred_ = false; } // Following two member functions are called from // callback functions in "BSP_AudioIn_Overwrite.cpp" static void Captured1st() { Captured(0); } static void Captured2nd() { Captured(bufferSize_/2); } // Following two member functions are called from // callback functions in "BSP_AudioOut_Overwrite.cpp" static void FillBuffer1st() { FillBuffer(0); } static void FillBuffer2nd() { FillBuffer(bufferSize_/2); } // Called form the functions in "BSP_AudioIn_Overwrite.cpp" // and "BSP_AudioOut_Overwrite.cpp" static void ErrorTrap(); private: const int FS_; const InOutBoth IOBOTH_; int16_t* inBuffer_; static int16_t* outBuffer_; static int16_t* tmp_; __IO int32_t inIndex_; __IO int32_t tmpIndex_; static int32_t nData_; static int32_t bufferSize_; static __IO bool captured_; static __IO int32_t inOffset_; static __IO bool xferred_; void InitCodec(uint16_t inputDevice); void InitInput(); void InitOutput(); void ClearBuffer(); static void Captured(int32_t offset); static void FillBuffer(uint32_t offset); }; } #endif // F746_SAI_IO_HPP