writesound: Write out a WAV file

Description Usage Arguments Details Author(s) References Examples

View source: R/writesound.R

Description

Create a WAV file from a numeric vector or 'sound' object.

Usage

1
writesound (samples, filename = '', fs = 22050)

Arguments

samples

A numeric vector representing a sound wave.

filename

A string indicating the desired output file name.

fs

The desired output sampling frequency. If a sound object is passed this does not need to be specified.

Details

This function generates single channel (mono), 16-bit WAV sound files at a desired sampling frequency. If a 'sound' object is passed, the filename and sampling frequency do not need to be set. If a filename is not set, the filename defaults to 'samples.wav' where 'samples' indicates the name of the samples variable that was passed to the function.

Author(s)

Santiago Barreda <[email protected]>

References

https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## generate a sine wave with a frequency of 1000 Hz
## sampled at a frequency of 10000 Hz
x = seq (0,.1, 1/10000)
snd = sin (2*pi*1000*x)
plot (snd[1:100], type = 'b')

## write out sine wave as a WAV file
writesound (snd, filename = '1khz.wav', fs = 10000)

## if no filename is provided, this sound will be called 'snd.wav'
writesound (snd, fs = 10000)

phonTools documentation built on May 29, 2017, 9 a.m.