AudioTools
Scale
scale audio data by the specified ratio or to the specified size
Calling Sequence
Parameters
Description
Examples
Scale(audArray, scale, options)
audArray

Array or Matrix containing the audio data to scale
scale
scale factor or desired length of scaled audio
options
options modifying the scaling operation
The Scale command rescales audio data, producing a new audio object with the specified size.
The audArray parameter specifies the audio to scale, and must be a dense, rectangular, one or two dimensional Array, Vector, or Matrix with datatype=float[8].
The scale parameter specifies either the desired scaling ratio, or the desired length, in samples, of the scaled audio data. The former is expressed as a numeric value. The latter is expressed as an integer range giving the desired resulting array indices.
By default, scaling is done using Bspline interpolation. This produces excellent results reasonably fast. When reducing audio data using scale factors smaller than 1/2.5, the scaling is done in steps to avoid unnecessary information loss. For example, scaling by 1/4 is accomplished by scaling twice by 1/2. The nature of the algorithm makes this stepwise scaling unnecessary when enlarging audio data.
If the method=nearest option is specified, scaling is done using the nearestneighbor algorithm. This produces poorer results, but the algorithm is very fast. This method is often suitable for producing lowquality rescalings of audio data.
Specifying method=bspline is equivalent to the default behavior.
NOTE: Scaling does not change the sampling rate of the data, which means that it does change the pitch. For example, scaling down by a factor of 0.5 will double the pitch (increase it by one octave). To resample audio data without affecting the pitch, use the AudioTools[Resample] command.
$\mathrm{audiofile}\u2254\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right)\,''/audio/stereo.wav''\right)\:$
$\mathrm{with}\left(\mathrm{AudioTools}\right)\:$
$\mathrm{aud}\u2254\mathrm{Read}\left(\mathrm{audiofile}\right)$
${\mathrm{aud}}{\u2254}\left[\begin{array}{cc}{''Sample\; Rate''}& {22050}\\ {''File\; Format''}& {\mathrm{PCM}}\\ {''File\; Bit\; Depth''}& {8}\\ {''Channels''}& {2}\\ {''Samples/Channel''}& {19962}\\ {''Duration''}& {0.90531}{}{s}\end{array}\right]$
$\mathrm{small}\u2254\mathrm{Scale}\left(\mathrm{aud}\,1..5000\right)$
${\mathrm{small}}{\u2254}\left[\begin{array}{cc}{''Sample\; Rate''}& {22050}\\ {''File\; Format''}& {\mathrm{PCM}}\\ {''File\; Bit\; Depth''}& {8}\\ {''Channels''}& {2}\\ {''Samples/Channel''}& {5000}\\ {''Duration''}& {0.22676}{}{s}\end{array}\right]$
$\mathrm{squished}\u2254\mathrm{Scale}\left(\mathrm{aud}\,0.25\right)$
${\mathrm{squished}}{\u2254}\left[\begin{array}{cc}{''Sample\; Rate''}& {22050}\\ {''File\; Format''}& {\mathrm{PCM}}\\ {''File\; Bit\; Depth''}& {8}\\ {''Channels''}& {2}\\ {''Samples/Channel''}& {4991}\\ {''Duration''}& {0.22635}{}{s}\end{array}\right]$
$\mathrm{quick}\u2254\mathrm{Scale}\left(\mathrm{aud}\,0.25\,\mathrm{method}=\mathrm{nearest}\right)$
${\mathrm{quick}}{\u2254}\left[\begin{array}{cc}{''Sample\; Rate''}& {22050}\\ {''File\; Format''}& {\mathrm{PCM}}\\ {''File\; Bit\; Depth''}& {8}\\ {''Channels''}& {2}\\ {''Samples/Channel''}& {4991}\\ {''Duration''}& {0.22635}{}{s}\end{array}\right]$
See Also
Array
AudioTools[Convolution]
AudioTools[Resample]
Matrix
Vector
Download Help Document
What kind of issue would you like to report? (Optional)