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@6:486b1cb03e61, 2017-01-27 (annotated)
- Committer:
- shorie
- Date:
- Fri Jan 27 01:53:43 2017 +0000
- Revision:
- 6:486b1cb03e61
- Parent:
- 3:1b420050bdda
- Child:
- 7:e86c645231ff
Skeleton build successful. Need to test.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 1:98ddcbbe10ba | 1 | #include "mbed.h" |
shorie | 1:98ddcbbe10ba | 2 | |
shorie | 6:486b1cb03e61 | 3 | // Note : Do not touch the "unzen dependent" part. |
shorie | 6:486b1cb03e61 | 4 | // Configure the "project dependent" part. |
shorie | 6:486b1cb03e61 | 5 | |
shorie | 6:486b1cb03e61 | 6 | |
shorie | 6:486b1cb03e61 | 7 | /************************** unzen dependent constants. ************************/ |
shorie | 6:486b1cb03e61 | 8 | #define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A |
shorie | 6:486b1cb03e61 | 9 | |
shorie | 6:486b1cb03e61 | 10 | |
shorie | 6:486b1cb03e61 | 11 | /*========================= Project Dependent Constants ======================*/ |
shorie | 6:486b1cb03e61 | 12 | #define BLOCKSIZE 16 // number of the sample to be processed at once. |
shorie | 6:486b1cb03e61 | 13 | #define FS shimabara::Fs_48 // Fs can be Fs_32, Fs_441, Fs_48, Fs_96 |
shorie | 6:486b1cb03e61 | 14 | |
shorie | 6:486b1cb03e61 | 15 | |
shorie | 6:486b1cb03e61 | 16 | /************************** unzen dependent include. **************************/ |
shorie | 0:a837eeab3ca6 | 17 | #include "unzen.h" // audio framework include file |
shorie | 1:98ddcbbe10ba | 18 | #include "umb_adau1361a.h" // audio codec contoler include file |
shorie | 3:1b420050bdda | 19 | #include "amakusa.h" // audio signal processing class library. |
shorie | 3:1b420050bdda | 20 | #include "ukifune.h" // UI board support routines |
shorie | 3:1b420050bdda | 21 | |
shorie | 6:486b1cb03e61 | 22 | |
shorie | 6:486b1cb03e61 | 23 | /*========================= project dependent include. =======================*/ |
shorie | 6:486b1cb03e61 | 24 | #include "signal_processing.h" |
shorie | 2:d5028a37f17b | 25 | |
shorie | 3:1b420050bdda | 26 | |
shorie | 6:486b1cb03e61 | 27 | /************************* Unzen Dependent Global Variables *******************/ |
shorie | 6:486b1cb03e61 | 28 | // I2C is essential to talk with ADAU1361 |
shorie | 6:486b1cb03e61 | 29 | I2C i2c(D14, D15); |
shorie | 6:486b1cb03e61 | 30 | // create an audio codec contoler |
shorie | 6:486b1cb03e61 | 31 | shimabara::UMB_ADAU1361A codec(FS, i2c, CODEC_I2C_ADDR ); |
shorie | 6:486b1cb03e61 | 32 | // create an audio framework by singlton pattern |
shorie | 6:486b1cb03e61 | 33 | unzen::Framework audio; |
shorie | 6:486b1cb03e61 | 34 | |
shorie | 6:486b1cb03e61 | 35 | |
shorie | 6:486b1cb03e61 | 36 | /*========================= project dependent Global Variable. ===============*/ |
shorie | 6:486b1cb03e61 | 37 | // create a pointer to the signal processing object. |
shorie | 6:486b1cb03e61 | 38 | SignalProcessing * process; |
shorie | 6:486b1cb03e61 | 39 | |
shorie | 6:486b1cb03e61 | 40 | |
shorie | 6:486b1cb03e61 | 41 | |
shorie | 6:486b1cb03e61 | 42 | /************************* Unzen Dependent Function Prototype *****************/ |
shorie | 6:486b1cb03e61 | 43 | // for system usage. Do not care. |
shorie | 6:486b1cb03e61 | 44 | void initialize_system(void); |
shorie | 0:a837eeab3ca6 | 45 | |
shorie | 2:d5028a37f17b | 46 | |
shorie | 6:486b1cb03e61 | 47 | /*========================= project dependent Signal Processing. ============*/ |
shorie | 0:a837eeab3ca6 | 48 | // customer signal processing initialization call back. |
shorie | 0:a837eeab3ca6 | 49 | void init_callback( |
shorie | 0:a837eeab3ca6 | 50 | unsigned int block_size // block size [sample] |
shorie | 0:a837eeab3ca6 | 51 | ) |
shorie | 0:a837eeab3ca6 | 52 | { |
shorie | 0:a837eeab3ca6 | 53 | // place initialization code here |
shorie | 6:486b1cb03e61 | 54 | process = new SignalProcessing( block_size ); |
shorie | 0:a837eeab3ca6 | 55 | } |
shorie | 0:a837eeab3ca6 | 56 | |
shorie | 0:a837eeab3ca6 | 57 | // customer signal processing call back. |
shorie | 0:a837eeab3ca6 | 58 | void process_callback( |
shorie | 0:a837eeab3ca6 | 59 | float rx_left_buffer[], // array of the left input samples |
shorie | 0:a837eeab3ca6 | 60 | float rx_right_buffer[], // array of the right input samples |
shorie | 0:a837eeab3ca6 | 61 | float tx_left_buffer[], // place to write the left output samples |
shorie | 0:a837eeab3ca6 | 62 | float tx_right_buffer[], // place to write the left output samples |
shorie | 0:a837eeab3ca6 | 63 | unsigned int block_size // block size [sample] |
shorie | 0:a837eeab3ca6 | 64 | ) |
shorie | 0:a837eeab3ca6 | 65 | { |
shorie | 6:486b1cb03e61 | 66 | // place signal processing code here |
shorie | 6:486b1cb03e61 | 67 | process->run( rx_left_buffer, rx_right_buffer, tx_left_buffer, tx_right_buffer, block_size ); |
shorie | 0:a837eeab3ca6 | 68 | } |
shorie | 0:a837eeab3ca6 | 69 | |
shorie | 6:486b1cb03e61 | 70 | |
shorie | 0:a837eeab3ca6 | 71 | |
shorie | 0:a837eeab3ca6 | 72 | int main() |
shorie | 0:a837eeab3ca6 | 73 | { |
shorie | 6:486b1cb03e61 | 74 | // start audio. Do not touch |
shorie | 6:486b1cb03e61 | 75 | initialize_system(); |
shorie | 0:a837eeab3ca6 | 76 | |
shorie | 6:486b1cb03e61 | 77 | // main loop. Signal processing is done in background. |
shorie | 6:486b1cb03e61 | 78 | while(1) |
shorie | 6:486b1cb03e61 | 79 | { // place your foreground program here. |
shorie | 6:486b1cb03e61 | 80 | process->set_volume( ukifune::get_volume(0) ); |
shorie | 2:d5028a37f17b | 81 | |
shorie | 6:486b1cb03e61 | 82 | // you have to call tick() every 20mS-50mS if you need get_volume() |
shorie | 6:486b1cb03e61 | 83 | wait(0.05); |
shorie | 6:486b1cb03e61 | 84 | ukifune::tick(); |
shorie | 6:486b1cb03e61 | 85 | } |
shorie | 2:d5028a37f17b | 86 | } |
shorie | 2:d5028a37f17b | 87 | |
shorie | 6:486b1cb03e61 | 88 | |
shorie | 6:486b1cb03e61 | 89 | /************************* Unzen Dependent Function implementation ************/ |
shorie | 6:486b1cb03e61 | 90 | void initialize_system(void) |
shorie | 2:d5028a37f17b | 91 | { |
shorie | 6:486b1cb03e61 | 92 | // Set I3C clock to 100kHz |
shorie | 6:486b1cb03e61 | 93 | i2c.frequency( 100000 ); |
shorie | 6:486b1cb03e61 | 94 | |
shorie | 6:486b1cb03e61 | 95 | // Configure the optional block size of signal processing. By default, it is 1[Sample] |
shorie | 6:486b1cb03e61 | 96 | audio.set_block_size(BLOCKSIZE); |
shorie | 6:486b1cb03e61 | 97 | |
shorie | 6:486b1cb03e61 | 98 | // Start UI module. |
shorie | 6:486b1cb03e61 | 99 | ukifune::init( & audio ); |
shorie | 6:486b1cb03e61 | 100 | |
shorie | 6:486b1cb03e61 | 101 | // Start the ADAU1361. Audio codec starts to generate the I2C signals |
shorie | 6:486b1cb03e61 | 102 | codec.start(); |
shorie | 6:486b1cb03e61 | 103 | // Start the audio framework on ARM processor. |
shorie | 6:486b1cb03e61 | 104 | audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework |
shorie | 6:486b1cb03e61 | 105 | |
shorie | 6:486b1cb03e61 | 106 | // Setup initial analog gain |
shorie | 6:486b1cb03e61 | 107 | codec.set_hp_output_gain( 0, 0 ); |
shorie | 6:486b1cb03e61 | 108 | codec.set_line_output_gain( 0, 0 ); |
shorie | 6:486b1cb03e61 | 109 | } |