Hello,
Could I please get some help or advise of how to change the Keil Usb audio example to adaptive transfers,
thanksyou
I got this information from this thread http://www.keil.com/forum/13257/
You can't replace the ring buffer with double buffers, because the purpose of buffering doesn't match. On this example, the ring buffer is used for sampling rate adjustment. Double buffer, which is always enabled on bulk and isoc EPs of LPC17xx, is used to separate the buffer access from firmware and SIE.
I'll explain about the sampling rate adjustment on this example.
Keil audio example doesn't define synchronization type on the endpoint descriptor (no synchronization), which is out of the USB audio spec. Audio isoc endpoint should have one of synchronization type, Asynchronous, Synchronous or Adaptive.
usb.h #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 usbdesc.c const BYTE USB_ConfigDescriptor[] = { ... /* Endpoint - Standard Descriptor */ AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(3), /* bEndpointAddress */ USB_ENDPOINT_TYPE_ISOCHRONOUS, /* bmAttributes */ <--------- should add synchronization type WBVAL(64), /* wMaxPacketSize */ 0x01, /* bInterval */ 0x00, /* bRefresh */ 0x00, /* bSynchAddress */
No synchronization isoc EP is handled as a Synchronous EP on Windows audio class driver. For Synchronous OUT EP, the data is provided to the EP, sampled by bus clock. Usually bus clock derives from a crystal on PC, whose frequency slightly differs from the crystal on the device. Therefore, re-sample is required to play back the data on the device DAC.
Audio source ---(re-sample)---> USB bus clock ---(re-sample)---> Device local clock
On this example, this re-sample is done in TIMER0_IRQHandler() on the DataBuf[]. This process adjust the sampling rate by skipping a sample, or by re-using the same sample again, according to the difference of sampling rate. It is tuned by increment of read-out index, DataOut, as follows.