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:

Then you can create a LiveSample as follows:

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).
l.stop() Stops sample playback immediately.
l.pause() Pauses sample playback (remembers current position for resume).
l.resume() Resumes sample playback (from the paused position).
l.isPlaying() Returns True if the sample is still playing, False otherwise.
l.startMonitoring() Starts monitoring audio being recorded (through the speakers).
l.stopMonitoring() Starts monitoring audio being recorded (through the speakers).
l.isMonitoring() Returns True if monitoring is on; False otherwise.
l.setPitch(pitch) Sets the sample pitch (0-127) through pitch shifting from sample’s base pitch.
l.getPitch() Returns the sample’s current pitch (it may be different from the default pitch).
l.setFrequency(freq) Sets the sample pitch frequency (in Hz).  This is equivalent to setPitch(), except it provides more granularity (accuracy).  For instance, pitch A4 is the same as frequency 440 Hz.
l.getFrequency() Returns the current playback frequency.
l.setVolume(volume) Sets the volume (amplitude) of the sample (volume ranges from 0 – 127).
l.getVolume() Returns the current volume (amplitude) of the sample (volume ranges from 0 – 127).
l.setPanning(panning) Sets the panning of the sample (panning ranges from 0 – 127).
l.getPanning() Returns the current panning of the sample (panning ranges from 0 – 127).
l.getFrameRate() Returns the sample’s recording rate (e.g., 44100.0 Hz).