- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dears I have problem to change sample frequency for USB audio demo project USB Audio Device (FreeRTOS) https://github.com/Infineon/mtb-example-psoc6-usb-audio-device-freertos in Modus Toolbox 3.0
I modify USB descriptor to include 16000 Hz freq
And add new PLL_FREQ definition in audio_app.c
#define PLL_FREQ_FOR_48KHZ 55296000 /* in Hz */
#define PLL_FREQ_FOR_44KHZ 50803200 /* in Hz */
#define PLL_FREQ_FOR_16KHZ 18432000 /* in Hz */
And ofcourse modify app_set_clock to adapt to new freq:
void audio_app_set_clock(uint32_t sample_rate)
{
/* Wait till the CapSense is ready */
while (!touch_is_ready())
{
vTaskDelay(1);
};
switch (sample_rate)
{
case AUDIO_SAMPLING_RATE_48KHZ:
{
cyhal_clock_set_frequency(&pll_clock, PLL_FREQ_FOR_48KHZ, &tolerance_0_p); // PLL_FREQ_FOR_48KHZ
break;
}
case AUDIO_SAMPLING_RATE_44KHZ:
{
cyhal_clock_set_frequency(&pll_clock, PLL_FREQ_FOR_44KHZ, &tolerance_0_p);
break;
}
case AUDIO_SAMPLING_RATE_16KHZ:
{
cyhal_clock_set_frequency(&pll_clock, PLL_FREQ_FOR_16KHZ, &tolerance_0_p);
break;
}
default:
break;
But it did not help, in Windows Repro/HeadPhones advanced settings ... I see only 24bit/48000 and 24bit/44100 Hz
(before I do any modification - only compiled demo, there was only grayed 48000 Hz)
Could somebody help to get it works ?
Regards
Radim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Every time you change the USB descriptor, you need to make sure to uninstall the USB driver first, otherwise you might have some driver issues on Windows. Alternatively, you can change the PID value in the device descriptor under the device descriptor tree window, so a new device enumerates.
A side note. Note that this CE originally sets the PLL as the source for the CPU clocks. If you change it to ~18 MHz, you will significantly drop the CPU frequency. You actually can keep the PLL frequency the same as for 48KHz, since both frequencies are multiple.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear @RodolfoGL ,
thanks for mention that it needs to uninstall USB drivers. I just do it once more, but still in USB Audio settings for Speakers there is still only 44100 and 48000 Hz
And If I replace 44100 Hz to 16000 Hz in USB desriptors variable tSampFreq = "16000; 48000;" than Windows show only 48000 Hz and it is grayed out(not available to change them)
Do you have another idea what could be still wrong ?
Regards
Radim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The driver might not be uninstalling correctly. Try to change the PID and let the OS re-enumerate it as a new device.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear @RodolfoGL ,
I just tried to modify VID & PID but after re-enumeration, it is same as previous (only grayed out 48kHz). So it did not helped me. I also studied USB Audio from usb.org if I have been omitted something else. But I did not found anything.
Radim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you add an additional frequency, you need to go change this #define AUDIO_STREAMING_EPS_NUMBER in audio.h. Currently it is set to 2.
Also try to set the Audio IN and Audio OUT to have the exact same frequencies options. I think the firmware doesn't distinguish between them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear @RodolfoGL ,
thanks for this info. But it did not help. I try to find where AUDIO_STREAMING_EPS_NUMBER is used and only in usb_comm.c
is definition
uint8_t usb_comm_sample_frequency[AUDIO_STREAMING_EPS_NUMBER][AUDIO_SAMPLE_FREQ_SIZE];
both def are now 3U
Radim
Radim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear @RodolfoGL
I verified once again and also using USB Device Tree Viewer utility:
------- Audio Streaming Format Type Descriptor -------- bLength : 0x11 (17 bytes) bDescriptorType : 0x24 (Audio Interface Descriptor) bDescriptorSubtype : 0x02 (Format Type) bFormatType : 0x01 (FORMAT_TYPE_I) bNrChannels : 0x02 (2 channels) bSubframeSize : 0x03 (3 bytes per subframe) bBitResolution : 0x18 (24 bits per sample) bSamFreqType : 0x03 (supports 3 sample frequencies) tSamFreq[1] : 0x03E80 (16000 Hz) tSamFreq[2] : 0x0AC44 (44100 Hz) tSamFreq[3] : 0x0BB80 (48000 Hz) Data (HexDump) : 11 24 02 01 02 03 18 03 80 3E 00 44 AC 00 80 BB .$.......>.D.... 00 .
But still I am unable to view these frequencies in Device Properties and playback frequency is still only 48000 Hz.
Could be another problem here ?
Regards
Radim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear @RodolfoGL do you have some another idea what could be wrong, that I am unable to set USB sampling freq to 16 kHz, I did all setup as you write... but Windows still report only 48 kHz
Best Regards
Radim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm attaching a modified version of the code example running at 16 KHz. Here is the list of things that changed:
1) USB descriptor was updated to only support 16 KHz. I also changed the PID to avoid driver issue.
2) Initialized the I2S to run at 16 KHz
3) Updated feedback endpoint sample rate
4) Updated the enpoint buffer sizes
5) Commented out code to update the PLL.
6) Updated the MCLK frequency
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear @RodolfoGL ,
I just tried to test the code in Modus Toolbox 3.0, but I was unable to import it to modus toolbox. After import it has different BSP CY8CKIT-062S2-43012. I tried to run make getlibs...
mtbgetlibs: getlibs failed
WARNING:Trying to latest-lock to release-v1.4.0 but this version doesn't exist in the database. This problem can occur if the locking_commit.log is out of date. Locking to release-v1.3.0.
ERROR:there was an error retreiving the asset 'https://github.com/cypresssemiconductorco/TARGET_CY8CKIT-062S2-43012W' commit 'latest-v2.X' - fatal: could not read Username for 'https://github.com': terminal prompts disabled
And also tried converting to CY8CPROTO-062-4343W without success... same error message.
after updating original BSP from 2.1.x -> 3.x it could be converted and look that it is working. Windows correctly see 24bit/16khz.
So many thanks, I will examine when I was wrong...
Best Regards
Radim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear @RodolfoGL
I just see only one difference that you do, I have USB descriptor with 3 frequencies "16000; 44100; 48000;" and make appropriate changes in audio_app.c, audio_feed.c
You have only one frequency 16000;
and you assign usb_comm_clock_configured = true; on startup
I update audio_app_set_clock function to adapt 16kHz (
audio_app.c:
/*******************************************************************************
* Function Name: audio_app_set_clock
********************************************************************************
* Summary:
* Update the PLL clock to achieve the desired sample rate.
*
* Parameters:
* sample_rate: new sample rate to be enforced.
*
*******************************************************************************/
void audio_app_set_clock(uint32_t sample_rate)
{
/* Wait till the CapSense is ready */
//while (!touch_is_ready())
//{
// vTaskDelay(1);
//};
switch (sample_rate)
{
case AUDIO_SAMPLING_RATE_48KHZ:
{
cyhal_clock_set_frequency(&pll_clock, PLL_FREQ_FOR_48KHZ, &tolerance_0_p);
break;
}
case AUDIO_SAMPLING_RATE_44KHZ:
{
cyhal_clock_set_frequency(&pll_clock, PLL_FREQ_FOR_44KHZ, &tolerance_0_p);
break;
}
case AUDIO_SAMPLING_RATE_16KHZ:
{
cyhal_clock_set_frequency(&pll_clock, PLL_FREQ_FOR_16KHZ, &tolerance_0_p);
break;
}
default:
break;
}
/* Update the USB Reset clock based on the new frequency */
cyhal_clock_set_frequency(&usb_rst_clock, USB_CLK_RESET_HZ, &tolerance_1_p);
/* Set flag to indicate that the clock was configured */
usb_comm_clock_configured = true;
/* Update baseline to compensate change in the clock */
touch_update_baseline();
}
audio_feed.c:
/*******************************************************************************
* Function Name: audio_feed_update_sample_rate
********************************************************************************
* Summary:
* Set the audio streaming sample rate.
*
*******************************************************************************/
void audio_feed_update_sample_rate(uint32_t sample_rate)
{
switch (sample_rate)
{
/* The sample rate in the feedback endpoint is represented with 3 bytes
* as an fraction number - X.Y, where:
* X = (Byte[2] << 2) + (Byte[1] >> 6)
* Y = (Byte[1] & 0x3F)) + (Byte[0] & 0xF0)
*/
case AUDIO_SAMPLING_RATE_48KHZ:
audio_feed_data[0] = 0x00u;
audio_feed_data[1] = 0x00u;
audio_feed_data[2] = 0x0Cu; //0x0Cu
break;
case AUDIO_SAMPLING_RATE_44KHZ:
audio_feed_data[0] = 0x40u;
audio_feed_data[1] = 0x06u;
audio_feed_data[2] = 0x0Bu;
break;
case AUDIO_SAMPLING_RATE_16KHZ:
audio_feed_data[0] = 0x00u;
audio_feed_data[1] = 0x00u;
audio_feed_data[2] = 0x04u;
break;
default:
break;
}
}
include\audio.h
/*******************************************************************************
* Constants from USB Audio Descriptor
*******************************************************************************/
#define AUDIO_OUT_ENDPOINT_SIZE (102U)
#define AUDIO_IN_ENDPOINT_SIZE (102U)
#define AUDIO_FEEDBACK_ENDPOINT_SIZE (3U)
#define AUDIO_FRAME_DATA_SIZE (32u)
Maybe the problem was in this file, I suppose that it's value is updated to correspond with USB descriptor... but it looks that it did not and need to by manually edited.
I don't know what other could be wrong, but now I can continue with only one freq. 16kHz... and hope that I will be able to continue.
Best Regards
Radim