wav

wav is a widely used audio file format created by Microsoft. It can contain audio data in a wide variety of formats but typically contains linear pulse code modulation data.


AF - here is a small package I started for reading some basic info from wav files.

 package provide wav 0.1

 namespace eval ::wav {}

 proc ::wav::info {file} {
    set fh [open $file r]
    binary scan [read $fh 12] A4iA4 sig1 len sig2
    if {$sig1 != "RIFF" || $sig2 != "WAVE"} { close $fh; return -code error "Not a WAV file" }
    binary scan [read $fh 24] A4issiiss id size format channels samplerate byterate align bitrate
    set len [expr {[file size $file] - [tell $fh] - 8 - ($size - 16)}] 
    close $fh
    return [list format $format channels $channels samplerate $samplerate byterate $byterate bitrate $bitrate size $len]
 }


 array set data [::wav::info $argv]

 if {$data(channels) == 1} {
    set chans mono
 } elseif {$data(channels) == 2} {
    set chans stereo
 } else {
    set chans "$data(channels) channels"
 }

 puts "$argv: [expr {$data(size) / double($data(byterate))}] seconds, [expr {int($data(samplerate) / 1000.00)}]KHz, $data(bitrate)bit, $chans"

RS: This code snippet works for playing WAV files on Win95,... :

  exec sndrec32 /play /close [file nativename $f]

See also: WAV Dump


SeS : 3rd August 2014

If you happen to have included ffidl package to your GUI distribution, you might also want to consider the following as an alternative:

ffidl::callout dll_sndPlaySound \
   {pointer-utf8 int} int \
   [ffidl::symbol winmm.dll sndPlaySoundA]

set mode(sync)  0   ;# play synchronously (default)
set mode(async) 1   ;# play asynchronously
set mode(loop)  8   ;# loop

dll_sndPlaySound [file nativename $filename] [expr $mode(async) + $mode(loop)]

This (and more) DLL call(s) will also be added to the ffidl-wrapper library of following releases of tG².