background image

USB Audio Design Guide

Document Number: XM0088546.1

Publication Date: 2016/5/12

XMOS © 2016, All Rights Reserved.

Summary of Contents for xCORE-200 Multi-channel Audio board

Page 1: ...USB Audio Design Guide Document Number XM0088546 1 Publication Date 2016 5 12 XMOS 2016 All Rights Reserved...

Page 2: ...deployed as a framework with reference design applications extending and customising this framework These reference designs have particular qualified feature sets and an accompanying reference hardwar...

Page 3: ...itecture 17 3 1 The USB Audio System Architecture 18 3 2 XMOS USB Device XUD Library 18 3 3 Endpoint 0 Management and Control 20 3 3 1 Enumeration 20 3 3 2 Over riding Standard Requests 21 3 3 3 Class...

Page 4: ...Applications and Modules 50 5 3 Build Configurations 50 5 4 Validated Build Configurations 51 5 5 Configuration Naming Scheme 51 5 6 A USB Audio Application 51 5 6 1 Custom Defines 52 5 6 2 Configura...

Page 5: ...Array Microphone Board 82 6 7 1 Clocking and Clock Selection 83 6 7 2 DAC Configuration 84 6 7 3 AudioHwInit 84 6 7 4 AudioHwConfig 84 6 7 5 Mic Processing Example 84 6 7 6 Validated Build Options 85...

Page 6: ...1 Overview XM0088546 1...

Page 7: ...for new designs Requirements Development Tools xTIMEcomposer Development Tools v14 or later USB External ULPI USB Phy If using XS1 G L Series Audio External audio DAC ADC CODECs and required supportin...

Page 8: ...controller an dual tile xCORE 200 device with an integrated High Speed USB 2 0 PHY RGMII Gigabit Ethernet interface and 16 logical cores deliver ing up to 2000MIPS of deterministic and responsive proc...

Page 9: ...bit ports on the xCORE 200 via a 5V to 3 3V buffer 2 1 4 Audio Clocking A flexible clocking scheme is provided for both audio and other system services In order to accommodate a multitude of clocking...

Page 10: ...instructions delivering up to 1000MMACS Figure 1 shows the block layout of the xCORE 200 Microhone Array board xCORE XUF216 Ethernet PHY LAN8710A RJ45 25MHz TILE CLK to xCore DAC MCLK PLL CLK Device...

Page 11: ...on the board MIC6 MIC1 MIC2 MIC5 MIC0 A B D xCORE 200 XUF216 C MIC4 MIC3 Figure 2 xCORE 200 Microphone Array Board Microphone Arrangement 2 2 2 Analogue Output As well at 7 PDM microphones the board...

Page 12: ...device is configured using the I2C interface 2 2 4 Buttons LEDs and Other IO The board has 13 LEDs that are controlled by the xCORE 200 GPIO The layout of the LEDs is shown in Figure 3 MIC6 MIC1 MIC2...

Page 13: ...ral purpose push button switches are provided When pressed each button creates a connection from the I O to GND A standard XMOS xSYS interface J2 is provided to allow host debug of the board via JTAG...

Page 14: ...socket on the USB AB slice XMOS XS1 U8A 64 24 bit 192kHz DSD Stereo Audio DAC CS4392 24 bit 192kHz Stereo Audio ADC CS4392 I2S I2S Audio Master Clock PLL 24 576 MHz Or 22 5792 MHz 24MHz MCLK FSEL Ster...

Page 15: ...quired USB switching This also means the XMOS device can be used as a USB device or host using the same main board This document addresses the combination of the main board with the USB AB slice part...

Page 16: ...r S PDIF output 2 6 USB Audio 2 0 Reference Design Board This hardware should not be used for the basis of a new design The USB Audio 2 0 Reference Design15 is a stereo hardware reference design avail...

Page 17: ...not be used for the basis of a new design The USB Audio 2 0 Multichannel Reference Design XR USB AUDIO 2 0 MC 17 is a hardware reference design available from XMOS based on the XMOS L16 device previou...

Page 18: ...USB Audio Design Guide 18 110 012 012 012 012 012 012 012 012 Figure 6 USB Audio 2 0 Multichannel Reference Design Block Diagram XM0088546 1...

Page 19: ...ADAT Receive External Clock Recovery ClockGen MIDI PDM Microphones Overview of PDM implemention Resource Usage The following sections describe the software architecture of the XMOS USB Audio framework...

Page 20: ...can also handle volume control instead of the decoupler S PDIF Transmitter Outputs samples of an S PDIF digital audio interface S PDIF Receiver Inputs samples of an S PDIF digital audio interface req...

Page 21: ...igure 9 shows the XUD library communicating with two other cores Endpoint 0 This core controls the enumeration configuration tasks of the USB device Endpoint Buffer This core sends receives data packe...

Page 22: ...B Specification Since these are required for all devices in order to function a USB_StandardRequests function is provided see module_usb_device which implements all of these requests This includes the...

Page 23: ...sts These are handled in functions such as AudioClasRequests_2 AudioClassRequests_2 DFUDeviceRequests etc depending on the type of re quest Any device specific requests are handled in this case Audio...

Page 24: ...er be handled by the decoupler core or the mixer component if the mixer component is used Handling the volume in the mixer gives the decoupler more performance to handle more channels If the effect of...

Page 25: ...he buffering core the decouple core passes the next packet from the FIFO to the buffer core It also signals to the XUD library that the buffer core is able to send a packet 4 When the buffer core has...

Page 26: ...ation scheme is shown in the table below for non sample frequency change case Decouple Audio System Note outuint Audio system requests sample exchange inuint Interrupt fires and inuint performed outui...

Page 27: ...USB frames are sent at 8kHz so on average for 48kHz each packet contains six samples per channel The device uses Asynchronous mode so the audio clock may drift and run faster or slower than the host...

Page 28: ...a out from the XMOS device to CODEC DAC MCLK The master clock running the CODEC DAC ADC Figure 12 I2S Signals The bit clock controls the rate at which data is transmitted to and from the CODEC In the...

Page 29: ...ort p_bclk BCLK is used to clock the LRCLK p_lrclk and data signals SDIN p_sdin and SDOUT p_sdout Again a clock block is used clk_audio_bclk which has p_bclk as its input and is used to clock the port...

Page 30: ...ring cores and mixer First a change of sample frequency is reported by sending the new frequency over an XC channel The audio core detects this by checking for the presence of a control token on the c...

Page 31: ...solely doing volume setting then the component will use only one core 3 6 1 Control The mixers can receive the following control commands from the Endpoint 0 core via a channel Command Description SET...

Page 32: ...ources 0 displays which channels could possibly be mapped to mixer inputs Notice that analogue inputs 1 and 2 are on mixer inputs 10 and 11 Now examine the audio output mapping xmos_mixer display aud...

Page 33: ...nalogue inputs To demonstrate this firstly undo the changes above xmos_mixer set value 0 80 inf xmos_mixer set value 0 89 inf xmos_mixer set value 0 0 0 xmos_mixer set value 0 9 0 The mixer should now...

Page 34: ...nsmitPortConfig function would enable internal master clock generation e g when clock source is already locked to desired audio clock Sample frequencies 44 1 48 88 2 96 176 4 192 kHz Master clock rati...

Page 35: ...eam structure The stream is composed of words with the following structure shown in Figure 20 The channel status bits are 0x0nc07A4 where c 1 for left channel c 2 for right channel and n indicates sam...

Page 36: ...Left and the first sample of a frame can be used if the user bits need to be reconstructed Figure 23 S PDIF RX Tags See S PDIF specification for further details on format user bits etc 3 8 1 Usage an...

Page 37: ...tore left break case FRAME_Z Store right break 3 9 ADAT Receive The ADAT receive component receives up to eight channels of audio at a sample rate of 44 1kHz or 48kHz The API for calling the receiver...

Page 38: ...ion can either provide fixed master clock sources via selectable oscil lators clock generation IC etc to provide the audio master or use an external PLL Clock Multiplier to generate a master clock bas...

Page 39: ...s these and translates them to 8 bit MIDI messages which are sent over UART Similarly incoming 8 bit MIDI messages are aggregated into 32 bit USB MIDI events an passed on to the buffer core The MIDI c...

Page 40: ...et FIR comp Gain comp Overlapping frames WIndowing Bit reverse 2x4 ch 8 48 kHz 2x4 ch 8 48 kHz mic_array_pdm_rx mic_array_decimate_to_pcm_4ch Figure 25 Five to eight count PDM interface The left most...

Page 41: ...cting it to the rest of the system pcm_pdm_mic c_pdm_pcm The implemetation of this function can be found in the file pcm_pdm_mics xc The first job of this function is to configure the ports clocking f...

Page 42: ...1 17 5 10 5 code none USB Buffering 1 22 5 1 code none Audio driver 1 8 5 6 code See 3 5 S PDIF Tx 1 3 5 2 code 1 x 1 bit port S PDIF Rx 1 3 7 3 7 code 1 x 1 bit port ADAT Rx 1 3 2 3 2 code 1 x 1 bit...

Page 43: ...imeout it will start in DFU mode this is initially set to one second and is configurable from the host The host can send a custom user request XMOS_DFU_RESETDEVICE to the DFU interface that resets the...

Page 44: ...tion of Windows drivers is beyond the scope of this document please contact XMOS for further details 4 2 2 Audio Class 1 0 Mode and Fall back The normal default for XMOS USB Audio applications is to r...

Page 45: ...int data handling is enabled in the buffer core The Get Descriptor Request enabled in endpoint 0 returns the report descriptor for the HID device This details the format of the HID reports returned fr...

Page 46: ...ate Settings that can be used to change certain characteristics of the interface and underlying endpoint A typical use of Alternate Settings is to provide a way to change the subframe size and or numb...

Page 47: ...upport restrictions with certain hosts For example many Android based hosts support only 16bit samples in a 2 byte subslot bSubSlot size is set using the following defines When running in high speed H...

Page 48: ...AW_DATA UAC_FORMAT_TYPEI_PCM Currently DSD is only supported on the output playback stream 4 byte slot size with a 32 bit resolution is required for RAW DSD format Native DSD requires driver support a...

Page 49: ...ed if USB audio design detects a un interrupted run of these samples above a defined threshold it switches to DSD mode using the lower 16 bits as DSD sample data When this check for DSD headers fails...

Page 50: ...the Build icon To install the software open the xTIMEcomposer Studio and follow these steps 1 Choose File Import 2 Choose General Existing Projects into Workspace and click Next 3 Click Browse next t...

Page 51: ...board and plug the xTAG 2 into your PC or Mac To upgrade the flash from xTIMEcomposer Studio follow these steps 1 Start xTIMEcomposer Studio and open a workspace 2 Choose File Import C XC C XC Execut...

Page 52: ...nnel Reference Design application app_usb_aud_skc_u16 U16 SliceKit with Audio Slice application app_usb_aud_xk_u8_2c Multi function Audio board application app_usb_aud_skc_su1 DJ kit application Figur...

Page 53: ...Series Reference Design Build Option Name Options Denoted by Audio Class Version 1 or 2 1 or 2 Audio Input on or off i or x Audio Output on or off o or x MIDI on or off m or x S PDIF Output on or off...

Page 54: ..._TX define SPDIF_TX 1 endif Next the file defines the audio properties of the application This application has stereo in and stereo out with an S PDIF output that duplicates analogue channels 1 and 2...

Page 55: ...n needs to provide implemen tations of user functions that are specific to the application For app_usb_aud_l1 the implementations can be found in audiohw xc Firstly code is required to initialise the...

Page 56: ...unsigned time unsigned tmp Put codec in reset and set master clock select appropriately Read current port output PORT32A_PEEK tmp Put CODEC reset line low tmp P32A_COD_RST if samFreq 22050 0 Frequenc...

Page 57: ...rt 32A resource ID asm peek 0 res 1 r x r XS1_PORT_32A x P32A_LED_B Output to port asm out res 0 1 r XS1_PORT_32A r x Any actions required on stream stop e g DAC mute run every stream stop For L1 USB...

Page 58: ...OINT_COUNT_IN c_sof epTypeTableOut epTypeTableIn p_usb_rst clk 1 XUD_SPEED_HS XUD_PWR_CFG else XUD_Manager c_xud_out ENDPOINT_COUNT_OUT c_xud_in ENDPOINT_COUNT_IN c_sof epTypeTableOut epTypeTableIn p_...

Page 59: ...def IAP_EA_NATIVE_TRANS c_xud_out ENDPOINT_NUMBER_OUT_IAP_EA_NATIVE_TRANS c_xud_in ENDPOINT_NUMBER_IN_IAP_EA_NATIVE_TRANS c_EANativeTransport_ctrl c_ea_data endif endif if defined SPDIF_RX defined ADA...

Page 60: ...pll_clk c_dig_rx c_clk_ctl c_clk_int endif Finally if MIDI is enabled you need a core to drive the MIDI input and output The MIDI core also optionally handles authentication with Apple devices Due to...

Page 61: ...ain xc 4 Add any custom code in other files you need The following sections show some example changes with a high level overview of how to change the code 5 7 1 Example Changing output format You may...

Page 62: ...B Audio Design Guide 62 110 3 Implement the DSP on this core This needs to be synchronous i e for every sample received from the decoupler a sample needs to be outputted to the audio driver XM0088546...

Page 63: ...The USB Audio 2 0 Reference Design is an application of the USB audio framework specifically for the hardware described in 2 6 and is implemented on the L Series single tile device 500MIPS The code c...

Page 64: ...ort 32A Port 32A on the XS1 L device is a 32 bit wide port that has several separate signal bit signal connected to it accessed by multiple cores To this end any output to this port must be read modif...

Page 65: ...D_A XD53 P32A4 LED_B Figure 34 Port 32A Signals 6 1 2 Clocking The board has two on board oscillators for master clock generation These produce 11 2896MHz for sample rates 44 1 88 2 176 4KHz etc and 2...

Page 66: ...z With MDIV2 high the master clock must be 512Fs in single speed mode 256Fs in double speed mode and 128Fs in quad speed mode This allows a 24 576MHz master clock to be used for sample rates of 48 96...

Page 67: ...changing the build options These are described in usb_audio_sec_custom_defines_api The design has only been fully validated against the build options as set in the application as distributed See 5 3...

Page 68: ...tile device 500MIPS The software design supports four channels of audio at sample frequencies up to 192kHz and uses the following components XMOS USB Device Driver XUD Endpoint 0 Endpoint buffer Deco...

Page 69: ...these CODECs takes place using I2C with both sharing the same I2C bus The design uses the open source I2C component sc_i2c27 6 2 3 U Series ADC The codebase includes code exampling how the ADC built i...

Page 70: ...everal ways by changing the build options These are described in usb_audio_sec_custom_defines_api The design has only been fully validated against the build options as set in the application as distri...

Page 71: ...onfiguration is similar to the configuration above in that it runs in Audio 1 0 over full speed USB However the it is output only i e the input path is disabled with DNUM_USB_CHAN_IN 0 6 3 The USB Aud...

Page 72: ...are Upgrade DFU Mixer S PDIF Transmitter S PDIF Receiver ADAT Receiver Clockgen MIDI Figure 37 shows the software layout of the USB Audio 2 0 Multichannel Reference Design tile 0 tile 1 Figure 37 Dual...

Page 73: ...Configuration 1 All the defines are set as per the distributed application It has the mixer enabled supports 16 channels in 10 channels out and supports sample rates up to 96kHz 6 3 2 2 Configuration...

Page 74: ...Endpoint buffer Decoupler Audio Driver Device Firmware Upgrade DFU S PDIF Transmitter or MIDI The software layout is the identical to the single tile L Series Reference Design and therefore the diagr...

Page 75: ...locked via the same pin as the I2S LR clock Since this means that a ADC sample is received every audio sample the ADC is setup and it s data received in the audio driver core audio xc The ADC inputs f...

Page 76: ...when inverted then the buttons states are used to either indicate play pause or next previous Based on counter and a small state machine a single click on either button provides a play pause command...

Page 77: ...ata 0 a HID_CONTROL_VOLUP_SHIFT b HID_CONTROL_VOLDN_SHIFT else Assign buttons A and B to play for single tap next prev for double tap if b multicontrol_count wait_counter 0 lastA 0 else if a multicont...

Page 78: ...L Series and vice versa 6 4 5 1 Configuration 2ioxs This configuration runs in high speed Audio Class 2 0 mode has the mixer disabled supports 2 channels in 2 channels out supports sample rates up to...

Page 79: ...sample frequencies up to 192kHz and uses the following components XMOS USB Device Driver XUD Endpoint 0 Endpoint buffer Decoupler Audio Driver Device Firmware Upgrade DFU S PDIF Transmitter MIDI The...

Page 80: ...he board is equipped with a single multi channel audio DAC Cirrus Logic CS4384 and a single multi channel ADC Cirrus Logic CS5368 giving 8 channels of analogue output and 8 channels of analogue input...

Page 81: ...ities between the U Series and L Series feature set it is fully expected that all listed U Series configurations will operate as expected on the L Series and vice versa 6 5 5 1 Configuration 2ioxs Thi...

Page 82: ...e derived reference The master clock source is controlled by a mux which in turn is controlled by bit 5 of PORT 8C Value Source 0 Master clock is sourced from PhaseLink PLL 1 Master clock is source fr...

Page 83: ...e 6 6 4 AudioHwConfig The AudioHwConfig function is called on every sample frequency change The AudioHwConfig function first puts the both the DAC and ADC into reset by setting P8C 1 and P8C 6 low It...

Page 84: ...MIDI enabled m disabled x SPDIF output enabled s disabled x SPDIF input enabled s disabled x ADAT output enabled a disabled x ADAT input enabled a disabled x DSD output enabled d disabled x Figure 42...

Page 85: ...ionality is primarily included on the board to allow for Ethernet AVB where syncing to an external clock is required In the USB audio design the IC is simply used for static master clock generation Th...

Page 86: ...the both the DAC headphone amp and into reset by writing to PORT 4F It then sets the required ratio in the CS2100 via I2C based on the mClk parameter After a delay in order to allow the master clock f...

Page 87: ...in the Makefile See 5 3 for details and binary naming schemes These fully validated build configurations are enumerated in the supplied Makefile In practise due to the similarities between the U L xCO...

Page 88: ...edefines h These defines should be over ridden in the mandatory customdefines h file or in Makefile for a relevant build configuration This section fully documents all of the setable defines and their...

Page 89: ...cription Number of input channels device to host Default NONE Must be defined by app Macro DSD_CHANS_DAC Description Number of DSD output channels Default 0 disabled Macro I2S_CHANS_DAC Description Nu...

Page 90: ...hould be used Default MIN_FREQ Macro MCLK_441 Description Master clock defines for 44100 rates in Hz Default NONE Must be defined by app Macro MCLK_48 Description Master clock defines for 48000 rates...

Page 91: ...iguration 7 1 5 1 MIDI Macro MIDI Description Enable MIDI functionality including buffering descriptors etc Default DISABLED Macro MIDI_RX_PORT_WIDTH Description MIDI Rx port width 1 or 4bit Default 1...

Page 92: ...les ADAT Rx Default 0 Disabled Macro ADAT_RX_INDEX Description ADAT Rx first channel index defines which channels ADAT will be input on Note indexed from 0 Default NONE Must be defined by app when ADA...

Page 93: ...Vendor String used by the device This is also pre pended to various strings used by the design Default XMOS Macro VENDOR_ID Description USB Vendor ID or VID as assigned by the USB IF Default 0x20B1 X...

Page 94: ...fault 0x0002 Macro BCD_DEVICE Description Device firmware version number in Binary Coded Decimal format 0xJJMN where JJ major M minor N sub minor version number NOTE User code should not modify this b...

Page 95: ...UT_1_SUBSLOT_BYTES Description Sample sub slot size bytes of output stream Alternate 1 when running in high speed Default 4 if resolution for Alternate 1 is 24bits else resolution 8 Note the default c...

Page 96: ...OUTPUT_1_RESOLUTION_BITS 8 Macro FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES Description Sample sub slot size bytes of output stream Alternate 2 when running in full speed Note in full speed mode bus band...

Page 97: ...PUT_FORMAT_COUNT Description Number of supported input stream formats Default 1 Macro STREAM_FORMAT_INPUT_1_RESOLUTION_BITS Description Sample resolution bits of input stream Alternate 1 Default 24 Ma...

Page 98: ..._PCM 7 1 8 Volume Control Macro OUTPUT_VOLUME_CONTROL Description Enable disable output volume control including all processing and descriptor support Default 1 Enabled Macro INPUT_VOLUME_CONTROL Desc...

Page 99: ...if MIXER enabled else 0 Macro MIX_INPUTS Description Number of channels input into the mixer Note total number of mixer nodes is MIX_INPUTS MAX_MIX_COUNT Default 18 Macro MIN_MIXER_VOLUME Description...

Page 100: ...by an application using the XMOS USB Audio framework 7 2 1 External Audio Hardware Configuration Functions Function AudioHwInit Description This function is called when the audio core starts after th...

Page 101: ...be configured for DSD operation sampRes_DAC The sample resolution of the DAC stream sampRes_ADC The sample resolution of the ADC stream 7 2 2 Audio Streaming Functions The following functions can be...

Page 102: ...ion Type void UserReadHIDButtons unsigned char hidData Parameters hidData The function should write relevant HID bits into this array The bit ordering and functionality is defined by the HID report de...

Page 103: ...chanend c_epOut int noEpOut chanend c_epIn int noEpIn chanend c_sof XUD_EpType epTypeTableOut XUD_EpType epTypeTableIn out port p_usb_rst clock clk unsigned rstMask XUD_BusSpeed_t desiredSpeed XUD_Pwr...

Page 104: ...s endpoint XUD_EPTYPE_INT Interrupt endpoint XUD_EPTYPE_DIS Endpoint not used The first array contains the endpoint types for each of the OUT endpoints the second array contains the endpoint types for...

Page 105: ...posed in the following order Endpoint 0 out Audio OUT endpoint if output enabled MIDI OUT endpoint if MIDI enabled Function Endpoint0 Description Function implementing Endpoint 0 for enumeration contr...

Page 106: ...to the clockgen thread if present c_usb_test Optional chanend to be connected to XUD if test modes required c_EANativeTransport_ctrl Optional chanend to be connected to EA Native endpoint man ager if...

Page 107: ...kGen thread if present c_sof Start of frame channel connected to the XUD c_aud_ctl Audio control channel connected to Endpoint0 p_off_mclk A port that is clocked of the MCLK input not the MCLK input i...

Page 108: ...es to from other digital I O threads Type void audio chanend c_in chanend c_config chanend c_adc Parameters c_in Audio sample channel connected to the mixer thread or the decouple thread c_dig channel...

Page 109: ...ies of 0 1 transitions it will increase the divider Output the received 24 bit sample values are output as a word on the streaming channel end Each value is shifted up by 4 bits with the bottom four b...

Page 110: ...rameters p ADAT port should be 1 bit and clocked at 100MHz oChan channel on which decoded samples are output Function adatReceiver44100 Description ADAT Receive Thread 44 1kHz sample rate When a data...

Page 111: ...ck clk_midi chanend c_midi unsigned cable_number chanend c_iap chanend c_i2c port p_scl port p_sda Parameters p_midi_in 1 bit input port for MIDI p_midi_out 1 bit output port for MIDI clk_midi clock b...

Page 112: ...f any kind express or implied and shall have no liability in relation to its use Xmos Ltd makes no representation that the Information or any particular implementation thereof is or will be free from...

Reviews: