Wince audio-driven model Overview (4)

Source: Internet
Author: User

Mixing Processing

If you want the sound driver model of Windows CE to support sound mixing, consider the following:

1) Does the sound Device Support Hardware mixing?

2) sound equipment must work at the same sampling frequency

3) sound equipment must be able to support both recording and playing operations

 

The sound driver is responsible for audio mixing for sound collection and sound mixing. The basic principles are as follows:

1) set the sound device to a single frequency, such as 44.1 kHz and 16 bit.

2) the driver allows multiple audio streams to be opened. Each audio stream allows different sampling rates, for example, (a: 8 kHz, 8 bit B: 44.1 kHz, 16 bit)

3) audio mixing in the final data preparation phase (that is, before the DMA), the synthesis algorithm is used to perform mathematical operations on all streams to obtain the sampling frequency (44.1 kHz, 16 bits. Data is sent to codec through DMA.

4) audio mixing operations are the basic data obtained from the sampling frequency (44.1 kHz, 16 bit) of the sound equipment, then, the audio streams are allocated to different frequencies through mathematical operations.

5) note that data does not overflow during merging. When separating data, pay attention to data rate matching and data width matching.

 

Interrupt and DMA driver model
Sound systems generally use DMA as the basic means of data transmission.

The processing of the sound subsystem plays a key role. DMA sound operations generally use dual buffer

This is the case for data buffering (recording and releasing). When one buffer is occupied by DMA, the other Buffer

To improve the efficiency. Obviously, the hardware operations of the sound subsystem are typical.
Consumer mode. Therefore, the control over shared resources is particularly important.

The hardware implementation of DMA varies slightly with the CPU. Some embedded chips are simple and do not support the chain connection of DMA addresses, while others do, but do not affect the specific implementation. They share the following points:

L generally, a DMA instance has n sub-channels.

L each channel can operate independently or shut down without interfering with each other. It has its own state machine.

L DMA uses a total DMA interrupt to notify the CPU, and the software is responsible for finding a specific channel.

 

If many drivers in a system use DMA, a DMA engine is required

Coordinate the operation of DMA; otherwise, the driver will compete for DMA. If only one driver uses the DMA system, the obstacles to implementation will be much smaller.

Two channels are used to independently perform recording and releasing operations, and each channel adopts a dual buffer strategy, to ensure that the DMA and CPU can work almost simultaneously without affecting each other. In addition, an audio driver that supports multiple streams at a high level should also be aware that the operations on the hardware device DMA should be mutually exclusive.

In the implementation process of the actual driver, this dual-channel and dual-buffer driver has many details to pay attention to. It is important to handle several types of relationships:

1) Relationship between hardware DMA and hardware codec

In the whole sound recording data transmission system, there are:

APP buffer à DMA buffer ß à I2S (ac97) FIFO ß à Codec

The app is responsible for providing data, and the DMA is responsible for data transmission. In fact, the data is transferred to a FIFO similar to I2S or ac97. I2S is responsible for transmitting data in frames and restoring the data by codec. Recording is vice versa.

Generally, I2S and CODEC should be prepared before DMA is started. The sequence of DMA and I2S startup often leads to data loss, which is a concern.

 

2) Relationship between DMA and app Buffer

During Restoration: the app often provides large data packets, such as 16 KB. Due to the design requirements, the DMA usually gets 4 kb, which is relatively large.

The conditions for starting the DMA Operation are as follows:

--- Fill two DMA Buffers

--- Prepare I2S

 

When the DMA processing is completed, there will be a DMA interruption. In the interrupt processing, pay attention to the following issues:

--- Start the second buffer and continue the DMA Operation. If it cannot be started, the DMA will be stopped.

--- The CPU is responsible for checking whether there is enough data for DMA. If yes, it is sufficient to fill in several DMA buffers.

 

DMA shutdown condition:

--- No more buffer is available for handling

--- Forced shutdown

 

In practice, you need to take the DMA startup and shutdown conditions, because the drivers are generally run in multiple threads, you must pay attention to the mutex during the DMA Operation to prevent exceptions or deadlocks.

 

In addition, the size of the DMA buffer is directly related to the sampling frequency, which is very important for some real-time applications. For example, if a 20 ms package period is required for VoIP, the DMA buffer size needs to be limited to control the interrupt time, and periodic package data is provided for VoIP in a timely manner.

 

3) Relationship between multiple DMA Channels

If both the recording and the playing channel are enabled, you must identify the data of the audio recording and the playing channel during DMA interrupt processing, and enable the second buffer of the respective channels in a timely manner, prevents data loss or pause.

 

Related Article

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.