Documentation Center

  • Trial Software
  • Product Updates

wavwrite

Write WAVE (.wav) sound file

    Note:   wavwrite will be removed in a future release. Use audiowrite instead.

Syntax

wavwrite(y,filename)
wavwrite(y,Fs,filename)
wavwrite(y,Fs,N,filename)

Description

wavwrite(y,filename) writes the data stored in the variable y to a WAVE file called filename. The filename input is a string enclosed in single quotes. The data has a sample rate of 8000 Hz and is assumed to be 16-bit. Each column of the data represents a separate channel. Therefore, stereo data should be specified as a matrix with two columns.

wavwrite(y,Fs,filename) writes the data stored in the variable y to a WAVE file called filename. The data has a sample rate of Fs Hz and is assumed to be 16-bit.

wavwrite(y,Fs,N,filename) writes the data stored in the variable y to a WAVE file called filename. The data has a sample rate of Fs Hz and is N-bit, where N is 8, 16, 24, or 32.

Input Data Ranges

The range of values in y depends on the number of bits specified by N and the data type of y. The following tables list the valid input ranges based on the value of N and the data type of y.

If y contains integer data:

N Bitsy Data Typey Data RangeOutput Format
8uint80 <= y <= 255uint8
16int16–32768 <= y <= +32767int16
24int32–2^23 <= y <= 2^23 – 1int32

If y contains floating-point data:

N Bitsy Data Typey Data RangeOutput Format
8single or double–1.0 <= y < +1.0uint8
16single or double–1.0 <= y < +1.0int16
24single or double–1.0 <= y < +1.0int32
32single or double–1.0 <= y <= +1.0single

For floating point data where N < 32, amplitude values are clipped to the range –1.0 <= y < +1.0.

    Note   8-, 16-, and 24-bit files are type 1 integer pulse code modulation (PCM). 32-bit files are written as type 3 normalized floating point.

See Also

| | | | | |

Was this topic helpful?