Reading a wav file: readwav

### 14.1.1 Reading a wav file: readwav

The readwav command takes as argument a sound file stored in WAV format (file extension: .wav), given as a string.

readwav returns a vector consisting of:

- A list consisting of:
  - The number of channels (generally 1 for mono and 2 for stereo).
  - The number of bits (generally 16).
  - The sampling frequency (44100 for a CD quality sound).
  - The number of bytes (excluding the header); i.e., the number of seconds times the sampling frequency times the number of bits/8 times the number of channels.
- A list of digital sound data for each channel.

The result of readwav is typically stored in a variable.
For example, if sound.wav is a sound file for a one-second sound in CD quality on a 16-bit channel:
Input:

s := readwav("sound.wav")

then:

s[0]

Output:

[1,16,44100,88200]

Input:

size(s)

Output:

2

which is the number of channels plus 1.
Input:

size(s[1])

Output:

44100