2.3 Simplifying circuits
3.4.5 Sound
Sound is another important medium to represent in modern computing systems. Sound consists of vibrations in the air, which can be modeled as a graph of amplitude over time.
3.4 Representing multimedia 31
amplitude time
(This is a very simple, regular amplitude graph. The graphs you frequently see, especially for human speech, tend to be much more irregular and spiky.)
One way of representing the sound is to divide the amplitude graph into regular intervals and to measure the graph’s height at each interval.
amplitude time
Then, we can store the height of the subsequent intervals. A system can interpolate between the sampled points to reproduce the original sound.
This technique of sampling is exactly the one used by CDs, which include samples of the amplitude graph taken 44,100 times a second. (The designers chose 44,100 times because the human ear can sense tones with a frequency of up to 22 KHz. That is, the human ear can handle tones that go from down to up to down again 22,000 times a second. By sampling at twice that rate, they get both the “down” and the “up” of such cycles so that the sound producer, which interpolates between the samples, can reproduce the sound wave.) CDs use 16 bits to represent each sample’s height, and they include samples for both the left and the right speaker to achieve a stereo effect, for a total of 32 bits per sample. Thus, to store music in the CD format, you need megabytes for each minute of sound:
samples sec bits sample byte bits MB bytes sec min MB min Since CDs typically store around
MB, they can hold around 65 minutes of sound. (Some CDs can hold
slightly more data, providing for somewhat longer recordings.)
CDs provide high-quality sound through a high sampling rate, but this contains much extraneous infor- mation that most ears can’t hear. It leaves a lot of room for more efficient representations of sound data.
The MP3 audio format is a particularly popular alternative. It uses a more complex understanding of how the human ear perceives sound. The human ear works by recognizing dominant frequencies in the sound it receives. Thus, to convert a sound to MP3 format, computers analyze a sound for the dominant sine waves that add up to the original wave.
amplitude time
Computers would ignore any frequencies beyond the ear’s limit of 22 KHz, and they give some preference to waves in the range where the ear is most sensitive (2–4 KHz). Then, it stores the frequencies for these sine waves in the MP3 file. The result is a file representing the most important data that is needed to reproduce a sound for the human ear. Through this, and through some more minor techniques, the MP3 files tends to be approximately the size of the simple sampling technique used for CDs.
Chapter 4
Computational circuits
We saw several simple circuits in Chapter 2. But all these circuits did was to compute some weird function of a combination of bits. Why would anybody want to do that? I can forgive you if you felt underwhelmed. Now that we understand the basics of data representation, we can explore more useful circuits for per- forming computation. In this chapter, we examine circuits for adding numbers together and circuits to remember data.
4.1
Integer addition
First we’ll examine a circuit for adding integers, something that we can certainly agree that a computer needs to do.
To work toward such a circuit, we first think about how we would do this on paper. Of course, we already understand how to do this for base-10 numbers. The computer will add binary numbers, but we can still use a similar approach. Suppose, for example, that we want to add 253
11111101 and 5 101 . 11111 1 11111101 + 101 100000010 The result here is 100000010
258
.
In Section 3.2.3 we saw that to add numbers in a two’s-complement format, we can simply perform regular addition as if they are unsigned and then throw out any extra bits (like the uppermost bit in the above example). The above, then, could also be understood as the computation of , which would yield a
solution of . Thus, though we will build a circuit for unsigned integers, our circuit will apply to adding
two’s-complement signed integers too.
The addition technique is fine on paper, but the computer doesn’t have the luxury of a pencil and paper to perform computation like this. We need a circuit. We’ll break the design process into two smaller pieces. The first, called a half adder, is for the rightmost column. (The box is intentionally drawn empty; we’ll see what circuit it represents soon.)
sum out c adder half a b
It takes two inputs, representing the two bits in the rightmost column of our addition, and it has two outputs, representing the bit to place in the sum’s rightmost column ( ) and the bit to carry to the next column
().
For each of the other columns, we’ll have three inputs: the carry from the previous column ( ) and the two bits in the current column. We’ll call the circuit to add these three bits together a full adder.
a b sum out in c c full adder
The two outputs have the same meaning as with the half adder.
The half adder
To build the half adder, we consider the four possible combinations of bits for the two inputs. We can draw a truth table for this.
0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0
Notice that the output is the AND function on and
. The output is called the exclusive-or
function (abbreviated XOR), so named because it is like an OR, but it excludes the possibility of both inputs being 1. We draw a XOR gate as an OR gate with a shield on its inputs.
To design a XOR gate using AND, OR, and NOT gates, we observe that the sum-of-products expression is
, from which we can construct a circuit.
sum a
b
With a XOR gate built, we can now put together our half adder.
sum out c b a
Incidentally, many people use use a circled plus sign to represent XOR in Boolean expressions. In this system, represents XOR .