This is a Java application that lets you see the effects of
sampling rate and bits-per-sample on the shape of an analog waveform
when it is digitized. Here is a screen shot. (You can increase
your browser’s text size to zoom in.):
When sound is recorded digitally, a microphone transforms
changes in sound pressure level to voltages that are a direct
analog of the sound pressure level as it varies in time. To
digitize the voltage, an analog to digital converter (ADC)
samples the voltage at a certain rate, converting each voltage
sample into a binary number. To reconstruct the sound later,
the binary numbers are fed into a digital to analog converter
(DAC) at the same rate at which they were recorded. The DAC
outputs a fixed voltage for each binary number it receives; a
loudspeaker or headphone causes sound pressure level changes in
proportion to the voltages it receives from the DAC.
When you run the program, you will see three main
panels:
- The left panel is labelled “Sampled Voltages.” The
upper part represents the points at which an analog sine wave would
be sampled, with the frequency of the sine wave and the sampling
rate being controlled by the sliders below it. The horizontal
(time) axis is scaled so that exactly one cyle of the sine wave fits
onto it.
There is a “Show Samples” button in the
lower right part of the application that will display the numerical
values of each of the sample points: the time of the sample in
microseconds, the amplitude of the sample in volts, and the binary
encoded representation of that amplitude. The time is relative to
the beginning of a cycle; the amplitude assumes the signal has a
peak-to-peak voltage ranging from -1.0 to +1.0; the binary value is
an unsigned integer (see below).
- The center panel shows how voltage ranges would be
digitized into unsigned binary numbers, given the number of
bits per sample set by the slider below it. This table can be
used to see how the third column of the “Show
Samples” display was derived from the second column of
that display.
The slider below the table controls the
number of bits per sample. If you try to set this value too
high, (a) the program can take a very long time to respond to
inputs because it has so many sample values to compute, and
(b) the pixel height of the Generated Waveforms panel limits
how many different intensity values can be represented.
- The right panel shows the output waveform that would be
generated if each sample value is converted to a voltage for
the duration of one sampling interval.
Downloading
The application consists of a Java jar file, so you
need to have the Java runtime
environment installed on your computer to run it. Download
the jar file: AudioSampling.jar. Save it to
a convenient spot, such as your desktop. You can then run the
application by double-clicking on it (Windows, OS X) or using the
command, "java -jar AudioSampling.jar" (all systems). Note: if
your browser downloads the file as AudioSampling.jar.zip, just
rename it to AudioSampling.jar; don’t unzip it.
Start-up and run-time options.
If you run the program from the command line, you can specify
initial values for the signal frequency, sampling rate, and bits
per sample on the command line. Use
name=value pairs, where name is
“frequency”, “rate”,
“bitspersample”, or “bits” (the last two
are equivalent). Also, the program’s audio playback
feature can be disabled by specifying the “disableAudio”
option on the command line.
Using either command line arguments or the controls in the
application, the signal frequency may be set to a value between
0.1 and 25 KHz. (The upper limit of human hearing under ideal
circumstances is about 20 KHz.) Sampling rate values may be set
to any value in the range of 0.1 to 50 KHz, but cannot be set
any higher than your computer’s audio system will support,
normally 44.1 KHz. Bits per sample can range from 1 to 20, but
values large values will produce no visible effect in the
generated waveform, and might slow the program down
considerably. Like the sampling rate, this parameter cannot be
set higher than the maximum value supported by your
computer’s audio system.
Audio Playback
The program can generate a tone based on the signal
frequency, sampling rate, and bits per sample. There are a few
thing to note about this feature:
- The program has been tested successfully on a number of
computers, both Windows and Macintosh. But on the computers
in the “TREE” domain at Queens College (and presumably
other computers as well), the program’s audio output is
interrupted by short drop-outs, leading to a strong buzzing sound,
making this feature virtually useless on those computers.
(Fix the problem and win a prize!)
- The tone you hear is not the displayed waveform repeated over
and over because doing that would produce an intensity discontinuity
at the end of each cycle whenever the tone’s frequency is not
an exact multiple of the sampling rate. Rather, the program
generates a continuous stream of output intensity samples from a
continuous sine wave. When the tone’s frequency is not an
exact multiple of the sampling rate, this means that the sampled
values will drift throughout the waveform from cycle to cycle, and
as a result you might hear a tone where the waveform on the screen
appears to be too degraded to produce one.
- The program produces lower sampling rates by a process called
“downsampling.” That is, each sample’s intensity
is sent to the computer’s audio system a number of times based
on the ratio between the computer’s sampling rate and the rate
you select. The control for selecting the sampling frequency limits
you to selecting integer divisors of the computer’s sampling
rate instead of arbitrary values.
In addition, lower bits per
sample are produced by masking off low order bits in the samples,
not by actually changing the audio system. That is, the program
never actually modifies the computer’s audio sampling rate and
bits per sample.
- Note that sub-optimal parameter values will often produce
“wrong” tones, not just lower quality ones.
These sounds are generally the natural result of a digital
sampling artifact called “aliasing.”
Source Code
The source code for the application, along with some classes
for experimenting with the Java Sampled Audio package, are
embedded in the jar file. You can import the jar file
as an Eclipse project if you want to work on the source code instead
of just running it.