Sound Documentation


Sound
Function Action
playTone(freq) plays tone mit given frequency (in Hz) and duration 1000 ms (blocking function)
playTone(freq, block=False) same, but not-blocking function, used to play several tones at (about) the same time
playTone(freq, duration) plays tone with given frequency and given duration (in ms)
playTone([f1, f2, ...]) plays several tones in a sequence with given frequency and duration 1000 ms
playTone([(f1, d1), (f2, d2), ...])
plays serveral tones in a sequence with given frequency and given duration
playTone([("c", 700), ("e", 1500), ...])
plays serveral tones in a sequence with given (Helmholtz) pitch naming and duration.
Supported are: great octave, one-line to three-line octave (range C, C# up to h'''
playTone([("c", 700), ("e", 1500), ...], instrument = "piano")
same, but selects instrument type. Supported are: piano, guitar, harp, trumpet, xylophone, organ, violin, panflute, bird, seashore, ... (see MIDI specifications)
playTone([("c", 700), ("e", 1500), ...], instrument = "piano", volume=10)
same, but selects sound volume (0..100)


Module import: from soundsystem import *
Playback
Function Action
getWavMono(filename)

provides lists of samples for the specified monaural sound file. "wav/xxx.wav" also loads from the  _wav directory in tigerjython2.jar

getWavStereo(filename)

provides lists of samples for the specified binaural sound file. "wav/xxx.wav" also loads from the _wav directory in tigerjython2.jar

getWavInfo(file)

provides a string with information about the sample rate, etc.

openSoundPlayer(filename)

opens a sound player with the specified sound file. Afterwards, it can be played with the following player functions

openMonoPlayer(filename)

opens a monaural sound player with the specified sound file. It can also handle binaural files (average of both channels)

openStereoPlayer(filename)

opens a binaural sound player with the specified sound files. It can also handle monaural files (both channels are identical)

openSoundPlayerMP3(filename)

just like openSoundPlayer(), but for MP3 files

openMonoPlayerMP3(filename)

just like openMonoPlayer(), but for MP3 files

openStereoPlayerMP3(filename)

just like openStereoPlayer(), but for MP3 files

play()

plays the sound from the current position and returns immediately

blockingPlay()

plays the sound from the current position and then waits until the playing has finished

advanceFrames(n)

fast forwards the current position by a given number of samples

advanceTime(t)

fast forwards the current position by a specified time

getCurrentPos()

returns the current position

getCurrentTime()

returns the current playing time

rewindFrames(n)

rewinds the current position by the specified number of samples

rewindTime(t)

rewinds the current position by the specified time

stop()

stops playing and resets the current playhead to the beginning

setVolume(v)

sets the volume (v = 0...100)

isPlaying()

returns True if the clip has not yet finished playing

mute(bool)

turns to True when muted, and False when audible

playLoop()

loops, and therefore plays the clip endlessly

replay()

replays the clip once

delay(time)

delays the program (in milliseconds), to insert intermissions

 

Recording and Saving
openMonoRecorder()

opens a monaural sound recorder

openStereoRecorder()

opens a binaural sound recorder

capture()

begins recording

stopCapture()

stops recording

getCapturedBytes()

returns the recorded samples as byte list

getCapturedSound()

returns the recorded samples as integer list values (binaural: channels alternate)

writeWavFile(samples, filename)

writes the samples into a WAV file

 

Fast Fourier Transform (FFT)
fft(samples, n)

transforms the first n values of the specified list of samples (floats). Returns a list with n // 2 equidistant spectral values (floats). At a sampling rate of fs these range from 0 to fs/2 at a distance fs/n (resolution)

sine(A, f, t)

creates a sine wave with amplitude A and frequency f (phase 0) for each float value t

square(A, f, t)

creates a square wave with amplitude A and frequency f (phase 0) for each float value t

sawtooth(A, f, t)

creates a sawtooth wave with amplitude A and frequency f (phase 0) for each float value t

triangle(A, f, t)

creates a triangle wave with amplitude A and frequency f (phase 0) for each float value t

chirp(A, f, t)

creates a sine wave with amplitude A and a frequency that increases linearly with time (initial value f) for each float value t