My requirement is to send 16kHz 1channel voice data stream to pc .
I use 16khz (2 channel and 1 channel) wav and 1 48khz (2 channel) wav as input (converted to .c file) data to directly send to m_temp_buffer in main.c (nRF5_SDK_17.0.2_d674dde\examples\peripheral\usbd_audio), and play a song in pc and then use recording tool in pc to record the data from nrf52 usb mic .
result is :
48khz input wav :the output recording is exactly same with the input.
16khz input wav(2 channel):the output recording is distorted.
16khz input wav(1 channel):the output recording is distorted.
my change to the main.c is as follows:
/**
* @brief User event handler @ref app_usbd_audio_user_ev_handler_t (headphones)
*/
static void hp_audio_user_ev_handler(app_usbd_class_inst_t const * p_inst,
app_usbd_audio_user_event_t event)
{
app_usbd_audio_t const * p_audio = app_usbd_audio_class_get(p_inst);
UNUSED_VARIABLE(p_audio);
switch (event)
{
case APP_USBD_AUDIO_USER_EVT_CLASS_REQ:
hp_audio_user_class_req(p_inst);
break;
case APP_USBD_AUDIO_USER_EVT_RX_DONE:
{
ret_code_t ret;
#if 0
/* Block from headphones copied into buffer, send it into microphone input */
ret = app_usbd_audio_class_tx_start(&m_app_audio_microphone.base, m_temp_buffer, m_temp_buffer_size);
if (NRF_SUCCESS == ret)
{
bsp_board_led_invert(LED_AUDIO_RX);
}
#endif
break;
}
default:
break;
}
}
static void hp_sof_ev_handler(uint16_t framecnt)
{
UNUSED_VARIABLE(framecnt);
if (APP_USBD_STATE_Configured != app_usbd_core_state_get())
{
return;
}
size_t rx_size = app_usbd_audio_class_rx_size_get(&m_app_audio_headphone.base);
m_temp_buffer_size = rx_size;
//NRF_LOG_INFO("%d %d",rx_size,sizeof(m_temp_buffer));
if (rx_size > 0)
{
ASSERT(rx_size <= sizeof(m_temp_buffer));
ret_code_t ret;
#if 1
memcpy(m_temp_buffer,samplelg1+offset,BUFFER_SIZE*4);
m_temp_buffer_size= BUFFER_SIZE*4;
offset+=BUFFER_SIZE*4;
if(offset>=652032)
{
offset=0;
}
#endif
/* Block from headphones copied into buffer, send it into microphone input */
ret = app_usbd_audio_class_tx_start(&m_app_audio_microphone.base, m_temp_buffer, m_temp_buffer_size);
if (NRF_SUCCESS == ret)
{
bsp_board_led_invert(LED_AUDIO_RX);
}
}
}
question is how to change usbd_audio example to send 16kHZ 1channel voice data to pc properly?