Chapter 6. Working with Sounds

Sounds are a necessary part of many interactive and entertainment projects. They increase the level of immersion and add feedback to the interactions. Also, sounds play a central role in sound art projects. In this chapter you will learn how to play sound samples, synthesize new sounds, and get sounds from the microphone. Also, you will learn how to get information from sound using its spectrum and use it for controlling visualization parameters:

  • Playing sound samples
  • Generating sounds
  • Using a microphone
  • Getting spectral data from sound

Sound basics

From a physical point of view, sound is a wave of air density changing, which propagates in the space from the sound source to our ears. In computers and other digital devices, a sound is represented as an array of numbers which describe the sound wave amplitude at discrete moments in time. These numbers are called digital audio samples.

Tip

Digital sound representation using audio samples is called Pulse Code Modulation (PCM). It is a historical term, meaning that we code the amplitudes using digital numbers.

An array of audio samples with additional information such as its discretization time step and number of channels (mono, stereo, and so on) is called a sound sample. Sound samples can be used as the elementary bricks for construction of sound and music. The most notable example is hip-hop music, which is based on samples. Many computer games also use samples for sounding player actions.

openFrameworks has good capabilities for playing samples. So using samples is a simple and straightforward way to add voices, effects, and the sound of real instruments to your interactive project.

The most widely used sound sample file formats are MP3, WAV, and AIFF. The WAV and AIFF formats store an uncompressed audio sample array with additional information, and they are usable in all cases, especially when high-quality sounds are needed.

MP3 is a format for playing music. It represents sound in a compressed form with losing quality, so such files are not appropriate for further sound processing. Also MP3 sounds consume more CPU memory on decoding data while playing. As MP3 files are much more compact than WAV and AIFF, they are great for long background sounds in your projects.

You can get many free and paid sound samples from the Web. Be careful about considering the licensee limitations when using these. Anyway, the good option is to record, synthesize, and process your own sounds, using sound recording and editing software and software synths that are widely available for computers and mobile devices.

Now we will consider how to use and play samples in openFrameworks. Low-level sound generation and recording is considered later in the Generating sounds section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset