Design of USB sound card system based on I2S

This article refers to the address: http://

Abstract : This paper introduces the design of USB sound card system based on S3C2410 processor platform using I2S bus. The implementation of USB sound card communication is elaborated, and the ring buffer is realized according to the characteristics of I2S bus DMA transmission to improve system performance and meet the real-time requirements of audio.
Key words : USB sound card; S3C2410; I2S

introduction
In recent years, USB products have emerged in an endless stream. The USB audio class has become a standard specification under the efforts of the USB Developer Forum. USB sound cards have also begun to appear quietly on the market. Because the USB sound card has built-in DAC and active power amplifier, the audio data enters the USB sound card digitally, which completely eliminates the internal interference of the PC. Therefore, the USB sound card may become an alternative to the existing built-in sound card. This article describes a USB sound card design based on ARM processor.

USB sound card principle
The working principle of the USB sound card can be seen from the USB sound card data flow diagram (see Figure 1). When playing music on the host side, the application software or driver converts various audio signals into a unified format, such as PCM, MPEG, etc., and sends the data stream to the USB sound card through the host's USB interface. After the USB interface of the sound card receives the data, the parallel audio data is converted into serial through the I2S interface, and then sent to the audio codec chip for D/A conversion, and the sound can be pronounced in the speaker connected to the audio chip. The recording process and the playback process are just the opposite.



Figure 1 USB sound card data stream

hardware design
The USB sound card hardware mainly includes an MCU and an audio codec chip. The MCU uses Samsung's processor S3C2410, and the S3C2410 has an I2S bus controller and a USB Slaver controller. The S3C2410's I2S controller implements an external 8/16-bit stereo audio CODEC IC interface that supports the I2S bus data format and MSB-justified data format and supports DMA transfer mode.

The audio chip uses the UDA1341TS. The UDA1341TS provides a standard I2S interface that can be directly connected to the I2S pin of the S3C2410. In addition, the chip also provides a standard L3, microphone and speaker interface. The pins of the L3 interface are connected to the three GPIO output pins of the S3C2410, and the L3 interface is controlled by the GPIO. The UDA1341TS audio chip integrates digital audio and mixer functions. The digital audio function can play digital sounds or record sounds. Because of this function, such chips are often referred to as CODEC devices. The mixer is used to control the volume of various input/outputs, etc., and is controlled by the L3 interface in this chip.



Figure 2 USB sound card topology

software design
The software design consists of two parts: USB sound card firmware programming and host-side Windows driver design. Because the USB audio device is a standard device and has a standard USB audio driver on the Windows operating system, developers only need to develop firmware based on the protocol of the USB audio class.

The firmware of the USB sound card mainly includes two parts. The first part is mainly USB communication, the second part realizes data transmission of I2S interface and buffer control of data stream.

USB communication
In order to effectively define the descriptor of the USB sound card, the USB sound card descriptor can first determine the topology of the USB sound card according to the USB audio protocol and the USB sound card function that needs to be implemented (see Figure 2), and then according to the topology diagram. And the protocol of the USB audio class descriptor, write the descriptor of the USB sound card.

The USB sound card descriptor consists of five parts, namely device descriptor, configuration descriptor, interface descriptor, endpoint descriptor and string descriptor. Interface descriptors are a difficult point. The interface descriptor of the USB sound card includes two parts: an audio control (AudioControl) interface descriptor and an audio data stream (AudioStreaming) interface descriptor.

1. USB audio control interface descriptor. According to the topology diagram of the USB sound card, when the sound card is used for the playback function, the control flow of the sound card function is represented by IT1 (Input Teminal), OT3 (Out Teminal) and Feature units, and IT1 indicates that the PC sends to the USB sound card. The audio data stream, OT3 represents the data stream sent to the DAC, and the Feature unit between IT1 and OT3 is used to adjust the volume and sound functions. When the sound card performs the recording function, the functional topology of the USB is represented by IT2, OT4, IT2 represents the audio data stream sampled by A/D, and OT4 represents the data stream sent to the PC through the USB interface. The data transfer of the USB audio control interface generally uses the default endpoint 0.

In the topology diagram of the USB sound card, F represents the Feature unit of the USB audio class. The main function of the Feature unit is to control the volume, mute, bass, and so on. If the Feature unit is declared in the descriptor, some functions of the sound and audio devices in the Control Panel can be used under the Windows operating system. Then, when controlling the volume and other controls in Windows, the firmware program is triggered to control the L3 interface of the UDA1341TS chip.

2. USB audio stream interface descriptor. Because USB audio has both playback and recording functions, two simultaneous data stream interfaces are required, and the two interfaces use bidirectional endpoint 1 for data transmission.

Through the topology diagram of the USB sound card, the flow and function of the audio interface can be analyzed to obtain the descriptor of the USB sound card.

Program Implementation of USB Communication The S3C2410 has five bidirectional FIFO endpoints, of which 0 is the control transmission endpoint, and the other 4 endpoints support batch, interrupt, and synchronous transmission. Two two-way transmission endpoints of 0 and 1 are used in this system. Endpoint 0 performs control transmission (CONTROL), on the one hand, transmits control information of the USB protocol, such as Setup events, handshake signals, enumeration information, etc., on the other hand, transmits audio control information such as sampling rate control, volume control, and the like. Endpoint 1 adopts synchronous transmission (ISOCHRONOUS) with a transmission time interval of 1ms, which is used to transmit recording or playback data between the host and I2S in real time.

According to the USB protocol, any data transfer of the USB device is assigned by the USB host, and then the USB device responds to the corresponding USB host bus request. The S3C2410's USB controller uses an interrupt mode response, so the following work should be done in the S3C2410's USB interrupt service routine:
Isr_USB()
{
If(USB_INT_REG&RESET_INT) Reset_USB(); //Restart USB device
If(USB_INT_REG&RESUME_INT) Resume_USB(); //Wake up the USB device
If(USB_INT_REG&SUSPEND_INT) Suspend_USB(); //suspend USB device
If(EP_INT_REG&EP0_INT) Handle_EP0(); //Execute control transfer endpoint 0 handler
If(EP_INT_REG&EP1_INT) Handle_EP1(); //Execute synchronous transfer endpoint 1 handler
}

Control Transfer of USB Sound Card In the host application, when performing volume adjustment, mute, etc., the USB audio driver performs a control transfer through the default endpoint 0. The primary control transmission mainly includes two steps. In the first step, the host sends a setup information to the device, describing the type of control access, and the device will perform the control access. The second step is the transmission of zero or more control data information, which is the specific information of the access. The control packet is decomposed according to the USB audio class protocol, and then the corresponding operation is performed according to the control information. For example, before playing music in a host-side application, the USB sound card receives the following two packages from the host:
Setup package 22 01 00 01 01 00 03 00
Control packet 40 1F 00

According to the USB audio class protocol decomposition of the Setup package, it can be known that the purpose of this control transmission is to set the sampling frequency of the USB sound card, and the received 3-byte control data information is the sampling frequency, that is, 8KHz. Then, before playing music, the sampling frequency of the I2S and UDA1341TS chips must be set to 8 kHz to keep in sync with the host.

I2S bus implementation method In the S3C2410 chip, the I2S interface provides three data transmission modes: normal transmission mode, DMA transmission mode, and transmission/reception mode. The system adopts the transmission/reception mode, which has dual-channel DMA function, which steals the bus control right and improves the throughput of the system. On the other hand, it can simultaneously receive and transmit audio data, that is, full-duplex mode.

In the S3C2410 chip, there are four DMA channel controllers for controlling various external devices. I2S shares two bridged DMA (BDMA) type DMA channels with other serial peripherals. The I2S interface can be operated in DMA mode by setting the I2SFCON register. The control of the FIFO register set in this mode is mastered on the DMA controller. When the FIFO is full, the data in the FIFO is processed by the DMA controller. The selection of the DMA mode is controlled by the fourth and fifth bits of the I2SCON register.

In order to make the playback and recording of the USB sound card can be performed simultaneously, that is, full duplex, data transmission uses two BDMA channels, channel 0 is used for playback, and channel 1 is used for recording, because there is no built-in DMA storage area in the BDMA of S3C2410, so A DMA buffer needs to be allocated in the SDRAM. When the audio data is played back, the audio data is first acquired by the USB bus, written into the DMA buffer, and the bus control right is stolen by the BDMA controller channel 0, written to the I2S bus through the I2S controller, and transmitted to the audio chip. The recording uses channel 1 of the BDMA controller, and its data flow process is reversed from playback.

Since the amount of processed audio data is relatively large, and the speed at which the PC receives/transmits data and the speed at which the I2S processes data cannot be completely matched, this results in playback distortion or loss of frame loss. To solve this problem, the easiest way is to use a larger ring cache. But in fact, a large buffer area requires a longer fill time, and there is a delay in use. To solve the problem of delay, a circular, multi-segment caching mechanism is used. Under this mechanism, the buffer area is divided into several blocks of the same size, and an algorithm is used to implement the ring buffer. The following describes the operation of the buffer by taking the playback of the 8 kHz/16-bit/single-channel audio stream as an example.

The USB audio class specifies a USB synchronous transmission period of 1 ms. That is, for an 8 kHz/16-bit/single-channel PCM-encoded audio stream, every 1 ms, the USB device receives a data from the host, and the packet size is 16 words. In order to keep the I2S and USB transmissions as synchronized as possible, 16 bytes can be taken as the size of a cache segment. When the USB sound card receives the data, the MCU first determines whether there is a free area in the buffer. If there is not enough buffer, skips a sample, and then copies the data in the FIFO to the SDRAM buffer.

Because the I2S DMA controller processes the data in segments, each segment is 16 bytes long. Before the DMA fetches the data, the amount of data in the buffer is determined. If there is not enough data (16 bytes), the mute data is added. And then perform a DMA transfer.

Conclusion The I2S bus-based USB sound card described in this article has been successfully implemented on the S3C2410 processor-based development board, but only realizes the most basic functions of the USB sound card. You can try to integrate MP4, U disk, etc. with USB sound card, which will be more valuable.

references
1. Samsung Inc. S3C44B0X Risc Microprocessor Datasheet. http:// . 2003
2. Philips Semiconductors. UDA1341TS datasheet.http://www. semiconductor. philips.com. 2002
3. Hyde, John, USB Design by Example. Intel.

Multi-port USB Charger

Multi-Port Charger Usb,5V2A Usb Charger,Mobile Phone Charger,Multi Ports Usb-A Charging Hub

shenzhen ns-idae technology co.,ltd , https://www.szbestchargers.com

Posted on