/* WAV 2 GSM Converter */
Call RxFuncAdd 'SysTempFileName', 'RexxUtil', 'SysTempFileName'
Call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'

crlf=d2c(13)d2c(10)

parse arg infile

if infile='' then
do
say crlf "GSM 2 WAV Converter."
say "Usage: gsm2wav infile" crlf
exit
end

if stream(infile,'c','query exist')='' then
 do
 say "File not found :" infile
 exit
 END

tmpfile=SysTempFileName(gsmtm???.wav)
'@pcm2wav -w771 -i'infile '-o'tmpfile


rc=charin(tmpfile,,4)
rc2=c2x(charin(tmpfile,59,2))

if rc <> 'RIFF' | rc2 <> 'FEFE' then
  do
  say "File is not a GSM 6.10 frame..."
  exit
  end

Call CharOut tmpfile

say "RIFF header cutting..."

infile=left(infile,pos('.',infile))||"gsm"
Call CharOut infile, CharIn(tmpfile,59,chars(tmpfile)), 1
Call CharOut infile
Call CharOut tmpfile

call SysFileDelete(tmpfile)

say "Writting" infile "Done."

exit

