不韋 呂 / F746_SAI_IO

Dependencies:   Array_Matrix

Dependents:   F746_SD_WavPlayer F746_SD_GraphicEqualizer_ren0620 Joerg_turbo_ede CW_Decoder_using_FFT_on_DiscoF746NG ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SAI_InOut.hpp Source File

SAI_InOut.hpp

00001 //-----------------------------------------------------------
00002 //  SaiIO class (Header)
00003 //  2017/03/17, Copyright (c) 2017 MIKAMI, Naoki
00004 //-----------------------------------------------------------
00005 
00006 #ifndef F746_SAI_IO_HPP
00007 #define F746_SAI_IO_HPP
00008 
00009 #include "mbed.h"
00010 #include "stm32746g_discovery_audio.h"
00011 #include "BSP_AudioIn_Overwrite.hpp"
00012 #include "BSP_AudioOut_Overwrite.hpp"
00013 #include "Array.hpp"
00014 
00015 namespace Mikami
00016 {
00017     class SaiIO
00018     {
00019     public:
00020         enum InOutBoth { INPUT,     // input only
00021                          OUTPUT,    // output only
00022                          BOTH };    // input and output
00023         // Constructor
00024         //      inputDevice: INPUT_DEVICE_DIGITAL_MICROPHONE_2 or
00025         //                   INPUT_DEVICE_INPUT_LINE_1
00026         //      inputDevice == 0 : not use input device
00027         SaiIO(InOutBoth ioBoth, int size, int fs,
00028               uint16_t inputDevice = 0);
00029         virtual ~SaiIO() {}
00030  
00031         int32_t GetLength() { return nData_; }
00032         
00033         void RecordIn();
00034         // sw = 0: DIGITAL_MICROPHONE_2
00035         //      1: LINE_1
00036         void SwitchInputDevice(int sw);
00037 
00038         bool IsCaptured();
00039         // Input using SAI
00040         void Input(int16_t &xL, int16_t &xR)
00041         {   (this->*InputFp)(xL, xR); }
00042 
00043         void StopIn()   { BSP_AUDIO_IN_Stop(CODEC_PDWN_SW); }
00044         void PauseIn()  { BSP_AUDIO_IN_Pause(); }
00045         void ResumeIn() { BSP_AUDIO_IN_Resume(); }
00046 
00047         void PlayOut();
00048         bool IsXferred();
00049         // Output using SAI
00050         void Output(int16_t xL, int16_t xR);
00051       
00052         void StopOut()   { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); }
00053         void PauseOut()  { BSP_AUDIO_OUT_Pause(); }
00054         void ResumeOut() { BSP_AUDIO_OUT_Resume(); }
00055        
00056         // IF you use both input and output of SAI,
00057         // you can use following function
00058         bool IsCompleted()
00059         {   return IsCaptured() && IsXferred(); }
00060 
00061         // Following two member functions are called from
00062         // callback functions in "BSP_AudioIn_Overwrite.cpp"
00063         static void Captured1st() { Captured(0); }
00064         static void Captured2nd() { Captured(bufferSize_/2); }
00065 
00066         // Following two member functions are called from
00067         // callback functions in "BSP_AudioOut_Overwrite.cpp"
00068         static void FillBuffer1st() { FillBuffer(0); }
00069         static void FillBuffer2nd() { FillBuffer(bufferSize_/2); }
00070 
00071         // Called form the functions in "BSP_AudioIn_Overwrite.cpp"
00072         // and "BSP_AudioOut_Overwrite.cpp" 
00073         static void ErrorTrap();
00074 
00075     private:
00076         const int FS_;
00077         const InOutBoth IOBOTH_; 
00078 
00079         Array<uint16_t> inBuffer_;
00080         static Array<uint16_t> outBuffer_;
00081         static Array<uint16_t> tmp_;       
00082 
00083         __IO int32_t inIndex_;
00084         __IO int32_t tmpIndex_;
00085 
00086         static int32_t nData_;
00087         static int32_t bufferSize_;
00088         static __IO bool captured_;
00089         static __IO int32_t inOffset_;
00090         static __IO bool xferred_;
00091 
00092         void InitCodec(uint16_t inputDevice);
00093         void InitInput(uint16_t inputDevice);
00094         void SetInput();
00095         void SetOutput();
00096         void ClearBuffer();
00097 
00098         // This function pointer is assigned by
00099         // InputNormal() or InputReversal()
00100         void (SaiIO::*InputFp)(int16_t &, int16_t &);
00101         // For line input
00102         void InputNormal(int16_t &xL, int16_t &xR);
00103         // For MEMS microphone input
00104         void InputReversal(int16_t &xL, int16_t &xR);
00105         
00106         static void Captured(int32_t offset);
00107         static void FillBuffer(uint32_t offset);
00108     };
00109 }
00110 #endif  // F746_SAI_IO_HPP