CS074: The Digital World
Lab 2
Due Wednesday, February 4
Here are several exercises using the Binary Editor, one involving
altering text, the other altering, and synthesizing, audio. In
all cases you should submit the product (the altered text and wave
files), and a writeup explaining EXACTLY what operations you perfromed
to achieve the result.
1. Take the text of 'The Telltale Heart' and modify it so that
all letters are lower-case, and so that the only character used that is
not a letter is the space character. You should save the result
as a text file with a different name. Even though it is now all
one long line, you should still be able to view it with the Text
Editor, by using the Word Wrap option.
Solution: I used the following
steps.
(a) Using the Modify screen, add 32 to
all cells with values in the range 65 to 90. This converts all
upper-case letters to lower-case.
(b) Set all cells with values in the
range 0 to 96 to 32.
(c) Set all cells with values in the
range 123 to 255 to 32. These last two steps change
everything that is not a lower-case letter to the space character.
(d) Finally, use the load/save screen
to save it as a binary file, which I called telltale_modified.txt. If you
try to display this in your Web browser, it will be just one humongous
line, but if you download it and view it in, say, the Text Editor, with
the Word Wrap option selected, you can see the result.
2. Take the audio file flute.wav, and modify it so that the second half
is played before the first half. Use the Save as Wave file option
to save the result under a different name. (This will attach the
appropriate header to the file.) It is not a bad idea to first
remove the original 40-byte header (using the Delete control) before
further processing the file.
Solution: That 40-byte header is really 44 bytes long, but it
doesn't really make very much difference to the sound if you leave it
in. Here's how I did the problem.
(a) The entire file is 72244 bytes
long. So I copied the range of cells from 0 to 36122 to the range
beginning at 72244, which is the first cell after the end of the
file. (It's important NOT to use 72245.)
(b) I then deleted the cells in the
range 0 to 36122.
Here's the result.
This next one takes some explaining: Our audio files use an 8-bit
quantity to represent the amplitude of each sample, while a CD
recording uses 16 bits: Distinguish a larger number of different
amplitude levels leads to better-quality sound. What if we wanted
to hear the effect of using fewer
bits to represent each sample? Here's an idea of how to do
this---take the original file, divide each sample by 8, and then
multiply each sample by 8. If you start out with a sample value
whose binary representation is, say,
11011011
then division by 8 gives
11011
(because the remainder is thrown away), and multiplication by 8 give
11011000
The amplitude values have about the same magnitude as before, but there
are fewer different levels distinguished: in effect we are using
5 bits to represent each sample instead of 8. (If you didn't perform
the step of multiplying by 8, then the sound would be much fainter, but
we're still only using 5 bits of information.)
3. Try this out, using 5 bits as in the example, 6 bits, 4 bits,
etc. At what point is the sound quality noticeably worse than the
original? Save the results of your experiments using the Save As
Wave file option, and name them appropriately (for instance
flute4bits.wav, flute5bits.wav, etc.)
Solution: You make the files by
dividing and then multiplying by 2 (7 bits), dividing and then
multiplying by 4 (6 bits), etc., all the way up to dividing and then
multiplying by 128, which uses only 1 bit to record each
amplitude. Here are the results:
flute7.wav flute6.wav flute5.wav flute4.wav flute3.wav flute2.wav flute1.wav
I think I start to notice the
distortion (in the form of added static-like noice) about
flute5.wav. But I find it astonishing just how well you can hear
the music when only ONE bit is used to represent the amplitude.
4. Create a synthetic sound. For instance, if you had a sample
file that had the value 0 for 1/1000 second, then 50 for 1/1000 sec,
then 0 again for 1/1000 sec., etc., you would have a so-called square
wave with a frequency of 500 hertz (since it goes through a complete
cycle every 1/500 second). Create a square wave approximately two
seconds in duration with a pitch of approximately 100 hertz (which is
rather low-pitched). Save the result as squarewave.wav using the
Save As Wave File option.
Solution: To produce a 100 hertz
tone, the length of each cycle will be 11025/100=110 bytes. So we will
have 55 bytes of 0's, 55 bytes of 50's, etc. We can just load any
old file into Binary Editor, then set the first 55 bytes to 0,
and the next 55 bytes to 1. This is accomplished with the Set
option in the Modify menu.
We then proceed to copy the first 110
cells to the range beginning at cell 110, doubling the size of the
file. We then repeat with 220, 440, 880, 1760,
3520,7040,14080. In all we need eight doublings. At the end we
will have 28160 samples, which is about 2.5 seconds.
Here's the result.
What to hand in: A zipped folder containing your .wav files from
problems 2,3, and 4, your text file from 1, together with a document
explaining carefully how you did all the problems. You should
also hand in a printout of this document.