WAVE File Format (WAV)
1 Reading and Writing
read-wave
write-wave
2 Utilities
wave?
wave-bits
wave-channels
wave-sample-rate
wave-format
in-wave-channel
in-wave
3 Binary Classes
wave:  format%
new
wave:  format:  extensible%
new
wave:  format:  extended%
new
6.12

WAVE File Format (WAV)

 (require binary-class/wave) package: binary-class-riff

This module provides utilities for reading and writing WAVE files.

Some of the more advanced features of the format are not implemented; let me know if you need them!

1 Reading and Writing

procedure

(read-wave [in])  wave?

  in : input-port? = (current-input-port)
Reads WAVE data from in and returns it.

procedure

(write-wave wav [out])  void?

  wav : wave?
  out : output-port? = (current-output-port)
Writes the WAVE object wav to out.

2 Utilities

procedure

(wave? v)  boolean?

  v : any/c
Predicate for WAVE data. Equivalent to (and (is-a? v riff:list%) (bytes=? #"WAVE" (get-field type v))).

procedure

(wave-bits wav)  exact-positive-integer?

  wav : wave?
Returns the number of bits per sample of wav.

procedure

(wave-channels wav)  exact-positive-integer?

  wav : wave?
Returns the number of channels in wav.

procedure

(wave-sample-rate wav)  exact-positive-integer?

  wav : wave?
Returns the sample rate of wav.

procedure

(wave-format wav)  (is-a?/c wave:format%)

  wav : wave?
Returns the format chunk of wav. An exception will be raised if none is found.

procedure

(in-wave-channel wav ch)  sequence?

  wav : wave?
  ch : exact-nonnegative-integer?
Returns a sequence consisting of the samples of channel number ch in wav.

procedure

(in-wave wav)  sequence?

  wav : wave?
Returns a sequence consisting of the samples of wav. Each element of the sequence has as many values as there are channels.

3 Binary Classes

class

wave:format% : class?

  superclass: riff%

A type representing the WAVE format chunk.

constructor

(new wave:format% 
    [format-tag format-tag] 
    [channels channels] 
    [samples-per-sec samples-per-sec] 
    [avg-bytes-per-sec avg-bytes-per-sec] 
    [block-align block-align] 
    [bits-per-sample bits-per-sample]) 
  (is-a?/c wave:format%)
  format-tag : exact-nonnegative-integer?
  channels : exact-positive-integer?
  samples-per-sec : exact-positive-integer?
  avg-bytes-per-sec : exact-positive-integer?
  block-align : exact-positive-integer?
  bits-per-sample : exact-positive-integer?

Represents extensible format data.

constructor

(new wave:format:extensible% 
    [extension-size extension-size] 
    ...superclass-args...) 
  (is-a?/c wave:format:extensible%)
  extension-size : exact-nonnegative-integer?

Represents extended format data.

constructor

(new wave:format:extended% 
    [valid-bits-per-sample valid-bits-per-sample] 
    [channel-mask channel-mask] 
    [sub-format sub-format] 
    ...superclass-args...) 
  (is-a?/c wave:format:extended%)
  valid-bits-per-sample : exact-nonnegative-integer?
  channel-mask : exact-nonnegative-integer?
  sub-format : bytes?