Synthesizer based on the Unzen / Nucleo F746ZG

Dependencies:   amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746

Fork of skeleton_unzen_nucleo_f746 by seiichi horie

雲仙フレームワークのテストとして作っているプロジェクトです。中身はどんどん変っていきます。 説明はDSP空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。

Committer:
shorie
Date:
Sun Dec 11 21:05:20 2016 +0000
Revision:
1:98ddcbbe10ba
Parent:
0:a837eeab3ca6
Child:
2:d5028a37f17b
Beta establishment. Demonstration of Unzen.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shorie 1:98ddcbbe10ba 1 #include "mbed.h"
shorie 1:98ddcbbe10ba 2
shorie 1:98ddcbbe10ba 3
shorie 0:a837eeab3ca6 4 #include "unzen.h" // audio framework include file
shorie 1:98ddcbbe10ba 5 #include "umb_adau1361a.h" // audio codec contoler include file
shorie 1:98ddcbbe10ba 6 #include "amakusa.h" // audio signal processing class library.
shorie 0:a837eeab3ca6 7
shorie 1:98ddcbbe10ba 8 #define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A
shorie 0:a837eeab3ca6 9
shorie 0:a837eeab3ca6 10 DigitalOut myled1(LED1);
shorie 0:a837eeab3ca6 11
shorie 1:98ddcbbe10ba 12 amakusa::OSCSinCos osc( 440.0, 48000 ); // freq=440Hz, Fs=48kHz.
shorie 0:a837eeab3ca6 13
shorie 0:a837eeab3ca6 14 // customer signal processing initialization call back.
shorie 0:a837eeab3ca6 15 void init_callback(
shorie 0:a837eeab3ca6 16 unsigned int block_size // block size [sample]
shorie 0:a837eeab3ca6 17 )
shorie 0:a837eeab3ca6 18 {
shorie 0:a837eeab3ca6 19 // place initialization code here
shorie 0:a837eeab3ca6 20 }
shorie 0:a837eeab3ca6 21
shorie 0:a837eeab3ca6 22
shorie 0:a837eeab3ca6 23 // customer signal processing call back.
shorie 0:a837eeab3ca6 24 void process_callback(
shorie 0:a837eeab3ca6 25 float rx_left_buffer[], // array of the left input samples
shorie 0:a837eeab3ca6 26 float rx_right_buffer[], // array of the right input samples
shorie 0:a837eeab3ca6 27 float tx_left_buffer[], // place to write the left output samples
shorie 0:a837eeab3ca6 28 float tx_right_buffer[], // place to write the left output samples
shorie 0:a837eeab3ca6 29 unsigned int block_size // block size [sample]
shorie 0:a837eeab3ca6 30 )
shorie 0:a837eeab3ca6 31 {
shorie 1:98ddcbbe10ba 32 // generate tone.
shorie 1:98ddcbbe10ba 33 osc.run( tx_left_buffer, block_size );
shorie 1:98ddcbbe10ba 34
shorie 1:98ddcbbe10ba 35 // copy left to right
shorie 0:a837eeab3ca6 36 for ( int i=0; i<block_size; i++) // for all sample
shorie 0:a837eeab3ca6 37 {
shorie 1:98ddcbbe10ba 38 tx_right_buffer[i] = tx_left_buffer[i] *= 0.5F;
shorie 0:a837eeab3ca6 39
shorie 0:a837eeab3ca6 40 }
shorie 0:a837eeab3ca6 41 }
shorie 0:a837eeab3ca6 42
shorie 0:a837eeab3ca6 43
shorie 0:a837eeab3ca6 44
shorie 0:a837eeab3ca6 45 int main()
shorie 0:a837eeab3ca6 46 {
shorie 0:a837eeab3ca6 47 // I2C is essential to talk with ADAU1361
shorie 0:a837eeab3ca6 48 I2C i2c(D14, D15);
shorie 0:a837eeab3ca6 49
shorie 0:a837eeab3ca6 50 // create an audio codec contoler
shorie 1:98ddcbbe10ba 51 shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR ); // Fs can be Fs_32, Fs_441, Fs_48, Fs_96
shorie 0:a837eeab3ca6 52
shorie 0:a837eeab3ca6 53 // create an audio framework by singlton pattern
shorie 0:a837eeab3ca6 54 unzen::Framework audio;
shorie 0:a837eeab3ca6 55
shorie 0:a837eeab3ca6 56 // Set I3C clock to 100kHz
shorie 0:a837eeab3ca6 57 i2c.frequency( 100000 );
shorie 0:a837eeab3ca6 58
shorie 0:a837eeab3ca6 59
shorie 0:a837eeab3ca6 60 // Configure the optional block size of signal processing. By default, it is 1[Sample]
shorie 0:a837eeab3ca6 61 // audio.set_block_size(16);
shorie 0:a837eeab3ca6 62
shorie 0:a837eeab3ca6 63
shorie 0:a837eeab3ca6 64 // Start the ADAU1361. Audio codec starts to generate the I2C signals
shorie 0:a837eeab3ca6 65 codec.start();
shorie 0:a837eeab3ca6 66
shorie 0:a837eeab3ca6 67 // Start the audio framework on ARM processor.
shorie 0:a837eeab3ca6 68 audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework
shorie 0:a837eeab3ca6 69
shorie 1:98ddcbbe10ba 70 codec.set_hp_output_gain( -3, -3 );
shorie 1:98ddcbbe10ba 71 codec.set_line_output_gain( -3, -3 );
shorie 0:a837eeab3ca6 72
shorie 0:a837eeab3ca6 73 // periodically changing gain for test
shorie 0:a837eeab3ca6 74 while(1)
shorie 0:a837eeab3ca6 75 {
shorie 1:98ddcbbe10ba 76 /*
shorie 1:98ddcbbe10ba 77 myled1 = 1;
shorie 1:98ddcbbe10ba 78 wait(0.2);
shorie 1:98ddcbbe10ba 79 myled1 = 0;
shorie 1:98ddcbbe10ba 80 wait(0.2);
shorie 1:98ddcbbe10ba 81 */
shorie 0:a837eeab3ca6 82 }
shorie 0:a837eeab3ca6 83 }