SAI_IO class for using CODEC (MW8994) as analog input and output. このライブラリを登録した際のプログラム:「F746_AudioIO_Demo」

Dependencies:   Array_Matrix

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-10
Revision:
3:3bfdd8be834f
Parent:
2:1aef7b703249
Child:
4:2170289dfe94

File content as of revision 3:3bfdd8be834f:

//-----------------------------------------------------------
//  SiaIO class (Header)
//  2016/05/10, 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 RecordIn();
        // 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 StopIn()   { BSP_AUDIO_IN_Stop(CODEC_PDWN_SW); }
        void PauseIn()  { BSP_AUDIO_IN_Pause(); }
        void ResumeIn() { BSP_AUDIO_IN_Resume(); }

        void PlayOut();
        bool IsXferred();
        void ResetXferred() { xferred_ = false; }
        void Output(int16_t xL, int16_t xR);
      
        void StopOut()   { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); }
        void PauseOut()  { BSP_AUDIO_OUT_Pause(); }
        void ResumeOut() { BSP_AUDIO_OUT_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(uint16_t inputDevice);
        void SetInput();
        void SetOutput();
        void ClearBuffer();

        static void Captured(int32_t offset);
        static void FillBuffer(uint32_t offset);
    };
}
#endif  // F746_SAI_IO_HPP