diff --git a/module_usb_audio/audio.h b/module_usb_audio/audio.h index 662a9af3..d8c56ac1 100644 --- a/module_usb_audio/audio.h +++ b/module_usb_audio/audio.h @@ -27,7 +27,7 @@ void audio(chanend c_in, , server interface i_dfu dfuInterface #endif #ifdef PDM_PCM_IN -, streaming chanend c_pdm_in + , chanend c_pdm_in #endif ); diff --git a/module_usb_audio/audio.xc b/module_usb_audio/audio.xc index 4f470862..31f43714 100755 --- a/module_usb_audio/audio.xc +++ b/module_usb_audio/audio.xc @@ -224,7 +224,7 @@ static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samp #pragma unsafe arrays -static inline unsigned DoSampleTransfer(chanend c_out, int readBuffNo, unsigned underflowWord) +static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, const unsigned underflowWord) { outuint(c_out, underflowWord); @@ -262,7 +262,6 @@ static inline unsigned DoSampleTransfer(chanend c_out, int readBuffNo, unsigned { int tmp = inuint(c_out); samplesOut[i] = tmp; - samplesOut[i] = samplesIn_0[0]; } #else inuint(c_out); @@ -435,7 +434,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, chanend c_dig_rx, #endif #ifdef PDM_PCM_IN - streaming chanend c_pdm_pcm, + chanend c_pdm_pcm, #endif chanend ?c_adc) @@ -689,7 +688,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if defined(SPDIF_RX) || defined(ADAT_RX) - /* Request digital data (with prefill) */ + /* Request digital data (with prefill) */ outuint(c_dig_rx, 0); #endif #if defined(SPDIF_TX) && (NUM_USB_CHAN_OUT > 0) @@ -699,15 +698,14 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #ifdef PDM_PCM_IN - c_pdm_pcm <: 1; - c_pdm_pcm :> samplesIn_0[0]; - c_pdm_pcm :> samplesIn_0[1]; - c_pdm_pcm :> samplesIn_0[2]; - c_pdm_pcm :> samplesIn_0[3]; - c_pdm_pcm :> samplesIn_0[4]; - c_pdm_pcm :> samplesIn_0[5]; - c_pdm_pcm :> samplesIn_0[6]; - c_pdm_pcm :> samplesIn_0[7]; + /* Request samples from PDM->PCM comverter */ + //c_pdm_pcm <: 1; + +#pragma loop unroll + for(int i = 0; i < 2 /*NUM_PDM_MICS*/; i++) + { + c_pdm_pcm :> samplesIn_0[i]; + } #endif } @@ -942,7 +940,7 @@ chanend ?c_config, chanend ?c , server interface i_dfu dfuInterface #endif #ifdef PDM_PCM_IN -, streaming chanend c_pdm_in +, chanend c_pdm_in #endif ) { diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index cdfaa48d..ad33f4cd 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -45,6 +45,13 @@ #define SPDIF_TX_TILE AUDIO_IO_TILE #endif +/** + * @brief Location (tile) of PDM Rx. Default: AUDIO_IO_TILE + */ +#ifndef PDM_TILE +#define PDM_TILE AUDIO_IO_TILE +#endif + /** * @brief Number of input channels (device to host). Default: NONE (Must be defined by app) */ @@ -201,11 +208,18 @@ /* Feature defines */ +/** + * @brief Number of PDM microphones in the design. Default: None + */ +#ifndef NUM_PDM_MICS +#define NUM_PDM_MICS (0) +#endif + /** * @brief Enable MIDI functionality including buffering, descriptors etc. Default: DISABLED */ #ifndef MIDI -#define MIDI (0) +#define MIDI (0) #endif #if defined(MIDI) && (MIDI == 0) @@ -1088,6 +1102,8 @@ #endif #endif + + /* Endpoint addresses enums */ enum USBEndpointNumber_In { diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 9eb586b2..c14c6c61 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -44,7 +44,7 @@ #include "clocking.h" #ifdef PDM_PCM_IN -void pcm_pdm_mic(streaming chanend c_pcm_out); +void pcm_pdm_mic(chanend c_pcm_out); #endif void genclock(); @@ -414,7 +414,7 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc, , server interface i_dfu dfuInterface #endif #ifdef PDM_PCM_IN - , streaming chanend c_pdm_pcm + , chanend c_pdm_pcm #endif ) { @@ -544,7 +544,7 @@ int main() #endif #ifdef PDM_PCM_IN - streaming chan c_pdm_pcm; + chan c_pdm_pcm; #endif USER_MAIN_DECLARATIONS diff --git a/module_usb_audio/pcm_pdm_mic.xc b/module_usb_audio/pdm_mics/pcm_pdm_mic.xc similarity index 57% rename from module_usb_audio/pcm_pdm_mic.xc rename to module_usb_audio/pdm_mics/pcm_pdm_mic.xc index 546a1cd7..89a90e89 100644 --- a/module_usb_audio/pcm_pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pcm_pdm_mic.xc @@ -1,29 +1,35 @@ -#include +/* This file includes an integration of lib_array_mic into USB Audio */ + #include #include #include -#include "beam.h" #include #include #include #include -#include "static_constants.h" -#include "debug_print.h" +//#include "debug_print.h" +#include "devicedefines.h" +#include "mic_array.h" +#include "mic_array_board_support.h" #if 1 -on tile[0]: in port p_pdm_clk = XS1_PORT_1E; -on tile[0]: in buffered port:8 p_pdm_mics = XS1_PORT_8B; -in port p_mclk = on tile[0]: XS1_PORT_1F; -clock mclk = on tile[0]: XS1_CLKBLK_1; -clock pdmclk = on tile[0]: XS1_CLKBLK_3; +in port p_pdm_clk = PORT_PDM_CLK; +in port p_pdm_mics = PORT_PDM_DATA; + +in port p_mclk = PORT_PDM_MCLK; +clock mclk = on tile[PDM_TILE]: XS1_CLKBLK_1; +clock pdmclk = on tile[PDM_TILE]: XS1_CLKBLK_3; + + +on tile[0]:p_leds leds = DEFAULT_INIT; // LEDs -out port p_led0to7 = on tile[0]: XS1_PORT_8C; -out port p_led8 = on tile[0]: XS1_PORT_1K; -out port p_led9 = on tile[0]: XS1_PORT_1L; -out port p_led10to12 = on tile[0]: XS1_PORT_8D; -out port p_leds_oen = on tile[0]: XS1_PORT_1P; +//out port p_led0to7 = on tile[0]: XS1_PORT_8C; +//out port p_led8 = on tile[0]: XS1_PORT_1K; +//out port p_led9 = on tile[0]: XS1_PORT_1L; +//out port p_led10to12 = on tile[0]: XS1_PORT_8D; +//out port p_leds_oen = on tile[0]: XS1_PORT_1P; // Buttons in port p_buttons = on tile[0]: XS1_PORT_4A; @@ -35,6 +41,7 @@ enum buttons BUTTON_D=1<<3 }; +#if 0 void lightLeds(int only_one_mic) { if(only_one_mic) @@ -52,7 +59,9 @@ void lightLeds(int only_one_mic) p_led9 <: 0; } } +#endif +#if 0 #define BUTTON_PRESSED(but_mask, old_val, new_val) (((old_val) & (but_mask)) == (but_mask) && ((new_val) & (but_mask)) == 0) #define BUTTON_DEBOUNCE_DELAY (20000000) #define LED_ON 0xFFFF @@ -160,16 +169,7 @@ void buttons_and_leds(chanend c) } } } - - -typedef struct { - unsigned ch_a; - unsigned ch_b; -} double_packed_audio; - -typedef struct { - double_packed_audio data[4][1< 0){ + delay--; + printf("n: %d\n", delay); + } + break; + } + case 3:{ + dir++; + if(dir == 6) + dir = 0; + break; + } + } + set_dir(lb, dir); + } + break; + } + default:break; + } +#if 1 + int output = - 2*delay_buffer[(delay_head-delay)%MAX_DELAY][0]; + switch(dir){ + case 0: + output = delay_buffer[delay_head][1] + delay_buffer[(delay_head-2*delay)%MAX_DELAY][4]; + break; + case 1: + output = delay_buffer[delay_head][2] + delay_buffer[(delay_head-2*delay)%MAX_DELAY][5]; + break; + case 2: + output = delay_buffer[delay_head][3] + delay_buffer[(delay_head-2*delay)%MAX_DELAY][6]; + break; + case 3: + output = delay_buffer[delay_head][4] + delay_buffer[(delay_head-2*delay)%MAX_DELAY][1]; + break; + case 4: + output = delay_buffer[delay_head][5] + delay_buffer[(delay_head-2*delay)%MAX_DELAY][2]; + break; + case 5: + output = delay_buffer[delay_head][6] + delay_buffer[(delay_head-2*delay)%MAX_DELAY][3]; + break; + } + c_audio <: output<<2; + c_audio <: output<<2; +#else + int output = 0; + for(unsigned i=1;i<6;i++){ + output += audio[buffer].data[i][0]; + } + c_audio <: output; + c_audio <: output; +#endif + delay_head++; + delay_head%=MAX_DELAY; + } + } +} + + + +void pcm_pdm_mic(chanend c_pcm_out) { streaming chan c_multi_channel_pdm, c_sync, c_4x_pdm_mic_0, c_4x_pdm_mic_1; streaming chan c_ds_output_0, c_ds_output_1; streaming chan c_buffer_mic0, c_buffer_mic1; - unsigned long long shared_memory[2] = {0}; - + + interface led_button_if lb; + configure_clock_src(mclk, p_mclk); configure_clock_src_divide(pdmclk, p_mclk, 2); configure_port_clock_output(p_pdm_clk, pdmclk); @@ -302,27 +462,17 @@ void pcm_pdm_mic(streaming chanend c_pcm_out) start_clock(mclk); start_clock(pdmclk); - chan c; - par { - buttons_and_leds(c); - - unsafe + decimator_config dc = {0, 1, 0, 0}; + + unsafe + { + par { - unsigned long long * unsafe p_shared_memory = shared_memory; - par - { - - //Input stage - pdm_first_stage(p_pdm_mics, p_shared_memory, - PDM_BUFFER_LENGTH_LOG2, c_sync, - c_4x_pdm_mic_0, c_4x_pdm_mic_1); - - pdm_to_pcm_4x(c_4x_pdm_mic_0, c_ds_output_0); - pdm_to_pcm_4x(c_4x_pdm_mic_1, c_ds_output_1); - - example(c_ds_output_0, c_ds_output_1, c_pcm_out, c); - - } + button_and_led_server(lb, leds, p_buttons); + pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1); + decimate_to_pcm_4ch_48KHz(c_4x_pdm_mic_0, c_ds_output_0, dc); + decimate_to_pcm_4ch_48KHz(c_4x_pdm_mic_1, c_ds_output_1, dc); + lores_DAS_fixed(c_ds_output_0, c_ds_output_1, lb, c_pcm_out); } }