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

Revision:
3:3bfdd8be834f
Parent:
2:1aef7b703249
Child:
4:2170289dfe94
--- a/SAI_InOut.cpp	Mon May 09 13:31:36 2016 +0000
+++ b/SAI_InOut.cpp	Tue May 10 12:26:13 2016 +0000
@@ -1,6 +1,6 @@
 //-----------------------------------------------------------
 //  SiaIO class
-//  2016/05/09, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/05/10, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "SAI_InOut.hpp"
@@ -54,7 +54,10 @@
         uint16_t dev = (sw == 0) ?
                         INPUT_DEVICE_DIGITAL_MICROPHONE_2
                       : INPUT_DEVICE_INPUT_LINE_1;
-        InitCodec(dev);
+        InitInput(dev);
+        ClearBuffer();
+        RecordIn();
+        if (IOBOTH_ == BOTH) PlayOut();
     }
     
     // If captured, return true
@@ -109,10 +112,21 @@
     // Initialize audio input and output 
     void SaiIO::InitCodec(uint16_t inputDevice)
     {
-        int audioInVolume = 0;
-        if (inputDevice != 0)
-            audioInVolume = (inputDevice == INPUT_DEVICE_INPUT_LINE_1) ?
-                                60 : 100;
+        if (inputDevice != 0) InitInput(inputDevice);
+
+        if (IOBOTH_ == OUTPUT)
+            if (BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE,
+                                   90, FS_) == AUDIO_ERROR)
+                ErrorTrap();
+
+        if (IOBOTH_ != OUTPUT) SetInput();
+        if (IOBOTH_ != INPUT) SetOutput();
+    }
+
+    void SaiIO::InitInput(uint16_t inputDevice)
+    {
+        int audioInVolume = (inputDevice == INPUT_DEVICE_INPUT_LINE_1) ?
+                            60 : 100;
 
         if (IOBOTH_ == BOTH)
             if (MyBSP_AUDIO_IN_OUT_Init(inputDevice, OUTPUT_DEVICE_HEADPHONE,
@@ -123,23 +137,15 @@
             if (BSP_AUDIO_IN_Init(inputDevice,
                                   audioInVolume, FS_) == AUDIO_ERROR)
                 ErrorTrap();
-
-        if (IOBOTH_ == OUTPUT)
-            if (BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE,
-                                   90, FS_) == AUDIO_ERROR)
-                ErrorTrap();
-
-        if (IOBOTH_ != OUTPUT) InitInput();
-        if (IOBOTH_ != INPUT) InitOutput();
     }
 
-    void SaiIO::InitInput()
+    void SaiIO::SetInput()
     {
         NVIC_SetVector(AUDIO_IN_SAIx_DMAx_IRQ,
                        (uint32_t)AUDIO_IN_SAIx_DMAx_IRQHandler);
     }
 
-    void SaiIO::InitOutput()
+    void SaiIO::SetOutput()
     {
         NVIC_SetVector(AUDIO_OUT_SAIx_DMAx_IRQ,
                        (uint32_t)AUDIO_OUT_SAIx_DMAx_IRQHandler);
@@ -184,4 +190,3 @@
     int16_t* SaiIO::tmp_;       
     __IO bool SaiIO::xferred_;
 }
-