Implementation: 3.2.1 Sound Card
Implementation: 3.2.1 Sound Card
Implementation
3.1 Overview
In this chapter we explain the practical implementation of the
system. The chapter is divided into two main parts, first the part of
the hardware implementation describes roughly how the
computer’s sound card works, as well as what has been done to
adapt the program to different types of computers.
The second part describes the implementation using Matlab.
Section 3.3.1 gives a brief introduction to Matlab, and mentions
some of the benefits that was utilized in the program. Section 3.3.2
explains the foundation of the main loop and finally Section 3.3.4
thoroughly explains the graphical user interface.
The base of the program is the main loop. A flowchart of the main
loop can be seen in Figure 3.3. The simplified version of the
structure of the loop can be seen in Figure 3.4. This pseudocode
describes the test bench upon which the main loop is built. The
program clearly has three phases. The program is first initialized,
the “Audiorecorder” object is created, variables are loaded as well
as memory for vectors and arrays is preallocated. Then, in the main
loop, the sound is sampled and divided into frames. At the end of
the loop there is usually either some plots created or some sound
is sent to tha audio output.
Figure 3.3: The loop that runs while the On/Off toggle button is pushed.
Figure 3.4: Pseudocode of the base of a testbench, the foundation of the main
loop.
The middle of the loop is where the signal is processed, either by
filtering or by computing the FFT is performed. At the end of the
program there is a terminate phase, where in this case the
“Audiorecorder” object is released.
Since this program was used for educational purposes there should
be different ways to construct and filter the audio. The different
ways are listed below.
• The main way of constructing a filter is by typing in the coefficients of the
filter an
and bn in the text boxes of the “Own filter design”-control panel.
• Create a Matlab filter in the “Matlab filter”-control panel.
• Create a Matlab function (see Section 3.3.4) and typing the
name of the function in the “Own filter function”-text box in
the “Filter source” control panel.
When it comes to designing the filter for the “Own filter design”,
it is up to the user to find the coefficients. Matlab then uses the
function “y = filter(b,a,x)” to calculate the output y from input
signal x with the help of coefficients b and a.
“Matlab filter” uses the “Filter Design assistant” to calculate a
filter object which is also filtering with the help of “y =
filter(filterobject, x)”. This provided tool Matlab includes design
methods such as Equiripple, Kaiser window, Butterworth,
Chebyshev Type I and Type II and Elliptic.
The prefabricated filters have various design methods. The basic
FIR and IIR filter types have been created with the help of Matlab’s
“filterbuilder”, which is slightly more com- plicated than “Filter
Design Assistant”.
On/Off
The On/Off control unit consists of three main interaction sources.
There is the On/Off toggle button which starts the main loop
described by the flowchart in Figure 3.3. There is also a pause
toggle button which can be used at any point to pause and restart.
The pause button activates a spin loop in the main loop. While
the pause button is pushed the user could enter either the
magnified timeplot GUI or the magnified FFT plot GUI. Third there
is the Reduced visual playback tick box which is ticked by default.
This is described in more detail in Section 3.2.2.
Source
There is the option whether to sample from a file or whether to
sample from the mic input of the computer. Both of them use the
same algorithm and both of them process the music in real time.
The mic input is the default and the file input is merely thought
of as a complement to increase the flexibility of the program. The
user chooses how to
sample the music and if the file input is choosen, the file name has
to be entered as text in the “File name”-text box. The entire file
name has to be entered, including the file type extension.
Miscellaneous
Setting the sampling rate is only an option while the filter
source is set to mic input. When the main loop is running, the
sampling rate text box is blocked from usage but the user can
still read out which sampling rate is used. It is the file’s sampling
rate that sets the sampling rate at which the program samples the
sound. The default is 44100 Hz. The gain works in a similar manner
as a volume knob. By pressing the arrows, the gain multiplier can
be increased or decreased. The user can also choose to enter a
non-integer value by typing the value into the textbox.
Figure 3.7: The misc control panel.
Matlab filter
When students will construct filters in the future, there is a great
chance that companies or others will have prefabricated filter
algorithms and programs for this purpose. Also, when discussing
filter properties with coworkers and fellow students it is important
that the terminology is correct. The “Matlab filter” panel lets the
student construct a filter and apply it without the tedious works of
calculating the coefficients by hand. The “Create Matlab filter”-push
button allows the user to create a filter using Matlab’s “Filter
design assistant” by specifying parameters to meet requirements.
This gives an incentive to learn the terminology used in filter
specifications as well as common construction algorithm names.
The “Change Matlab filter”-push button lets the user change the
parameters of the already constructed filter and “Visualize Matlab
filter” opens up the “Filter Visualization Tool” to acquire the
information already mentioned in Section 3.3.4. The text below
gives some simple information about the filter, but the text string
mostly aims to indicate whether a filter has already been created
or not.
Figure 3.9: The matlab filter design panel.
Filter source
The filter source control panel allows the user to choose the filter source. The
options are:
• Own filter design
• Matlab filter (“Let Matlab do it”)
• Prefabricated filter
• Own filter function
“Own filter design” and “Let Matlab do it” uses the filter methods described in
Section
3.3.4. “Prefabricated filter” lets the user choose between a
selection of filters from a pop- up menu, some FIR filters, some IIR
filters and some simpler filters with sound effects. “Own filter
function” lets the user construct a function script in Matlab which
can receive an input vector, perform filtering or whatever the user
wishes to do with the samples, and return a vector of the same
size. This option is suitable if the user wishes to use more
complicated filters. This invites the user to play and create
filters with sound effects, and cascaded filters with endless
possibilities. The only criterion to create such a filter is as
mentioned, that the size and shape are the same for input and
ouput signal, and the function header must be as described in
Equation 3.1 with a header that handles an indexation variable. The
reason for this is that many more advanced filter such as a flanger
for instance has a periodical feature to create these sound effects.
When Matlab divides the samples into frames, these frames
represent such a short period of time in a song that these periodical
features do not have time to create an effect. A flanger has a
periodical feature with a period of around 20-40ms[10], a frame of
1024 samples sampled at 44100Hz
represents a time from t = 0 seconds
44100 to t = 1
·1024 = 0.232
seconds. The flanger then needs to keep track of its own
periodicity when the next frame arrives so that the effect
can continue without interruptions that would worsen the sound.
The filtering method can be changed anytime while the program is
running, even if the main loop is activated. To activate filtering,
the tick box “Apply filter” needs to be ticked.
function y = testfilterfunction(audioIn, index)
(3.1)
Figure 3.10: Filter source control panel.
Impulse response
The user can plot a simple plot in the axes inside the “Impulse
response” panel. The interface is very limited and there are no
possibilities for interaction. The panel is merely there to give the
user a rough idea of how the impulse response of the filter might
look like. The reason for this is that in Matlab’s “Filter Visualization
Tool” there already are possibilities of acquiring this information.
Spectral analysis
The spectral analysis control panel is designed to communicate to
the user the sufficient information needed to be able to know what
type of filter is needed. The top axes plots the FFT of the input
signal and the bottom the output signal. It is possible to change the
visible range. However only the x-axis can be changed and only
while pause is activated. So either the program has to be paused or
the “Spectral analysis” pause toggle button needs to be pressed. If
the user needs more information, while pause is active (s)he can
press the magnifying glass, opening up the spectral analysis’s GUI.
The GUI is seen in Figure 4.2. With this interface open the user
can change both the limits of the x-axis and the y-axis to have a
closer look. However, only information from the present frame is
available.
Figure 3.12: The spectral analysis control panel.
Chapter 4
Results
4.1 Software
The main program’s graphical user interface can be seen in Figure
4.1. On top of the main GUI, there are also two more simple GUIs
that can be opened by pressing the magnifying glass next to some
of the plots while the program is paused.