Reading a wav file: readwav

### 15.1.11 Reading a wav file: readwav

The readwav command retrieves information about a wav file.

- readwav takes one argument:
  filename, a sound file (with extension .wav) stored in wav format given as a string.
- readwav(filename) 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.

  Example.
  Assuming that sound.wav is a sound file for a one-second sound in CD quality on a 16-bit channel:
  Input:

  s:= readwav("sound.wav"):;
  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