diff --git a/demo/audio_v1_mic_multichan_template.c b/demo/audio_v1_mic_multichan_template.c index 9e4e85dd..94ca950c 100644 --- a/demo/audio_v1_mic_multichan_template.c +++ b/demo/audio_v1_mic_multichan_template.c @@ -220,6 +220,7 @@ const uint8_t audio_v1_descriptor[] = { volatile bool tx_flag = 0; volatile bool ep_tx_busy_flag = false; +volatile uint32_t s_mic_sample_rate; static void usbd_event_handler(uint8_t busid, uint8_t event) { @@ -260,6 +261,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf) tx_flag = 0; } +void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq) +{ + if (ep == AUDIO_IN_EP) { + s_mic_sample_rate = sampling_freq; + } +} + +uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep) +{ + (void)busid; + + uint32_t freq = 0; + + if (ep == AUDIO_IN_EP) { + freq = s_mic_sample_rate; + } + + return freq; +} + void usbd_audio_iso_callback(uint8_t busid, uint8_t ep, uint32_t nbytes) { USB_LOG_RAW("actual in len:%d\r\n", (unsigned int)nbytes); diff --git a/demo/audio_v1_mic_speaker_multichan_template.c b/demo/audio_v1_mic_speaker_multichan_template.c index 547641ab..c764ee93 100644 --- a/demo/audio_v1_mic_speaker_multichan_template.c +++ b/demo/audio_v1_mic_speaker_multichan_template.c @@ -258,6 +258,8 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t s_speaker_feedback_buffer[4]; volatile bool tx_flag = 0; volatile bool rx_flag = 0; volatile bool ep_tx_busy_flag = false; +volatile uint32_t s_mic_sample_rate; +volatile uint32_t s_speaker_sample_rate; static void usbd_event_handler(uint8_t busid, uint8_t event) { @@ -291,7 +293,7 @@ void usbd_audio_open(uint8_t busid, uint8_t intf) /* setup first out ep read transfer */ usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET); #if USING_FEEDBACK == 1 - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_SPEAKER_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value); /* uac1 can only use 10.14 */ usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE); #endif @@ -315,6 +317,30 @@ void usbd_audio_close(uint8_t busid, uint8_t intf) } } +void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq) +{ + if (ep == AUDIO_OUT_EP) { + s_speaker_sample_rate = sampling_freq; + } else if (ep == AUDIO_IN_EP) { + s_mic_sample_rate = sampling_freq; + } +} + +uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep) +{ + (void)busid; + + uint32_t freq = 0; + + if (ep == AUDIO_OUT_EP) { + freq = s_speaker_sample_rate; + } else if (ep == AUDIO_IN_EP) { + freq = s_mic_sample_rate; + } + + return freq; +} + void usbd_audio_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes) { USB_LOG_RAW("actual out len:%d\r\n", (unsigned int)nbytes); @@ -331,7 +357,7 @@ void usbd_audio_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes) void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nbytes) { USB_LOG_RAW("actual feedback len:%d\r\n", (unsigned int)nbytes); - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_SPEAKER_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value); usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE); } diff --git a/demo/audio_v2_mic_multichan_template.c b/demo/audio_v2_mic_multichan_template.c index 8c25f25b..cd6e9b15 100644 --- a/demo/audio_v2_mic_multichan_template.c +++ b/demo/audio_v2_mic_multichan_template.c @@ -235,6 +235,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET]; volatile bool tx_flag = 0; volatile bool ep_tx_busy_flag = false; +volatile uint32_t s_mic_sample_rate; static void usbd_event_handler(uint8_t busid, uint8_t event) { @@ -273,6 +274,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf) tx_flag = 0; } +void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq) +{ + if (ep == AUDIO_IN_EP) { + s_mic_sample_rate = sampling_freq; + } +} + +uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep) +{ + (void)busid; + + uint32_t freq = 0; + + if (ep == AUDIO_IN_EP) { + freq = s_mic_sample_rate; + } + + return freq; +} + void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table) { if (ep == AUDIO_IN_EP) { diff --git a/demo/audio_v2_mic_speaker_multichan_template.c b/demo/audio_v2_mic_speaker_multichan_template.c index d96916c5..ce77c302 100644 --- a/demo/audio_v2_mic_speaker_multichan_template.c +++ b/demo/audio_v2_mic_speaker_multichan_template.c @@ -342,6 +342,8 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET]; volatile bool tx_flag = 0; volatile bool rx_flag = 0; volatile bool ep_tx_busy_flag = false; +volatile uint32_t s_mic_sample_rate; +volatile uint32_t s_speaker_sample_rate; static void usbd_event_handler(uint8_t busid, uint8_t event) { @@ -402,6 +404,30 @@ void usbd_audio_close(uint8_t busid, uint8_t intf) } } +void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq) +{ + if (ep == AUDIO_OUT_EP) { + s_speaker_sample_rate = sampling_freq; + } else if (ep == AUDIO_IN_EP) { + s_mic_sample_rate = sampling_freq; + } +} + +uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep) +{ + (void)busid; + + uint32_t freq = 0; + + if (ep == AUDIO_OUT_EP) { + freq = s_speaker_sample_rate; + } else if (ep == AUDIO_IN_EP) { + freq = s_mic_sample_rate; + } + + return freq; +} + void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table) { if (ep == AUDIO_OUT_EP) { @@ -429,10 +455,10 @@ void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nb { USB_LOG_RAW("actual feedback len:%d\r\n", nbytes); #ifdef CONFIG_USB_HS - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(AUDIO_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value); #else - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value); #endif usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE); diff --git a/demo/audio_v2_speaker_multichan_template.c b/demo/audio_v2_speaker_multichan_template.c index 9f0de4c7..e89c8808 100644 --- a/demo/audio_v2_speaker_multichan_template.c +++ b/demo/audio_v2_speaker_multichan_template.c @@ -274,6 +274,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[AUDIO_OUT_PACKET]; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t s_speaker_feedback_buffer[4]; volatile bool rx_flag = 0; +volatile uint32_t s_speaker_sample_rate; static void usbd_event_handler(uint8_t busid, uint8_t event) { @@ -307,10 +308,10 @@ void usbd_audio_open(uint8_t busid, uint8_t intf) usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET); #if USING_FEEDBACK == 1 #ifdef CONFIG_USB_HS - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(AUDIO_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value); #else - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value); #endif usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE); @@ -324,6 +325,26 @@ void usbd_audio_close(uint8_t busid, uint8_t intf) rx_flag = 0; } +void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq) +{ + if (ep == AUDIO_OUT_EP) { + s_speaker_sample_rate = sampling_freq; + } +} + +uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep) +{ + (void)busid; + + uint32_t freq = 0; + + if (ep == AUDIO_OUT_EP) { + freq = s_speaker_sample_rate; + } + + return freq; +} + void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table) { if (ep == AUDIO_OUT_EP) { @@ -342,10 +363,10 @@ void usbd_audio_iso_out_feedback_callback(uint8_t busid, uint8_t ep, uint32_t nb { USB_LOG_RAW("actual feedback len:%d\r\n", (unsigned int)nbytes); #ifdef CONFIG_USB_HS - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(AUDIO_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_HS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_HS(s_speaker_feedback_buffer, feedback_value); #else - uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(AUDIO_FREQ); + uint32_t feedback_value = AUDIO_FREQ_TO_FEEDBACK_FS(s_speaker_sample_rate); AUDIO_FEEDBACK_TO_BUF_FS(s_speaker_feedback_buffer, feedback_value); #endif usbd_ep_start_write(busid, AUDIO_OUT_FEEDBACK_EP, s_speaker_feedback_buffer, FEEDBACK_ENDP_PACKET_SIZE);