1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4
<link rel="STYLESHEET" href="pyalsaaudio.css" type='text/css' />
5
<link rel="first" href="pyalsaaudio.html" title='PyAlsaAudio' />
6
<link rel='contents' href='contents.html' title="Contents" />
7
<link rel='last' href='about.html' title='About this document...' />
8
<link rel='help' href='about.html' title='About this document...' />
9
<link rel="next" href="pcm-objects.html" />
10
<link rel="prev" href="module-alsaaudio.html" />
11
<link rel="parent" href="module-alsaaudio.html" />
12
<link rel="next" href="pcm-objects.html" />
13
<meta name='aesop' content='information' />
14
<title>4.1 PCM Terminology and Concepts</title>
17
<DIV CLASS="navigation">
18
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
19
<table align="center" width="100%" cellpadding="0" cellspacing="2">
21
<td class='online-navigation'><a rel="prev" title="4 alsaaudio"
22
href="module-alsaaudio.html"><img src='previous.png'
23
border='0' height='32' alt='Previous Page' width='32' /></A></td>
24
<td class='online-navigation'><a rel="parent" title="4 alsaaudio"
25
href="module-alsaaudio.html"><img src='up.png'
26
border='0' height='32' alt='Up One Level' width='32' /></A></td>
27
<td class='online-navigation'><a rel="next" title="4.2 PCM Objects"
28
href="pcm-objects.html"><img src='next.png'
29
border='0' height='32' alt='Next Page' width='32' /></A></td>
30
<td align="center" width="100%">PyAlsaAudio</td>
31
<td class='online-navigation'><a rel="contents" title="Table of Contents"
32
href="contents.html"><img src='contents.png'
33
border='0' height='32' alt='Contents' width='32' /></A></td>
34
<td class='online-navigation'><img src='blank.png'
35
border='0' height='32' alt='' width='32' /></td>
36
<td class='online-navigation'><img src='blank.png'
37
border='0' height='32' alt='' width='32' /></td>
39
<div class='online-navigation'>
40
<b class="navlabel">Previous:</b>
41
<a class="sectref" rel="prev" href="module-alsaaudio.html">4 alsaaudio</A>
42
<b class="navlabel">Up:</b>
43
<a class="sectref" rel="parent" href="module-alsaaudio.html">4 alsaaudio</A>
44
<b class="navlabel">Next:</b>
45
<a class="sectref" rel="next" href="pcm-objects.html">4.2 PCM Objects</A>
49
<!--End of Navigation Panel-->
51
<H2><A NAME="SECTION002410000000000000000">
52
4.1 PCM Terminology and Concepts</A>
56
In order to use PCM devices it is useful to be familiar with some concepts and
61
<DT><STRONG>Sample</STRONG></DT>
62
<DD>PCM audio, whether it is input or output, consists at the lowest level
63
of a number of single samples. A sample represents the sound in a single channel in
64
a brief interval. If more than one channel is in use, more than one sample is required
65
for each interval to describe the sound. Samples can be of many different sizes, ranging
66
from 8 bit to 64 bit presition. The specific format of each sample can also vary - they
67
can be big endian byte order, little endian byte order, or even floats.
71
<DT><STRONG>Frame</STRONG></DT>
72
<DD>A frame consists of exactly one sample per channel. If there is only one
73
channel (Mono sound) a frame is simply a single sample. If the sound is stereo, each frame
74
consists of two samples, etc.
78
<DT><STRONG>Frame size</STRONG></DT>
79
<DD>This is the size in bytes of each frame. This can vary a lot: if each sample is
80
8 bits, and we're handling mono sound, the frame size is one byte. Similarly in 6 channel audio with
81
64 bit floating point samples, the frame size is 48 bytes
85
<DT><STRONG>Rate</STRONG></DT>
86
<DD>PCM sound consists of a flow of sound frames. The sound rate controls how often
87
the current frame is replaced. For example, a rate of 8000 Hz means that a new frame is played
88
or captured 8000 times per second.
92
<DT><STRONG>Data rate</STRONG></DT>
93
<DD>This is the number of bytes, which must be recorded or provided per second
94
at a certain frame size and rate.
97
8000 Hz mono sound with 8 bit (1 byte) samples has a data rate of 8000 * 1 * 1 = 8 kb/s
100
At the other end of the scale, 96000 Hz, 6 channel sound with 64 bit (8 bytes) samples
101
has a data rate of 96000 * 6 * 8 = 4608 kb/s (almost 5 Mb sound data per second)
105
<DT><STRONG>Period</STRONG></DT>
106
<DD>When the hardware processes data this is done in chunks of frames. The time interval
107
between each processing (A/D or D/A conversion) is known as the period. The size of the period has
108
direct implication on the latency of the sound input or output. For low-latency the period size should
109
be very small, while low CPU resource usage would usually demand larger period sizes. With ALSA, the
110
CPU utilization is not impacted much by the period size, since the kernel layer buffers multiple
111
periods internally, so each period generates an interrupt and a memory copy, but userspace can be
112
slower and read or write multiple periods at the same time.
116
<DT><STRONG>Period size</STRONG></DT>
117
<DD>This is the size of each period in Hz. <em>Not bytes, but Hz!.</em> In <tt class="module">alsaaudio</tt>
118
the period size is set directly, and it is therefore important to understand the significance of this
119
number. If the period size is configured to for example 32, each write should contain exactly 32 frames
120
of sound data, and each read will return either 32 frames of data or nothing at all.
127
Once you understand these concepts, you will be ready to actually utilize PCM API. Read on.
131
<DIV CLASS="navigation">
132
<div class='online-navigation'>
134
<table align="center" width="100%" cellpadding="0" cellspacing="2">
136
<td class='online-navigation'><a rel="prev" title="4 alsaaudio"
137
href="module-alsaaudio.html"><img src='previous.png'
138
border='0' height='32' alt='Previous Page' width='32' /></A></td>
139
<td class='online-navigation'><a rel="parent" title="4 alsaaudio"
140
href="module-alsaaudio.html"><img src='up.png'
141
border='0' height='32' alt='Up One Level' width='32' /></A></td>
142
<td class='online-navigation'><a rel="next" title="4.2 PCM Objects"
143
href="pcm-objects.html"><img src='next.png'
144
border='0' height='32' alt='Next Page' width='32' /></A></td>
145
<td align="center" width="100%">PyAlsaAudio</td>
146
<td class='online-navigation'><a rel="contents" title="Table of Contents"
147
href="contents.html"><img src='contents.png'
148
border='0' height='32' alt='Contents' width='32' /></A></td>
149
<td class='online-navigation'><img src='blank.png'
150
border='0' height='32' alt='' width='32' /></td>
151
<td class='online-navigation'><img src='blank.png'
152
border='0' height='32' alt='' width='32' /></td>
154
<div class='online-navigation'>
155
<b class="navlabel">Previous:</b>
156
<a class="sectref" rel="prev" href="module-alsaaudio.html">4 alsaaudio</A>
157
<b class="navlabel">Up:</b>
158
<a class="sectref" rel="parent" href="module-alsaaudio.html">4 alsaaudio</A>
159
<b class="navlabel">Next:</b>
160
<a class="sectref" rel="next" href="pcm-objects.html">4.2 PCM Objects</A>
164
<span class="release-info">Release 0.2.</span>
166
<!--End of Navigation Panel-->