Synthesizer based on the Unzen / Nucleo F746ZG
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
雲仙フレームワークのテストとして作っているプロジェクトです。中身はどんどん変っていきます。 説明はDSP空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。
main.cpp@0:a837eeab3ca6, 2016-06-19 (annotated)
- Committer:
- shorie
- Date:
- Sun Jun 19 05:47:06 2016 +0000
- Revision:
- 0:a837eeab3ca6
- Child:
- 1:98ddcbbe10ba
Sample program of the nucleo_f746
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 0:a837eeab3ca6 | 1 | #include "unzen.h" // audio framework include file |
shorie | 0:a837eeab3ca6 | 2 | #include "umb_adau1361a.h" // audio codec contoler include file |
shorie | 0:a837eeab3ca6 | 3 | #include "mbed.h" |
shorie | 0:a837eeab3ca6 | 4 | |
shorie | 0:a837eeab3ca6 | 5 | #define CODEC_I2C_ADDR 0x38 |
shorie | 0:a837eeab3ca6 | 6 | |
shorie | 0:a837eeab3ca6 | 7 | DigitalOut myled1(LED1); |
shorie | 0:a837eeab3ca6 | 8 | |
shorie | 0:a837eeab3ca6 | 9 | |
shorie | 0:a837eeab3ca6 | 10 | // customer signal processing initialization call back. |
shorie | 0:a837eeab3ca6 | 11 | void init_callback( |
shorie | 0:a837eeab3ca6 | 12 | unsigned int block_size // block size [sample] |
shorie | 0:a837eeab3ca6 | 13 | ) |
shorie | 0:a837eeab3ca6 | 14 | { |
shorie | 0:a837eeab3ca6 | 15 | // place initialization code here |
shorie | 0:a837eeab3ca6 | 16 | } |
shorie | 0:a837eeab3ca6 | 17 | |
shorie | 0:a837eeab3ca6 | 18 | |
shorie | 0:a837eeab3ca6 | 19 | // customer signal processing call back. |
shorie | 0:a837eeab3ca6 | 20 | void process_callback( |
shorie | 0:a837eeab3ca6 | 21 | float rx_left_buffer[], // array of the left input samples |
shorie | 0:a837eeab3ca6 | 22 | float rx_right_buffer[], // array of the right input samples |
shorie | 0:a837eeab3ca6 | 23 | float tx_left_buffer[], // place to write the left output samples |
shorie | 0:a837eeab3ca6 | 24 | float tx_right_buffer[], // place to write the left output samples |
shorie | 0:a837eeab3ca6 | 25 | unsigned int block_size // block size [sample] |
shorie | 0:a837eeab3ca6 | 26 | ) |
shorie | 0:a837eeab3ca6 | 27 | { |
shorie | 0:a837eeab3ca6 | 28 | // Sample processing |
shorie | 0:a837eeab3ca6 | 29 | for ( int i=0; i<block_size; i++) // for all sample |
shorie | 0:a837eeab3ca6 | 30 | { |
shorie | 0:a837eeab3ca6 | 31 | tx_left_buffer[i] = rx_left_buffer[i]; // copy from input to output |
shorie | 0:a837eeab3ca6 | 32 | tx_right_buffer[i] = rx_right_buffer[i]; |
shorie | 0:a837eeab3ca6 | 33 | |
shorie | 0:a837eeab3ca6 | 34 | } |
shorie | 0:a837eeab3ca6 | 35 | } |
shorie | 0:a837eeab3ca6 | 36 | |
shorie | 0:a837eeab3ca6 | 37 | |
shorie | 0:a837eeab3ca6 | 38 | |
shorie | 0:a837eeab3ca6 | 39 | int main() |
shorie | 0:a837eeab3ca6 | 40 | { |
shorie | 0:a837eeab3ca6 | 41 | // I2C is essential to talk with ADAU1361 |
shorie | 0:a837eeab3ca6 | 42 | I2C i2c(D14, D15); |
shorie | 0:a837eeab3ca6 | 43 | |
shorie | 0:a837eeab3ca6 | 44 | // create an audio codec contoler |
shorie | 0:a837eeab3ca6 | 45 | shimabara::UMB_ADAU1361A codec(shimabara::Fs_32, i2c, CODEC_I2C_ADDR ); // Default Fs is 48kHz |
shorie | 0:a837eeab3ca6 | 46 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_441, i2c, CODEC_I2C_ADDR ); |
shorie | 0:a837eeab3ca6 | 47 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR ); |
shorie | 0:a837eeab3ca6 | 48 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_96, i2c, CODEC_I2C_ADDR ); |
shorie | 0:a837eeab3ca6 | 49 | |
shorie | 0:a837eeab3ca6 | 50 | // create an audio framework by singlton pattern |
shorie | 0:a837eeab3ca6 | 51 | unzen::Framework audio; |
shorie | 0:a837eeab3ca6 | 52 | |
shorie | 0:a837eeab3ca6 | 53 | // Set I3C clock to 100kHz |
shorie | 0:a837eeab3ca6 | 54 | i2c.frequency( 100000 ); |
shorie | 0:a837eeab3ca6 | 55 | |
shorie | 0:a837eeab3ca6 | 56 | |
shorie | 0:a837eeab3ca6 | 57 | // Configure the optional block size of signal processing. By default, it is 1[Sample] |
shorie | 0:a837eeab3ca6 | 58 | // audio.set_block_size(16); |
shorie | 0:a837eeab3ca6 | 59 | |
shorie | 0:a837eeab3ca6 | 60 | |
shorie | 0:a837eeab3ca6 | 61 | // Start the ADAU1361. Audio codec starts to generate the I2C signals |
shorie | 0:a837eeab3ca6 | 62 | codec.start(); |
shorie | 0:a837eeab3ca6 | 63 | |
shorie | 0:a837eeab3ca6 | 64 | // Start the audio framework on ARM processor. |
shorie | 0:a837eeab3ca6 | 65 | audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework |
shorie | 0:a837eeab3ca6 | 66 | |
shorie | 0:a837eeab3ca6 | 67 | |
shorie | 0:a837eeab3ca6 | 68 | // periodically changing gain for test |
shorie | 0:a837eeab3ca6 | 69 | while(1) |
shorie | 0:a837eeab3ca6 | 70 | { |
shorie | 0:a837eeab3ca6 | 71 | for ( int i=-15; i<4; i++ ) |
shorie | 0:a837eeab3ca6 | 72 | { |
shorie | 0:a837eeab3ca6 | 73 | codec.set_hp_output_gain( i, i ); |
shorie | 0:a837eeab3ca6 | 74 | codec.set_line_output_gain( i, i ); |
shorie | 0:a837eeab3ca6 | 75 | myled1 = 1; |
shorie | 0:a837eeab3ca6 | 76 | wait(0.2); |
shorie | 0:a837eeab3ca6 | 77 | myled1 = 0; |
shorie | 0:a837eeab3ca6 | 78 | wait(0.2); |
shorie | 0:a837eeab3ca6 | 79 | } |
shorie | 0:a837eeab3ca6 | 80 | } |
shorie | 0:a837eeab3ca6 | 81 | } |