Sound File Controller
Description
Outputs the the signal read from a sound file (or portion of a sound file) as a controller, optionally changing its sampling rate.
(make-controller 'sound-file ... )
Lisp Syntax and Default Values
The 'sound-file controller can be created using the following Lisp syntax:
(make-controller 'sound-file dimension period samplerate filename offset length taps)
Parameters
The 'sound-file controller takes seven arguments:
- dimension: number of input and output channels.
- period: the time between the controller's value updates. If zero is given then it updates every sample.
- samplerate: controller specifying the sample rate in Hz.
- filename: pathname of sound file to be read. (in quotes.)
- offset: offset form the beginning of the sound file, in seconds.
- length: length of sound to be read from file, in seconds
- taps: integer number of taps used in the resampling filter (an even integer not less than 4).
The dimension should correspond to the number of channels in the sound file. This will also also be used as the number of dimensions of the resulting Modalys controller.
The period is the time between the updates of the output of the resampling filter, in synthesis seconds (i.e. seconds from the point of view of Modalys and the synthesis it is calculating). As with all periodic controllers in Modalys, if zero is given then it updates every sample.
The samplerate parameter is a controller corresponding to the sample rate at which the sound file will be read. Naturally, if you want to read the sound file at "normal" speed, you can simply use a constant controller with the appropriate sampling rate. You can also read the file with variable playback speed, if you so desire.
The pathname of the soundfile should be provided in quotes. The path is relative to the Modalys application, unless it begins with a slash, in which case it is an absolute path from the root directory of the hard disk. The syntax for the path follows the syntax rules of your operating system.
The offset is the point at which we start reading the sound file, in seconds, with respect to the sample rate of the sound file (as read from its header). This allows you start at an arbitrary point in the sound file, instead of always starting from the beginning.
The length parameter is the length of sound to be read from the offset point in the file, in seconds, with respect to the sample rate of the sound file (as read from its header). The offset and the length parameters can be used to select a certain region in the sound file. When the sound-file controller reaches the end of the file it returns sample values of zero from that point onward. (i.e. it does not report an error.)
The number of filter taps for the reconstruction of the resampled sound can be chosen. This parameter has an effect on the quality of the resampling (but remember that the computation time increases with the square of taps). A good value for taps is 30. If you are not not changing the sampling rate, and the sound file's sampling rate is the same as the synthesis, then a smaller value can probably safely be used - down to a minimum of 4.
Discussion
The sound-file controller can be used to read control samples stored in sound files. This is useful when working with external excitations or to save computation time by reusing control data generated once. The sound-file controller is a periodic controller, i.e. it is only activated after each period. The samples in sound file between periods are skipped. Like all periodic controllers the sound-file controller uses a one sample period if 0 is passed as period length. This will most often be the case when using the sound-file controller. Here is a practical example of using the sound-file controller with a force connection to excite a string (this one-second sound file controller is shown in the image at the top of this page):
(setq my-string (make-object 'mono-string))
(setq my-string-acc (make-access my-string (const .6) 'trans0))
(setq soundfile-ctl (make-controller 'sound-file 1 0
(const 44100)
"Examples/sound/fl.taps.aiff"
0 1 30))
(make-connection 'force my-string-acc soundfile-ctl)
(make-controller 'sound-file 2 0
(const 44100)
"/my-disk/my-dir/my-sound.aiff"
0 2 30))
Options
File Pathnames
More informaiton on file paths coming soon.....