Lab exercise 3: Realtime Audio Prototype
From SoftwarePractice.org
In this lab, you will be developing an exploratory prototype for a real-time audio processing system. The system being developed is intended for sounds-effects track construction, in which a series of effects "clips" are played at specified times, in order to create the whole effects sound-track.
A track thus consists in essence of a set of pairs, each of which groups a clip with a time at which that clip starts in the effects sound-track. There may be any number of clips playing simultaneously - that is, a clip may start playing before the previous one finishes.
The concurrency view of the prototype is shown in Figure 1.
Figure 1: The concurrency view of the prototype
Contents |
3.1 Setting up XAMPP
The first thing you need to do is install XAMPP. XAMPP is an easy to install, integrated server package of Apache, mySQL, PHP and Perl that you can run from your local machine. Follow the steps below to set up the XAMPP environment.
- Copy all lab 3 files into your home directory.
- Run the program setup_xampp.bat in the xampplite folder.
- Run xampp-control.exe
- Click start on mysql and apache.
3.2 Database review
In this section you will review some basic concepts of relational databases. To do so, you will create tables to store the simple data model for student enrolments shown in Figure 2. This simple data model that shows that a major consists of some number of courses, and that students are enrolled in multiple subjects (and that each subject has multiple students enrolled in it).
Figure 2: A simple data model
- In a browser window, open the database administration interface:
- Create a new database called Lab3.
- Using the Query window (click on the "SQL" in the left frame), create a table to hold majors. Note: In order to avoid confusion with other students doing the lab, give the table a name beginning with your own name.
CREATE TABLE johnr_major (major_name varchar(255),major_id int(11) not null auto_increment,primary key (major_id));
- Again using the Query window, create a table to hold subjects. Note: In order to avoid confusion with other students doing the lab, give the table a name beginning with your own name.
CREATE TABLE johnr_subject (subject_name varchar(255),subject_code varchar(5),major_id int(11),subject_id int(11) not null auto_increment,primary key (subject_id));
- Use the web interface (the Insert tab) to add a new row to the majors table. For example, B.E. DipEngPrac. View the modified table in the Browse tab. Note the ID of this row.
- Add some subjects that belong to this major. Assume that the ID of this major was 7 - that is the value that will be set in the major_id field:
INSERT INTO johnr_subject (subject_name,subject_code,major_id)VALUES ('Software Architecture','48433',7);INSERT INTO johnr_subject (subject_name,subject_code,major_id)VALUES ('Object-Oriented Design','48024',7);
- Browse the table to see the data.
- Now run a query to select all subjects in that major (the one with ID 7):
SELECT * from johnr_subject where major_id=7
- Now run a query that also displays the name of the selected major:
- (Optional) Add the student table. Then, to represent the many-to-many association between students and subjects, create another table with two columns|one containing student IDs, and one containing subject IDs.
3.3 Setting up audio playback
In this section of the lab, you will create a simple subsystem prototype that plays back audio clips in real time. For the audio processing you will be using the Java Media Framework (JMF). The generic JMF jar file is included with the lab materials, but if you are doing this on your own computer you may want to install one of the optimized versions of JMF. You can obtain the JMF and documentation from:
The demonstration sound files included with the lab are from the following link. You should be able to find other clips and sound files on the web that you can use without copyright issues. You may even want to record your own.
To proceed:
- Update your subversion module to ensure that you have the latest versions of the laboratory files.
- Browse the directory tree and make sure that you understand its layout (it's very simple).
- Compile and run TrackPlayer.java. This simple program assembles sound clips into a continuous audio stream. (It doesn't do it particularly well - remember that this is the first step of a prototype.)
- Note: you will need to include the jmf.jar file in the classpath when you compile and run TrackPlayer. The java run command should look something like this...
- java -classpath .;lib/jmf.jar TrackPlayer
- Read the source code of TrackPlayer.java, and make sure that you understand how it works.
3.4 Using a database
TrackPlayer has its playlist hardwired into the source code. In this section you will get the track data from a database.
- Draw the data model of tracks and clips.
- Figure out the table structure needed to store this data model in a relational database. Use the database admin interface from the previous part of the lab to help you construct the structure of these tables.
- Create a test data set and use the database admin interface to help you construct a set of typical queries.
- At this point you can either continue to use the MySQL database provided with XAMPP or revert to the hsql database. Write a script for the database server, which creates the tables and initialises them with your test dataset. Start up the database and load the script.
- Note: there are some syntactic differences between MySQL and hsqldb.
- Refer to the init.sql script from Lab 2 for the proper syntax for hsqldb.
- If you are using MySQL, you will need to download the JDBC driver [1]
- Modify TrackPlayer to run the appropriate query to fetch the clip playback data.
- Here are some tips on how to do this from the OReilly site [2]
- or you can use the code in proto/HsqlQuery.java, from Lab 2 as a basis.
3.5 Completing the prototype (post-lab work)
Create a simple user interface with a button that, when pressed, uses a TrackPlayer object to play back a track.
- What problem does this interface have? (For example: what would happen if you tried to play back two tracks at once?)
- Modify the program to fix the problem. Show that the modified program is able to play back two different tracks simultaneously.
Draw the concurrency view of the completed prototype.


