LiveSample

LiveSample includes functions for recording and playing live audio (captured from the computer’s microphone) in real-time. Live samples may be played once, looped, paused, resumed, and change pitch/frequency, among other things.

LiveSample objects can be used in building interactive musical instruments and installations. Also see AudioSample.

LiveSample is included in the audio library, so you need the following:

from music import *

Then you can create a LiveSample as follows:

live = LiveSample(30)

where 30 is the maximum number of seconds the live recording may be, and live is the variable storing the AudioSample.

You may have several LiveSample objects loaded and playing at the same time (even copies of the same live sample). It is possible to create complex timbres by creating several simple sound objects and manipulating them (e.g., change their frequency and/or volume) in real-time.

NOTE: LiveSamples (similarly to AudioSamples) use up lots of computer memory. Create only what you need (in terms of max recording time). Smaller samples will make your program run faster. Longer samples may slow down your program.

Live samples are created as follows:

Function

Description

LiveSample()

Creates a live sample for a maximum recording of 30 seconds.

LiveSample(maxSeconds, pitch, volume)

Creates a live sample for a maximum recording of maxSeconds. Parameter pitch (optional) specifies a base MIDI pitch to be associated with the sound (default is A4), so we can play different pitches with it by changing its pitch (or frequency). Parameter volume (optional) specifies a MIDI note velocity to be used for playback (default is 127).

Once a live sample, l, has been created, the following functions are available:

Function

Description

l.startRecording()

Starts recording live sound from the computer’s audio in (usually microphone).

l.stopRecording()

Stops recording live sound.

l.isRecording()

Returns True if l is currently recording (is in the recording state), False otherwise.

l.play()

Play the sample once.

l.loop()
l.loop(times, start, size)

Repeat the sample indefinitely. Optional parameters times specifies the number of times to repeat (default is -1, indefinitely). If start and size are provided, looping occurs between millisecond start and millisecond start+size (default is 0 and -1, respectively, meaning from beginning to end).