Design of MP3 file playing System Based on uC/OS-II

Source: Internet
Author: User
Design of MP3 file playing System Based on uC/OS-II
[Date:] Source: China Power Grid Author: Xiang sahui, Chen shengyun, Ren Hua [Font:Large Medium Small]

 

 

1 Introduction

In recent years, MP3 audio products have been favored by consumers, and high-quality sound effects are an important trend in the development of MP3 audio products. Software Decoding and hardware decoding are generally used for MP3 file decoding. Hardware decoding is simple, but hardware costs need to be increased. Software Decoding requires a lot of CPU time, which is difficult to implement, but it is low in cost and flexible in processing. As long as the CPU has enough processing speed, it is a good choice. This article introduces the hardware and software design of the MP3 file playback system, using the EP9315 processor of Cirrus Logic and the UDA1341 decoder, the MP3 decoding principle, playing function and hardware interface initialization based on μC/OS-II open-source real-time operating system are introduced.

2 MP3 encoding/decoding principle

MP3 is the abbreviation of MPEG-1 Atdio Layer-3, which is a complete set of Audio Encoding algorithms based on sensing. This algorithm applies the psychological acoustic model to achieve a compression ratio. The psychological acoustic model is applied to human ears to maximize the quality of the original voice. The MPEG-1 Audio Encoding object is 20Hz ~ The bandwidth of Hz is called the sub-band coding (SBC ), this achieves the goal of compressing sound data and keeping the original sound quality as much as possible. SBC encoding objects are not limited to voice data and a sound source. The specific idea is: first, transform the sound data in the time domain to the frequency domain, quantify and encode the sub-band components in the frequency domain, and determine the sample Accuracy Based on the psychological acoustic model, so as to compress the data volume. Based on the masking feature of the auditory system, the theory of the sub-band encoding mainly uses the masking feature in the frequency domain to reserve the signal bandwidth during the encoding process, but discards the masked signal, therefore, the decoded (decoded, reconstructed) Sound Signal is different from the pre-coded sound signal, but it is difficult for human auditory systems to tell their differences. Therefore, for the auditory system, This compression is "lossless compression ".

After the MP3 file is opened, the player first tries to synchronize the frames, then reads data such as the channel information and gain factor, and then performs the Hoffman decoding. At this point, the decompressed data has been obtained. However, these data cannot be played, and they are still in the frequency domain. To play back the data, you need to change it from the frequency domain to the time domain through specific means. Then, the three-dimensional processing, anti-sawtooth processing, IMDCT transformation, IDCT transformation, and window sliding processing are performed respectively. In this way, the data can be converted to D/A and played back.

Decoding MP3 songs is a very complex process, which can be completed through the Start_mp3_decode () decoding function. In addition, you also need to provide data to the decoding function, initialize the audio interface, and initialize the playing process.

3 system hardware design

3.1 System Structure Analysis

This system takes EP9315 as the core, including the UDA1341 stereo audio codecs, SDRAM, and Flash Memory of Philips. The processor uses the IIS interface to control the transmission of audio data between the system memory (SDRAM) and UDA1341. UDA1341 is configured and controlled through the L3 control port. In this design, the MP3 system adopts a USB Host structure and USB flash drives are required for use. The system structure 1 is shown in.

3.2 audio decoder Interface

IIS (inter-IC Sound) bus is a serial Digital Audio bus protocol proposed by Philips. It is a multimedia-oriented Audio bus dedicated to data transmission between audio devices, providing sequential connections to standard codecs for digital stereo. The IIS bus only processes sound data, and other signals (such as control signals) must be transmitted separately. To minimize the number of circuit leads, IIS uses only three serial buses to provide time-sharing data lines, field selection lines, and clock signal lines.

The hardware design of the entire audio system is mainly the connection between the CPU and the decoder. The system uses the IIS-Based Audio bus UDA1341 audio codecs from Philips. UDA1341 supports the IIS bus data format. It uses bit-element Stream Conversion Technology for signal processing and provides Programmable Gain Amplifier (PGA) and digital automatic gain controller (AGC ). UDA1341 provides two sets of audio signal input interfaces, each of which includes two sound channels. Because IIS bus only processes audio data, UDA1341 also has a built-in L3 bus interface for transmitting control signals. The L3 interface is equivalent to the mixer control interface, which can control the bass and volume of the input/output audio signal. The L3 interface is connected to three universal GPIO Input and Output pins of EP9315. EP9315 has a built-in IIS Bus Interface of up to 6 channels, which can be directly connected to a 16-bit stereo decoder. It contains three transmission channels and three receiving channels. EP9315 supports 12 independent DMA channels, 10 of which are used for data transmission between the peripheral module and the memory. The other two channels are used for data transmission between the memory. As shown in figure 2, the IIS Bus signal of EP9315 is directly connected to the IIS signal of UDA1341. The L3MODE, L3CLOCK, and L3DATA pins of the L3 interface are connected to EGPI012, EGPIO11, and EGPIO10 universal data output pins of EP9315, respectively, use these three I/O ports to simulate all the time series and protocols of the L3 bus for control.

4. Software Design

4.1 embedded real-time operating system μC/OS-II

For most mobile devices, using open-source operating systems μC/OS-II is the best choice. The μC/OS-II is a complete, portable, solidified, and can be laid out to occupy the first real-time multi-task kernel. μC/OS-II is roughly divided into kernel, task management, time management, task synchronization and communication, and CPU interface, among which task management is closely related to task operations, including task creation, deletion, suspension, and recovery. Task synchronization and communication include the signal mailbox, mailbox queue, and time mark. It is mainly used for mutual association between tasks and access to critical resources.

Multi-task management of 4.2 μC/OS-II Kernel

In addition to good stability and security, μC/OS-II is mainly for the management of multi-task, can manage up to 64 tasks. In addition to eight white tasks, your applications can have up to 56 tasks.

In a multitasking system, the kernel is responsible for managing tasks and communicating tasks. The basic service for Kernel improvement is task switching, which is managed by the real-time kernel. A task has five States. At any given time point, the task state must be one of these five States: Sleep, ready, running, suspended (waiting for an event to happen), and interrupted.

μ C/OS-II is always the one with the highest priority in the ready state task. You can use the task-level scheduling function OSSched () or the interrupt-level scheduling function OSIntExt () to find it in the task readiness list OSRdyTb. After determining the readiness state task with the highest priority, if a task with a higher priority needs to be run, OS _TASK_SW () is called to complete the actual task switching.

4.3 μC/OS-II Task Communication

μC/OS-II has three methods for data sharing and task communication: semaphores, mailboxes, and message queues. Semaphores are two-value or counting volumes used to indicate the occurrence of one or more events. Or, it is used to achieve mutually exclusive access to shared resources. The task call function OSSemPend () waits for a semaphore and sends a semaphore using OSSemPost. Both the mailbox and Message Queue use the pointer variable communication mechanism in the μC/OS-II. The mailbox contains a pointer pointing to a data structure containing a specific "message". You can also use the mailbox as a binary semaphore to achieve mutually exclusive resource access. Message queues can be seen as arrays composed of multiple mailboxes, but they share a list of waiting tasks. The data structure pointed to by each pointer can be set according to the specific application. This system contains five tasks: play, pause, stop, control volume, and download. Set the corresponding task Stack and priority for each task. The download task has the highest priority, and the other four tasks have the highest priority from high to low to stop playing (stop-task) pause-task, control volume-task, and plav-task ). In this way, when playing (play-task) Running State, other tasks can also obtain CPU control and complete other functions during playing.

The ARM processor has an audio file decoding library that can effectively decode mp3-format songs and output 16-bit stereo PCM data. In play-task, call the int play (struct audio_play * Play) function to play a song. struct audio_play * play is a custom audio_play pointer. Call voidwrite_dev () during playback to initialize IIS interface and dma2. The following code implements software playback:

5. Interface initialization when running a playback task

At the beginning of the system, you need to initialize the hardware functions. The initialization of each interface sets the corresponding control register implementation according to the specific execution requirements of the task. In the arm storage system, all I/O ing is the address space, which is easy to implement read/write operations. Note the time sequence of the L3 control port for uda1341 initialization. Because the L3 control port is controlled by the general port of the arm device, it is necessary to program the time sequence of symbol l3 In the process of transmitting control information.

The main code for IIS Initialization is:


6 conclusion

The system makes full use of the multi-task management and task communication functions of μC/OS-II. A MP3 file playing System Based on EP9315 processor is proposed, which supports Serial Port debugging and USB interface to download songs. Because the system uses the uda1341 codec device and has an audio input interface, the recording function of the system can be expanded.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.