ALSA Lib Basic concept

Source: Internet
Author: User

1.channel

Channel, which is the number of channels we know. Left/right channel, 5.1channel, etc.

2.sample

A sample is a single value that describes the amplitude of the audio signal at a single point in time, on a single cha Nnel.

Sample is sampled once, the usual sample bit refers to a channnel, the number of bits sampled at a time (common sample bit 8/16/24/32bits)

3.frame

When we talk about working and digital audio, we often want to talk about the data that represents all channels at a sing Le Point in time. This was a collection of samples, one per channel, and is generally called a "frame". When we talk about the passage of time in terms of frames, it roughly equivalent to what people when they measure in term s of samples, but are more accurate; More importantly, when we're talking about the amount of data needed to represent all the channels at a-point-in-time, its The only unit is makes sense.

A frame is a sample bit on all channel at a time of sampling. frame = channels * (sample bit).

4.peroid

A period is the number of frames in between each hardware interrupt.

Whenever there is a peroid size frame space in hardware buffer, the hardware interrupts to notify ALSA driver to write data to and from the hardware.

5.buffer size

This determines what large the hardware buffer is.

Hardware buffer size is made up of multiple peroid. Buffer size = peroid Size * peroids.

6.Data Access and layout

Interleaveda:data layout arrangement where the samples of each channel that would be is played at the same time follow each o ther sequentially. See "Non-interleaved"

Non-interleaveda:data layout where the samples for a single channel follow each of the other sequentially; Samples for another channel is either in another buffer or another part of this buffer. Contrast with "interleaved"

Within a period (interleaved and non-interleaved are lined up in a period) , the data is in accordance with Channel1 row Channel2, or a frame of a frame to row (frame in the ALSA refers to a sampling time, Two channel data put together is a frame) is interleaved.

7.Hardware parameter

These is parameters that directly affect the hardware of the audio interface.

Hardware parameter is a function of the sound card hardware, including sample rate, sample format, interupt intervals, data access and layout, buffer size.

8.Software parameter

These is parameters that control the operation of the device driver rather than the hardware itself. Most programs this use the ALSA Audio API would not need to set any of the these; A few would need set a subset of them.

Software parameter is a function of Alsa core. Typically used to control when-to-start the device, what-does about xruns, Available minimum space/data for wakeup,transfer chunk size.

8.1 When to start the device

When your open the audio interface, ALSA ensures that it's not active-no data are being moved to or from its external con Nectors. Presumably, at some point you want this data transfer to begin. There is several options for what to do this happen.

The control point here's the start threshold, which defines the number of frames of space/data necessary to start the device automatically. If set to some value and than zero for playback, it's necessary to prefill the playback buffer before the device would s Tart. If set to zero, the first data written to the device (or first attempt to read from a capture stream) would start the Devic E.

You can also start the device explicitly using snd_pcm_start , but this requires buffer prefilling in the case of the playback stre Am. If you attempt to start the stream without doing this, you'll get-epipe as a return code, indicating that there is no D ATA waiting to deliver to the playback hardware buffer.

We can use API Snd_pcm_sw_params_set_start_threshold to set when to start the sound card. For playback, assuming that the first set of start threshold is 320, then that is, when the user calls Writei, the data written will be temporarily present in the ALSA drive space, when the data volume reaches 320 frames, the ALSA driver begins to write the data to hardware Buffer and start the DA conversion.

8.2What to does about Xruns

If an xrun occurs, the device driver could, if requested, take certain steps to handle it. Options include stopping the device, or silencing all or part of the hardware buffer used for playback.

The Stop threshold

If the number of frames of data/space available meets or exceeds this value, the driver would stop the interface.

The silence threshold

If the number of frames of space available for a playback stream meets or exceeds this value, the driver would fill part of The playback hardware buffer with silence.

Silence Size

When the silence threshold level was met, this determines how many frames of silence was written into the playback hardware Buffer

Xrun refers to the sound card period one, triggering an interrupt, tells the ALSA driver, to fill in the data, or read the data, but the problem is that the ALSA read and write operations must be called by the user Writei and Readi will not happen, it does not cache the data. If no user calls Writei and Readi at the top, then the overrun will be generated (when recording, the data is full, not yet read by the ALSA driver) and underrun (need data to play, ALSA Drive does not write data), collectively known as Xrun.

When xrun occurs, you can stop audio interface when the free space exceeds the stop threshold.

You can also set silence threshold to hardware buffer when the free space exceeds silence threshold.

8.3 Available minimum Space/data for wakeup

Programs that use poll(2) or to select(2) determine when audio data is transferred To/from the interface may set this to con Trol at "relative to the state of the hardware buffer", they wish to is woken up.

This software parameters is only used in Interrupt-driven mode. This mode is ALSA drive layer, not hardware interrupt. it means that when the user uses snd_pcm_wait (), the actual package is the system's poll call, indicating that the user is waiting, then waiting for what? For playback, is waiting for the sound card below the hardware buffer has a certain amount of space, you can put new data, for the record, is waiting for the following new data acquisition of the sound card reached a certain number. This is a certain number, is to use Snd_pcm_sw_params_set_avail_min to set, Unit is frame.

8.4 Transfer Chunk Size

This determines the number of frames used when transferring data to/from the device hardware buffer.

ALSA Lib Basic concept

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.