Book Image

OpenFrameworks Essentials

Book Image

OpenFrameworks Essentials

Overview of this book

Table of Contents (19 chapters)
openFrameworks Essentials
About the Authors
About the Reviewers

Using the level of sound for a parameter's automation

Real-time analysis of sound lets us create audio-reactive visuals. It is an important part of any video synthesizer. Here, we consider the simplest case of analysis—getting the level of sound and using it to control a parameter of our project.

We consider two ways of getting a sound: by playing an audio file and by capturing a sound from the sound card's input.

Playing and analyzing an audio file

openFrameworks has a powerful class for audio file playback, called ofSoundPlayer. It loads an audio file of various formats, including MP3, WAV, and AIFF, plays it, and controls its basic parameters, such as volume, pan, and speed.

Let's use this class to play an audio file by performing the following steps:

  1. Add the audio player object definition to the ofApp class:

    ofSoundPlayer sound;
  2. Load an audio file and set up its parameters by adding the following code to setup():

    sound.loadSound( "skvo.wav" );
    sound.setVolume( 0.8 );
    sound.setLoop( true );