Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed FrequencyResponseDrawer F746_SAI_IO Array_Matrix
Revision 7:2964179ff931, committed 2016-05-07
- Comitter:
- MikamiUitOpen
- Date:
- Sat May 07 07:58:42 2016 +0000
- Parent:
- 6:141ee26db40b
- Child:
- 8:e9309409f4a7
- Commit message:
- 8. From this revision, using class library "F746_SAI_IO".
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/F746_SAI_IO.lib Sat May 07 07:58:42 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/MikamiUitOpen/code/F746_SAI_IO/#eade5d3ae0eb
--- a/MyClasses_Functions/BSP_AudioOut_Overwrite.cpp Sun May 01 14:05:06 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-//--------------------------------------------------------------
-// Overwrite functuions and define calback functions
-// for functions in stm32746g_discovery_audio.cpp
-//--------------------------------------------------------------
-#include "BSP_AudioOut_Overwrite.hpp"
-
-// These three callback functions are modyfied by Mikami
-void BSP_AUDIO_OUT_HalfTransfer_CallBack()
-{
- Mikami::SaiIO_O::FillBuffer1st();
-}
-
-void BSP_AUDIO_OUT_TransferComplete_CallBack()
-{
- Mikami::SaiIO_O::FillBuffer2nd();
-}
-
-void BSP_AUDIO_OUT_Error_CallBack()
-{
- Mikami::SaiIO_O::ErrorTrap();
-}
-
-//--------------------------------------------------------------
-// Followings are original by Nanase
-//--------------------------------------------------------------
-
-DMA_HandleTypeDef hdma_sai_tx;
-
-void AUDIO_OUT_SAIx_DMAx_IRQHandler()
-{
- HAL_DMA_IRQHandler(&hdma_sai_tx);
-}
-
-void BSP_AUDIO_OUT_MspInit(SAI_HandleTypeDef *hsai, void *Params)
-{
- //static DMA_HandleTypeDef hdma_sai_tx;
- GPIO_InitTypeDef gpio_init_structure;
-
- /* Enable SAI clock */
- AUDIO_OUT_SAIx_CLK_ENABLE();
-
- /* Enable GPIO clock */
- AUDIO_OUT_SAIx_MCLK_ENABLE();
- AUDIO_OUT_SAIx_SCK_SD_ENABLE();
- AUDIO_OUT_SAIx_FS_ENABLE();
-
- /* CODEC_SAI pins configuration: FS, SCK, MCK and SD pins ------------------*/
- gpio_init_structure.Pin = AUDIO_OUT_SAIx_FS_PIN;
- gpio_init_structure.Mode = GPIO_MODE_AF_PP;
- gpio_init_structure.Pull = GPIO_NOPULL;
- gpio_init_structure.Speed = GPIO_SPEED_HIGH;
- gpio_init_structure.Alternate = AUDIO_OUT_SAIx_FS_SD_MCLK_AF;
- HAL_GPIO_Init(AUDIO_OUT_SAIx_FS_GPIO_PORT, &gpio_init_structure);
-
- gpio_init_structure.Pin = AUDIO_OUT_SAIx_SCK_PIN;
- gpio_init_structure.Mode = GPIO_MODE_AF_PP;
- gpio_init_structure.Pull = GPIO_NOPULL;
- gpio_init_structure.Speed = GPIO_SPEED_HIGH;
- gpio_init_structure.Alternate = AUDIO_OUT_SAIx_SCK_AF;
- HAL_GPIO_Init(AUDIO_OUT_SAIx_SCK_SD_GPIO_PORT, &gpio_init_structure);
-
- gpio_init_structure.Pin = AUDIO_OUT_SAIx_SD_PIN;
- gpio_init_structure.Mode = GPIO_MODE_AF_PP;
- gpio_init_structure.Pull = GPIO_NOPULL;
- gpio_init_structure.Speed = GPIO_SPEED_HIGH;
- gpio_init_structure.Alternate = AUDIO_OUT_SAIx_FS_SD_MCLK_AF;
- HAL_GPIO_Init(AUDIO_OUT_SAIx_SCK_SD_GPIO_PORT, &gpio_init_structure);
-
- gpio_init_structure.Pin = AUDIO_OUT_SAIx_MCLK_PIN;
- gpio_init_structure.Mode = GPIO_MODE_AF_PP;
- gpio_init_structure.Pull = GPIO_NOPULL;
- gpio_init_structure.Speed = GPIO_SPEED_HIGH;
- gpio_init_structure.Alternate = AUDIO_OUT_SAIx_FS_SD_MCLK_AF;
- HAL_GPIO_Init(AUDIO_OUT_SAIx_MCLK_GPIO_PORT, &gpio_init_structure);
-
- /* Enable the DMA clock */
- AUDIO_OUT_SAIx_DMAx_CLK_ENABLE();
-
- if(hsai->Instance == AUDIO_OUT_SAIx)
- {
- /* Configure the hdma_saiTx handle parameters */
- hdma_sai_tx.Init.Channel = AUDIO_OUT_SAIx_DMAx_CHANNEL;
- hdma_sai_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
- hdma_sai_tx.Init.PeriphInc = DMA_PINC_DISABLE;
- hdma_sai_tx.Init.MemInc = DMA_MINC_ENABLE;
- hdma_sai_tx.Init.PeriphDataAlignment = AUDIO_OUT_SAIx_DMAx_PERIPH_DATA_SIZE;
- hdma_sai_tx.Init.MemDataAlignment = AUDIO_OUT_SAIx_DMAx_MEM_DATA_SIZE;
- hdma_sai_tx.Init.Mode = DMA_CIRCULAR;
- hdma_sai_tx.Init.Priority = DMA_PRIORITY_HIGH;
- hdma_sai_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
- hdma_sai_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
- hdma_sai_tx.Init.MemBurst = DMA_MBURST_SINGLE;
- hdma_sai_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
-
- hdma_sai_tx.Instance = AUDIO_OUT_SAIx_DMAx_STREAM;
-
- /* Associate the DMA handle */
- __HAL_LINKDMA(hsai, hdmatx, hdma_sai_tx);
-
- /* Deinitialize the Stream for new transfer */
- HAL_DMA_DeInit(&hdma_sai_tx);
-
- /* Configure the DMA Stream */
- HAL_DMA_Init(&hdma_sai_tx);
- }
-
- /* SAI DMA IRQ Channel configuration */
- HAL_NVIC_SetPriority(AUDIO_OUT_SAIx_DMAx_IRQ, AUDIO_OUT_IRQ_PREPRIO, 0);
- HAL_NVIC_EnableIRQ(AUDIO_OUT_SAIx_DMAx_IRQ);
-}
-
-
--- a/MyClasses_Functions/BSP_AudioOut_Overwrite.hpp Sun May 01 14:05:06 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -//-------------------------------------------------------------- -// Overwrite functuions and define calback function (Header) -// for functions in stm32746g_discovery_audio.cpp -//-------------------------------------------------------------- - -#ifndef F746_AUDIO_OUT_OVERWRITE_HPP -#define F746_AUDIO_OUT_OVERWRITE_HPP - -#include "stm32746g_discovery_audio.h" -#include "SAI_Output.hpp" - -void AUDIO_OUT_SAIx_DMAx_IRQHandler(); - -#endif // F746_AUDIO_OUT_OVERWRITE_HPP
--- a/MyClasses_Functions/MyFunctions.cpp Sun May 01 14:05:06 2016 +0000
+++ b/MyClasses_Functions/MyFunctions.cpp Sat May 07 07:58:42 2016 +0000
@@ -1,13 +1,13 @@
//--------------------------------------------------------------
// フィルタ処理付き SD オーディオプレーヤーで使う大域関数(ヘッダ)
//
-// 2016/04/30, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/05/07, Copyright (c) 2016 MIKAMI, Naoki
//--------------------------------------------------------------
#include "MyFunctions.hpp"
// 1フレーム分の信号処理 (IIR フィルタ) の実行
-void ProcessSignal(SD_WavReader &sdReader, SaiIO_O &mySai,
+void ProcessSignal(SD_WavReader &sdReader, SaiIO &mySai,
int16_t sn[], float g0, Biquad hn[],
int order, bool filterOn)
{
--- a/MyClasses_Functions/MyFunctions.hpp Sun May 01 14:05:06 2016 +0000
+++ b/MyClasses_Functions/MyFunctions.hpp Sat May 07 07:58:42 2016 +0000
@@ -1,13 +1,13 @@
//--------------------------------------------------------------
// フィルタ処理付き SD オーディオプレーヤーで使う大域関数(ヘッダ)
//
-// 2016/04/20, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/05/07, Copyright (c) 2016 MIKAMI, Naoki
//--------------------------------------------------------------
#ifndef F746_MY_FUNCTIONS_HPP
#define F746_MY_FUNCTIONS_HPP
-#include "SAI_Output.hpp"
+#include "SAI_InOut.hpp"
#include "ButtonGroup.hpp"
#include "FileSelectorWav.hpp"
#include "DesignerDrawer.hpp"
@@ -16,7 +16,7 @@
using namespace Mikami;
// 1フレーム分の信号処理 (IIR フィルタ) の実行
-void ProcessSignal(SD_WavReader &sdReader, SaiIO_O &mySai,
+void ProcessSignal(SD_WavReader &sdReader, SaiIO &mySai,
int16_t sn[], float g0, Biquad hn[],
int order, bool filterOn);
--- a/MyClasses_Functions/SAI_Output.cpp Sun May 01 14:05:06 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-//-----------------------------------------------------------
-// SiaIO class for output
-// 2016/04/20, Copyright (c) 2016 MIKAMI, Naoki
-//-----------------------------------------------------------
-
-#include "SAI_Output.hpp"
-
-namespace Mikami
-{
- SaiIO_O::SaiIO_O(int size, int fs) : FS_(fs), tmpIndex_(0)
- {
- nData_ = size;
- bufferSize_ = (size*2)*2;
- outBuffer_ = new int16_t[(size*2)*2];
- tmp_ = new int16_t[size*2];
- xferred_ = false;
- }
- SaiIO_O::~SaiIO_O()
- {
- delete[] tmp_;
- delete[] outBuffer_;
- }
-
- void SaiIO_O::InitCodecOut()
- {
- if (BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, VOLUME_OUT_, FS_) == AUDIO_ERROR)
- ErrorTrap();
- for (int n=0; n<bufferSize_; n++) outBuffer_[n] = 0;
- for (int n=0; n<nData_*2; n++) tmp_[n] = 0;
-
- NVIC_SetVector(AUDIO_OUT_SAIx_DMAx_IRQ, (uint32_t)AUDIO_OUT_SAIx_DMAx_IRQHandler);
- BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
-
- if (BSP_AUDIO_OUT_Play((uint16_t *)outBuffer_,
- bufferSize_*AUDIODATA_SIZE) == AUDIO_ERROR)
- ErrorTrap();
- }
-
- bool SaiIO_O::IsXferred()
- {
- if (xferred_)
- {
- tmpIndex_ = 0;
- return true;
- }
- else
- return false;
- }
-
- void SaiIO_O::Output(int16_t xL, int16_t xR)
- {
- tmp_[tmpIndex_++] = xL; // Left
- tmp_[tmpIndex_++] = xR; // Right
- }
-
- void SaiIO_O::ErrorTrap()
- {
- DigitalOut led1(LED1);
- fprintf(stderr, "\r\n### ERROR\r\n");
- while(true)
- {
- led1 = !led1;
- wait_ms(250);
- }
- }
-
- void SaiIO_O::FillBuffer(uint32_t offset)
- {
- int k = offset;
- for (int n=0; n<nData_*2; n++)
- outBuffer_[k++] = tmp_[n];
- xferred_ = true;
- }
-
- // Instances for static variables
- int32_t SaiIO_O::nData_;
- int32_t SaiIO_O::bufferSize_;
- int16_t* SaiIO_O::outBuffer_;
- int16_t* SaiIO_O::tmp_;
- __IO bool SaiIO_O::xferred_;
-}
-
--- a/MyClasses_Functions/SAI_Output.hpp Sun May 01 14:05:06 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-//-----------------------------------------------------------
-// SiaIO class for output (Header)
-// 2016/04/20, 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_AudioOut_Overwrite.hpp"
-
-namespace Mikami
-{
- class SaiIO_O
- {
- public:
- SaiIO_O(int size, int fs);
- ~SaiIO_O();
-
- void InitCodecOut();
-
- bool IsXferred();
- void Output(int16_t xL, int16_t xR);
-
- void ResetXferred() { xferred_ = false; }
- int32_t GetLength() { return nData_; }
- void Stop() { BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); }
- void Pause() { BSP_AUDIO_OUT_Pause(); }
- void Resume() { BSP_AUDIO_OUT_Resume(); }
-
-
- // These three member functions are called from
- // callback functions in "BSP_AudioOut_Overwrite.cpp"
-
- // Called form BSP_AUDIO_OUT_HalfTransfer_CallBack()
- static void FillBuffer1st() { FillBuffer(0); }
- // Called form BSP_AUDIO_OUT_TransferComplete_CallBack()
- static void FillBuffer2nd() { FillBuffer(bufferSize_/2); }
- // Also called form BSP_AUDIO_OUT_Error_CallBack()
- static void ErrorTrap();
-
- private:
- const int FS_;
- static const uint8_t VOLUME_OUT_ = 90;
-
- static int32_t nData_;
- static int32_t bufferSize_;
-
- static int16_t* outBuffer_;
- static int16_t* tmp_;
-
- static __IO bool xferred_;
-
- __IO int32_t tmpIndex_;
-
- static void FillBuffer(uint32_t offset);
- };
-}
-#endif // F746_SAI_IO_HPP
--- a/main.cpp Sun May 01 14:05:06 2016 +0000
+++ b/main.cpp Sat May 07 07:58:42 2016 +0000
@@ -5,7 +5,7 @@
// IIR フィルタ ---- 低域通過および高域通過フィルタ
// 出力:モノラル
//
-// 2016/05/01, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/05/07, Copyright (c) 2016 MIKAMI, Naoki
//--------------------------------------------------------------
#include "MyFunctions.hpp"
@@ -19,7 +19,7 @@
Label myLabel2(200, 18, "---- variable LPF and HPF ----", Label::CENTER, Font12);
const int FS = AUDIO_FREQUENCY_44K; // 標本化周波数: 44.1 kHz
- SaiIO_O mySai(2048, FS);
+ SaiIO mySai(SaiIO::OUTPUT, 2048, FS);
SD_WavReader sdReader(mySai.GetLength()); // SD カード読み込み用オブジェクト
const int MAX_FILES = 7;
@@ -118,7 +118,6 @@
playOk = false;
bool stopOk = false;
- mySai.InitCodecOut(); // SAI の初期化
// IIR フィルタの内部の遅延器のクリア
for (int k=0; k<ORDER/2; k++) hn[k].Clear();