First Publish. Works fine.
Dependents: unzen_sample_LPC4088_quickstart
Framework Class Reference
adio frame work. More...
#include <unzen.h>
Public Member Functions | |
Framework (void) | |
| |
error_type | set_block_size (unsigned int new_block_size) |
set the interval interrupt count for each time call back is called. | |
void | start (void(*init_cb)(unsigned int), void(*process_cb)(float[], float[], float[], float[], unsigned int)) |
the real audio signal transfer. | |
void | set_post_interrupt_callback (void(*cb)(void)) |
Debug hook for interrupt handler. | |
void | set_pre_process_callback (void(*cb)(void)) |
Debug hook for processing handler. | |
void | set_post_process_callback (void(*cb)(void)) |
Debug hook for processing handler. | |
void | set_i2s_irq_priority (unsigned int pri) |
optional priority control for I2S IRQ. | |
void | set_process_irq_priority (unsigned int pri) |
optional priority control for Signal Processing IRQ. |
Detailed Description
adio frame work.
Create a object and execute the Framework::start() method.
example :
#include "unzen.h" // audio framework include file #include "umb_adau1361a.h" // audio codec contoler include file #include "mbed.h" #define CODEC_I2C_ADDR 0x38 DigitalOut myled1(LED1); // customer signal processing initialization call back. void init_callback( unsigned int block_size // block size [sample] ) { // place initialization code here } // customer signal processing call back. void process_callback( float rx_left_buffer[], // array of the left input samples float rx_right_buffer[], // array of the right input samples float tx_left_buffer[], // place to write the left output samples float tx_right_buffer[], // place to write the left output samples unsigned int block_size // block size [sample] ) { // Sample processing for ( int i=0; i<block_size; i++) // for all sample { tx_left_buffer[i] = rx_left_buffer[i]; // copy from input to output tx_right_buffer[i] = rx_right_buffer[i]; } } int main() { // I2C is essential to talk with ADAU1361 I2C i2c(SDA, SCL); // create an audio codec contoler shimabara::UMB_ADAU1361A codec(shimabara::Fs_32, i2c, CODEC_I2C_ADDR ); // Default Fs is 48kHz // shimabara::UMB_ADAU1361A codec(shimabara::Fs_441, i2c, CODEC_I2C_ADDR ); // shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR ); // shimabara::UMB_ADAU1361A codec(shimabara::Fs_96, i2c, CODEC_I2C_ADDR ); // create an audio framework by singlton pattern unzen::Framework audio; // Set I3C clock to 100kHz i2c.frequency( 100000 ); // Configure the optional block size of signal processing. By default, it is 1[Sample] // audio.set_block_size(16); // Start the ADAU1361. Audio codec starts to generate the I2C signals codec.start(); // Start the audio framework on ARM processor. audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework // periodically changing gain for test while(1) { for ( int i=-15; i<4; i++ ) { codec.set_hp_output_gain( i, i ); codec.set_line_output_gain( i, i ); myled1 = 1; wait(0.2); myled1 = 0; wait(0.2); } } }
Definition at line 114 of file unzen.h.
Constructor & Destructor Documentation
Framework | ( | void | ) |
initialize the internal variables and set up all interrrupt / I2S related peripheral. If needed, power up the peripheral, assign the clock and pins. At the end of this constructor, the audio framework is ready to run, but still paused. To start the real processing, call the start method.
Note that this constructor set the block size ( interval count which audio processing call back is called ) as 1. If it is needed to use other value, call set_brock_size() method.
Member Function Documentation
error_type set_block_size | ( | unsigned int | new_block_size ) |
set the interval interrupt count for each time call back is called.
- Parameters:
-
block_size An integer parameter > 1. If set to n, for each n interrupts, the audio call back is called.
- Returns:
- show the error status
This method re-allocate the internal buffer. Then, the memory allocation error could occur. To detect the memory allocation error, use get_error() method.
void set_i2s_irq_priority | ( | unsigned int | pri ) |
optional priority control for I2S IRQ.
- Parameters:
-
pri Priority of IRQ.
This is optional control. Usually, user doesn't need to call this method. In case the framework has serious irq priority contention with other software, this API help programmer to change the priority of the Unzen framework.
Value must be acceptable to CMSIS NVIC_SetPriority(). For LPC4337, it is range of 0..7. The 0 is highest priority.
By default, the framework set this priority as +2 higher than the lowest.
The priority set by this API must be higher than priority set by set_process_irq_priority
void set_post_interrupt_callback | ( | void(*)(void) | cb ) |
Debug hook for interrupt handler.
- Parameters:
-
cb A call back which is called at the end of I2S interrupt.
Parameter cb is call at the end of the I2S interrupt. This call back can be used to mesure the timing of interrupt by toggling the GPIO pin.
Passing 0 to cb parameter let the framwork ignore the callback.
void set_post_process_callback | ( | void(*)(void) | cb ) |
Debug hook for processing handler.
- Parameters:
-
cb A call back which is called at the end of processing.
Parameter cb is call at the end of the signal processing. This call back can be used to mesure the load of CPU by toggling the GPIO pin.
Passing 0 to cb parameter let the framwork ignore the callback.
void set_pre_process_callback | ( | void(*)(void) | cb ) |
Debug hook for processing handler.
- Parameters:
-
cb A call back which is called at the beggining of processing.
Parameter cb is call at the beggining of the signal processing. This call back can be used to mesure the load of CPU by toggling the GPIO pin.
Passing 0 to cb parameter let the framwork ignore the callback.
void set_process_irq_priority | ( | unsigned int | pri ) |
optional priority control for Signal Processing IRQ.
- Parameters:
-
pri Priority of IRQ.
This is optional control. Usually, user doesn't need to call this method. In case the framework has serious irq priority contention with other software, this API help programmer to change the priority of the Unzen framework
Value must be acceptable to CMSIS NVIC_SetPriority(). For LPC4337, it is range of 0..7. The 0 is highest priority.
By default, the framework set this priority as +2 higher than the lowest.
void start | ( | void(*)(unsigned int) | init_cb, |
void(*)(float[], float[], float[], float[], unsigned int) | process_cb | ||
) |
the real audio signal transfer.
Trigger the I2S interrupt and call the call back.
- Parameters:
-
init_cb initializer call back for signal processing. This is invoked only once before processing. Can be NUL process_cb The call back function
Set the call back function, then start the transer on I2S
Before the real data transaction on I2S, this method call init_cb(int) call back. The parameter is block size (>0) which is set by set_block_size() method. If the init_cb is NUL, this part is skipped.
This process_cb function is called for each time the rx buffer is filled. The call back has 5 parameters.
- left_rx Received data from I2S rx port. Left data only.
- right_rx Received data from I2S rx port. Right data only.
- left_tx Buffer to fill the transmission data. This buffer mus be filled by call back. Left data only
- right_tx Buffer to fill the transmission data. This buffer mus be filled by call back. Right data only
- length length of above buffers.
The process call back is called for each time interrupt comes n times. Where n is the value which is specified by set_block_size() function. This n is also passed to call back as above length parameter. By default, n is 1.
Note that the call back is called at interrupt context. Not the thread level context. That mean, it is better to avoid to call mbed API except the mbed-RTOS API for interrupt handler.
Generated on Wed Jul 13 2022 06:48:06 by 1.7.2