#!/usr/bin/awk -f
# HP 20020308
# convert list of wav files (44.1kHz/2ch/16bit) to toc file
# for cdrdao and xcdrdao/gcdmaster
# usage:
#  \ls *.wav | wav2toc pregap=1.5 > all_wavs.toc
#  echo "file1.wav\nfile2.wav" | wav2toc > files.toc

BEGIN {
  track = 0
  pregap = 0
  printf "CD_DA\n"
  printf "\n"
}

{
  track++
  printf "// Track %d\n",track
  printf "TRACK AUDIO\n"
  printf "NO COPY\n"
  printf "NO PRE_EMPHASIS\n"
  printf "TWO_CHANNEL_AUDIO\n"
  if (pregap) {
    pregapf = int(pregap*75)
    pregaps = int(pregapf/75)
    pregapf -= pregaps*75
    printf "SILENCE 00:%02d:%02d\n",pregaps,pregapf
  }
  printf "START\n"
  printf "FILE \"%s\" 0\n",$0
  printf "\n"
}
