CLAM TUTORIAL PART 3

My first CLAM application: playing around with Audios

CLAM (as any development framework) has its own coding conventions: a set of rules and recomendations we should observe when writing CLAM-compliant code. Read the corresponding section in the manual.

Now we are ready to implement our first CLAM application. It will be a very minimal application that will just be able to load an audio file into memory and then save it again using another file name.

First of all you must start a new CLAM project. Consult the CLAM User and Development documentation's section on creating a new CLAM-project for the platform you've chosen. For our first application we will be using CLAM's Audio, AudioFileIn and AudioFileOut classes.

Create a new project using CLAM for your application.

Now create a new class called MyCLAMApp and give it a (CLAM::)Audio member which we will use to store the audio we are going to use. Add a method, LoadAudioFile(), to this class which loads an audio file into the class' Audio object using an AudioFileIn object which must first be configured. Then, add a method, SaveAudioFile(), which saves the class' Audio member to a file (with a different file name than the input file) using an AudioFileOut object. Finially, add a Do() method which first calls LoadAudioFile() and then calls SaveAudioFile(). Create a main-like function which calls MyCLAMApp::Do().

Compile and run your app to see if it works properly.

We will want to make our app a little more flexible (as we want to extend it later on). So we now create a very simple user interface. To keep things simple, create a 'console-based' user interface which has options for loading and saving an audio file and allows the user to enter file names for both files. The application class' Do() method may be removed now as it's no longer needed.

  1. Comment what are the main steps you had to take in order to complete this part of the tutorial and if you encountered any problem.

Once we have an audio signal we sould like to be able to see it and to listen to it.

CLAM has a quite large and complex visualization module but we will only use one of its functionalities: the Plots.

Add a Plot showing the waveform of your application's Audio member. Add an option in your main menu so the user is able to watch the sound once loaded.

The truth is that, appart from seeing the waveforms, it would be very interesting to listen to the sounds inside our application. One way to do so is from the Audio Plot that we have just added. But we would like to be able to listen to the sounds without having to open the Plot. To do so, we need to take a look at the way the AudioIO example handles audio playback. Look at the code and note how it is completely cross-platform (the same lines are used for Linux and for Windows).

So you can very easily add audio output support to your application. You will have to compile all the .cxx files from the /tools/AudioIO folder and, in case you are compiling Linux the ones in /tools/AudioIO/Linux and, in case you are using Windows the files that implement the default RtAudio layer (all the files that start with Rt).

Add audio playback capabilities to your application.

Now we are going to study some more audio signals. We will use signals that are usually used as test signals for audio systems: a sinusoid, a variable frequency sinusoidal signal (sweep) and pink noise.

  1. Open the sine.wav, sweep.wav and noise.wav files from your application. What is the fundamental frequency and period of each of the sounds?

Next we will take a deeper look at the CLAM classes we have used until now. To start with, we will focus in the ProcessingData Audio class. It is a class with a quite simple structure but with some methods that are a bit more complex, look at its attributes and methods.

For reading/writing the audio files we are using the AudioFileIn and AudioFileOut classes from the src/Processing folder. Take a look at them and try to understand their structure/functionalities.

For audio playback, we use the classes in the /src/Processing/AudioIO and src/Tools/AudioIO folders. Although not strictly necessary you can also take a look at them.