24bit 48kHz Audio Delay
Dependencies: mbed-dsp mbed shimabara unzen_nucleo_f746
Fork of unzen_sample_nucleo_f746 by
雲仙フレームワークを使ったオーディオディレイのsampleです。
main.cpp@1:5b735bc30c17, 2016-12-12 (annotated)
- Committer:
- GSMCustomEffects
- Date:
- Mon Dec 12 09:26:41 2016 +0000
- Revision:
- 1:5b735bc30c17
- Parent:
- 0:a837eeab3ca6
- Child:
- 3:d9fd88ea0ff5
add
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" |
GSMCustomEffects | 1:5b735bc30c17 | 4 | #include "arm_math.h" |
shorie | 0:a837eeab3ca6 | 5 | #define CODEC_I2C_ADDR 0x38 |
shorie | 0:a837eeab3ca6 | 6 | |
shorie | 0:a837eeab3ca6 | 7 | DigitalOut myled1(LED1); |
GSMCustomEffects | 1:5b735bc30c17 | 8 | DigitalIn User_b1(PC_13); |
GSMCustomEffects | 1:5b735bc30c17 | 9 | Serial uart(SERIAL_TX,SERIAL_RX); |
GSMCustomEffects | 1:5b735bc30c17 | 10 | float32_t delay_buf[1]; |
GSMCustomEffects | 1:5b735bc30c17 | 11 | float32_t delay_buf1[1]; |
GSMCustomEffects | 1:5b735bc30c17 | 12 | float32_t delay_buf2[1]; |
GSMCustomEffects | 1:5b735bc30c17 | 13 | int flag = 1; |
GSMCustomEffects | 1:5b735bc30c17 | 14 | char uart_read_value = 0; |
shorie | 0:a837eeab3ca6 | 15 | // customer signal processing initialization call back. |
shorie | 0:a837eeab3ca6 | 16 | void init_callback( |
shorie | 0:a837eeab3ca6 | 17 | unsigned int block_size // block size [sample] |
shorie | 0:a837eeab3ca6 | 18 | ) |
shorie | 0:a837eeab3ca6 | 19 | { |
shorie | 0:a837eeab3ca6 | 20 | // place initialization code here |
shorie | 0:a837eeab3ca6 | 21 | } |
shorie | 0:a837eeab3ca6 | 22 | |
shorie | 0:a837eeab3ca6 | 23 | |
shorie | 0:a837eeab3ca6 | 24 | // customer signal processing call back. |
shorie | 0:a837eeab3ca6 | 25 | void process_callback( |
shorie | 0:a837eeab3ca6 | 26 | float rx_left_buffer[], // array of the left input samples |
shorie | 0:a837eeab3ca6 | 27 | float rx_right_buffer[], // array of the right input samples |
shorie | 0:a837eeab3ca6 | 28 | float tx_left_buffer[], // place to write the left output samples |
shorie | 0:a837eeab3ca6 | 29 | float tx_right_buffer[], // place to write the left output samples |
shorie | 0:a837eeab3ca6 | 30 | unsigned int block_size // block size [sample] |
shorie | 0:a837eeab3ca6 | 31 | ) |
shorie | 0:a837eeab3ca6 | 32 | { |
GSMCustomEffects | 1:5b735bc30c17 | 33 | |
GSMCustomEffects | 1:5b735bc30c17 | 34 | if(flag == 1){ |
shorie | 0:a837eeab3ca6 | 35 | // Sample processing |
GSMCustomEffects | 1:5b735bc30c17 | 36 | for ( int i=0; i<block_size; i++) // for all sample |
GSMCustomEffects | 1:5b735bc30c17 | 37 | { |
GSMCustomEffects | 1:5b735bc30c17 | 38 | tx_left_buffer[i] = rx_left_buffer[i]; // copy from input to output |
GSMCustomEffects | 1:5b735bc30c17 | 39 | tx_right_buffer[i] = rx_right_buffer[i]; |
GSMCustomEffects | 1:5b735bc30c17 | 40 | |
GSMCustomEffects | 1:5b735bc30c17 | 41 | } |
GSMCustomEffects | 1:5b735bc30c17 | 42 | } |
GSMCustomEffects | 1:5b735bc30c17 | 43 | else if(flag == 0){ |
GSMCustomEffects | 1:5b735bc30c17 | 44 | for ( int i=0; i<block_size; i++) // for all sample |
GSMCustomEffects | 1:5b735bc30c17 | 45 | { |
GSMCustomEffects | 1:5b735bc30c17 | 46 | tx_left_buffer[i] = 0; // copy from input to output |
GSMCustomEffects | 1:5b735bc30c17 | 47 | tx_right_buffer[i] = 0; |
GSMCustomEffects | 1:5b735bc30c17 | 48 | |
GSMCustomEffects | 1:5b735bc30c17 | 49 | } |
shorie | 0:a837eeab3ca6 | 50 | } |
shorie | 0:a837eeab3ca6 | 51 | } |
shorie | 0:a837eeab3ca6 | 52 | |
shorie | 0:a837eeab3ca6 | 53 | |
shorie | 0:a837eeab3ca6 | 54 | |
shorie | 0:a837eeab3ca6 | 55 | int main() |
shorie | 0:a837eeab3ca6 | 56 | { |
shorie | 0:a837eeab3ca6 | 57 | // I2C is essential to talk with ADAU1361 |
shorie | 0:a837eeab3ca6 | 58 | I2C i2c(D14, D15); |
GSMCustomEffects | 1:5b735bc30c17 | 59 | |
GSMCustomEffects | 1:5b735bc30c17 | 60 | |
shorie | 0:a837eeab3ca6 | 61 | // create an audio codec contoler |
GSMCustomEffects | 1:5b735bc30c17 | 62 | //shimabara::UMB_ADAU1361A codec(shimabara::Fs_32, i2c, CODEC_I2C_ADDR ); // Default Fs is 48kHz |
GSMCustomEffects | 1:5b735bc30c17 | 63 | shimabara::UMB_ADAU1361A codec(shimabara::Fs_441, i2c, CODEC_I2C_ADDR ); |
shorie | 0:a837eeab3ca6 | 64 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR ); |
shorie | 0:a837eeab3ca6 | 65 | // shimabara::UMB_ADAU1361A codec(shimabara::Fs_96, i2c, CODEC_I2C_ADDR ); |
shorie | 0:a837eeab3ca6 | 66 | |
shorie | 0:a837eeab3ca6 | 67 | // create an audio framework by singlton pattern |
shorie | 0:a837eeab3ca6 | 68 | unzen::Framework audio; |
shorie | 0:a837eeab3ca6 | 69 | |
shorie | 0:a837eeab3ca6 | 70 | // Set I3C clock to 100kHz |
shorie | 0:a837eeab3ca6 | 71 | i2c.frequency( 100000 ); |
shorie | 0:a837eeab3ca6 | 72 | |
shorie | 0:a837eeab3ca6 | 73 | |
shorie | 0:a837eeab3ca6 | 74 | // Configure the optional block size of signal processing. By default, it is 1[Sample] |
GSMCustomEffects | 1:5b735bc30c17 | 75 | audio.set_block_size(16); |
shorie | 0:a837eeab3ca6 | 76 | |
shorie | 0:a837eeab3ca6 | 77 | |
shorie | 0:a837eeab3ca6 | 78 | // Start the ADAU1361. Audio codec starts to generate the I2C signals |
shorie | 0:a837eeab3ca6 | 79 | codec.start(); |
shorie | 0:a837eeab3ca6 | 80 | |
shorie | 0:a837eeab3ca6 | 81 | // Start the audio framework on ARM processor. |
shorie | 0:a837eeab3ca6 | 82 | audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework |
shorie | 0:a837eeab3ca6 | 83 | |
shorie | 0:a837eeab3ca6 | 84 | |
shorie | 0:a837eeab3ca6 | 85 | // periodically changing gain for test |
shorie | 0:a837eeab3ca6 | 86 | while(1) |
shorie | 0:a837eeab3ca6 | 87 | { |
GSMCustomEffects | 1:5b735bc30c17 | 88 | |
GSMCustomEffects | 1:5b735bc30c17 | 89 | delay_buf[0] = 1.0; |
GSMCustomEffects | 1:5b735bc30c17 | 90 | codec.set_hp_output_gain( 3, 3); |
GSMCustomEffects | 1:5b735bc30c17 | 91 | codec.set_line_output_gain( 3, 3 ); |
GSMCustomEffects | 1:5b735bc30c17 | 92 | arm_add_f32( delay_buf, delay_buf1, delay_buf2, 1 ); |
GSMCustomEffects | 1:5b735bc30c17 | 93 | if(User_b1 == 1){ |
GSMCustomEffects | 1:5b735bc30c17 | 94 | if(flag == 1){flag = 0;} |
GSMCustomEffects | 1:5b735bc30c17 | 95 | else if(flag == 0){flag = 1;} |
GSMCustomEffects | 1:5b735bc30c17 | 96 | if(flag == 1){myled1 =1;uart.printf("Effect On \r\n");} |
GSMCustomEffects | 1:5b735bc30c17 | 97 | else if(flag == 0){myled1 =0;uart.printf("Effect Off \r\n");} |
GSMCustomEffects | 1:5b735bc30c17 | 98 | while(User_b1==1){} |
GSMCustomEffects | 1:5b735bc30c17 | 99 | } |
GSMCustomEffects | 1:5b735bc30c17 | 100 | if(uart.readable()== 1){uart_read_value = uart.getc(); |
GSMCustomEffects | 1:5b735bc30c17 | 101 | if(uart_read_value == 'e'){flag = 1;uart.printf("Effect On \r\n");} |
GSMCustomEffects | 1:5b735bc30c17 | 102 | if(uart_read_value == 'd'){flag = 0;uart.printf("Effect Off \r\n");} |
GSMCustomEffects | 1:5b735bc30c17 | 103 | } |
shorie | 0:a837eeab3ca6 | 104 | } |
shorie | 0:a837eeab3ca6 | 105 | } |