Fall2006.PythonMediaSoundAPI History

Hide minor edits - Show changes to output

Added lines 1-92:
!Python Media API

!!Sound I/O

To input an external WAV file into an internal '''Sound''' encoding. \\
Also, to output an internal encoding to an external WAV file.


The following functions manipulate a sound.

(:table border=1 width=80%:)
(:cell style='padding:5px;':)
'''''Function'''''
(:cell style='padding:5px;':)
'''''Description'''''

(:cellnr style='padding:5px;':)
pickAFile()
(:cell style='padding:5px;':)
Lets the user pick a file and returns the complete
path name as a string.

(:cellnr style='padding:5px;':)
makeSound(''filename'')
(:cell style='padding:5px;':)
Takes a filename as input, reads the file, and creates
a sound from it. Returns the sound.

(:cellnr style='padding:5px;':)
makeEmptySound(''length'')
(:cell style='padding:5px;':)
Creates an empty sound with ''length'' samples. Returns the sound.

(:cellnr style='padding:5px;':)
play(''sound'')
(:cell style='padding:5px;':)
Plays a sound provided as input. No return value.

(:cellnr style='padding:5px;':)
blockingPlay(''sound'')
(:cell style='padding:5px;':)
Plays a sound provided as input and makes sure that no other sound plays at the exact same time. No return value.

(:cellnr style='padding:5px;':)
writeSoundTo(''sound'',"file.wav")
(:cell style='padding:5px;':)
Writes ''sound'' to the file called "file.wav". Returns nothing.

(:tableend:)

!! Definitions

Objects used internally to store external sounds:

* Sound - an internal encoding of a sound, typically coming from am external WAV file.

* Sample - a value between -32768 and 32767 in the Sound. This represents the voltage that a microphone would generate (while recording the sound) at the given moment. The duration of this moment is typically 1/44K sec (for CD-quality sound).

* Samples - a sequence of Sample objects. For example, samples[1] returns the leftmost sample in a sound.

!! Sound Functions

To access the internal '''Sound''' encoding:

(:table border=1 width=80%:)

(:cellnr style='padding:5px;':)
getLength(''sound'')
(:cell style='padding:5px;':)
Returns the number of samples in ''sound''.

(:cellnr style='padding:5px;':)
getSamplingRate(''sound'')
(:cell style='padding:5px;':)
Returns the number of samples per second in ''sound''.

(:cellnr style='padding:5px;':)
getSamples(''sound'')
(:cell style='padding:5px;':)
Returns a list of samples from ''sound''.

(:cellnr style='padding:5px;':)
getSampleValueAt(''sound'',''index'')
(:cell style='padding:5px;':)
Returns the sample of ''sound'' at ''index''.

(:cellnr style='padding:5px;':)
setSampleValueAt(''sound'',''index'',''value'')
(:cell style='padding:5px;':)
Sets the sample of ''sound'' at ''index'' to ''value''.

(:tableend:)