;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "htk/htk-config")



#? *** htk_wave

;; dummy function that adds HTK C header files in C file
(eval `(de dummy_htk_wave () ,htk-cpheader-cmd ()))

#? * (dummy_htk_wave)
#? * (initwave)
#? * (openwaveinput <x> <fname> <fmt> <windur> <frperiod> <sampperiod>)
#? * (closewaveinput <w>)
#? * (zeromeanwave <w>)
#? * (framesinwave <w>)
#? * (sampsinwaveframe <w>)
#? * (getwave <w> <nframes> <buf>)
#? * (getwavedirect <w> <nsamples>)
#? * (openwaveoutput <x> <sampperiod> <bufsize>)
#? * (putwavesample <w> <nsamples> <buf>)
#? * (closewaveoutput <w> <fmt> <fname>)
#? * (waveformat <w>)
#? * (format2str <format>)
#? * (str2format <fmt>)
#? * (readhtkheader <f> <nsamp> <sampp> <samps> <kind> <bswap>)
#? * (writehtkheader <f> <nsamp> <sampp> <samps> <kind> <bswap>)
#? * (storeesigfieldlist <flist>)
#? * (retrieveesigfieldlist <flist>)
#? * (readesignalheader <f> <nsamp> <sampp> <samps> <kind> <bswap> <hdrs> <ispipe>)

;; ********************************************************


(de InitWave (  )
    #{ InitWave(  );  #} 
    ()
)


(de OpenWaveInput (  x  fname  fmt  windur  frperiod  sampperiod )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "char *") fname) 
    ((-int-) fmt)                 ;; FileFormat (enum) -> int
    ((-double-) windur) 
    ((-double-) frperiod) 
    ((-gptr- "HTime *") sampperiod)  
    (gptr   #{ OpenWaveInput(  $x   ,$fname   ,$fmt   ,$windur   ,$frperiod   ,$sampperiod  )  #} )   ;; Wave ( struct _Wave *) -> gptr
)


(de CloseWaveInput (  w )
    ((-gptr- "struct _Wave *") w)  
    #{ CloseWaveInput(  $w  );  #} 
    ()
)


(de ZeroMeanWave (  w )
    ((-gptr- "struct _Wave *") w)  
    #{ ZeroMeanWave(  $w  );  #} 
    ()
)


(de FramesInWave (  w )
    ((-gptr- "struct _Wave *") w)  
    (int   #{ FramesInWave(  $w  )  #} )
)


(de SampsInWaveFrame (  w )
    ((-gptr- "struct _Wave *") w)  
    (int   #{ SampsInWaveFrame(  $w  )  #} )
)


(de GetWave (  w  nframes  buf )
    ((-gptr- "struct _Wave *") w) 
    ((-int-) nframes) 
    ((-gptr- "float *") buf)  
    #{ GetWave(  $w   ,$nframes   ,$buf  );  #} 
    ()
)


(de GetWaveDirect (  w  nsamples )
    ((-gptr- "struct _Wave *") w) 
    ((-gptr- "long *") nsamples)  
    (gptr #{ GetWaveDirect(  $w   ,$nsamples  )  #} )            ;; short *   -> gptr
)


(de OpenWaveOutput (  x  sampperiod  bufsize )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "HTime *") sampperiod) 
    ((-int-) bufsize)                    ;; long -> int
    (gptr   #{ OpenWaveOutput(  $x   ,$sampperiod   ,$bufsize  )  #} )        ;; Wave (struct _Wave *) -> gptr
)


(de PutWaveSample (  w  nsamples  buf )
    ((-gptr- "struct _Wave *") w) 
    ((-int-) nsamples)                   ;; long -> int
    ((-gptr- "short *") buf)  
    #{ PutWaveSample(  $w   ,$nsamples   ,$buf  );  #} 
    ()
)


(de CloseWaveOutput (  w  fmt  fname )
    ((-gptr- "struct _Wave *") w) 
    ((-int-) fmt)                 ;; FileFormat (enum) -> int
    ((-gptr- "char *") fname)  
    (int   #{ CloseWaveOutput(  $w   ,$fmt   ,$fname  )  #} )       ;; ReturnStatus -> int
)


(de WaveFormat (  w )
    ((-gptr- "struct _Wave *") w)  
    (int   #{ WaveFormat(  $w  )  #} )        ;; FileFormat (enum ) -> int
)


(de Format2Str (  format )
    ((-int-) format)                  ;; FileFormat (enum) -> int
    (gptr #{ Format2Str(  $format  )  #} )            ;; char *   -> gptr
)


(de Str2Format (  fmt )
    ((-gptr- "char *") fmt)  
    (int   #{ Str2Format(  $fmt  )  #} )        ;; FileFormat (enum ) -> int
)


(de ReadHTKHeader (  f  nsamp  sampp  samps  kind  bswap )
    ((-gptr- "FILE *") f) 
    ((-gptr- "long *") nsamp) 
    ((-gptr- "long *") sampp) 
    ((-gptr- "short *") samps) 
    ((-gptr- "short *") kind) 
    ((-gptr- "Boolean *") bswap)  
    (int   #{ ReadHTKHeader(  $f   ,$nsamp   ,$sampp   ,$samps   ,$kind   ,$bswap  )  #} )
)


(de WriteHTKHeader (  f  nsamp  sampp  samps  kind  bswap )
    ((-gptr- "FILE *") f) 
    ((-int-) nsamp)                   ;; long -> int
    ((-int-) sampp)                   ;; long -> int
    ((-int-) samps)                   ;; short -> int
    ((-int-) kind)                   ;; short -> int
    ((-gptr- "Boolean *") bswap)  
    #{ WriteHTKHeader(  $f   ,$nsamp   ,$sampp   ,$samps   ,$kind   ,$bswap  );  #} 
    ()
)


(de StoreESIGFieldList (  flist )
    ((-gptr- "FieldSpec **") flist)  
    #{ StoreESIGFieldList(  $flist  );  #} 
    ()
)


(de RetrieveESIGFieldList (  flist )
    ((-gptr- "HFieldList *") flist)  
    #{ RetrieveESIGFieldList(  $flist  );  #} 
    ()
)


(de ReadEsignalHeader (  f  nsamp  sampp  samps  kind  bswap  hdrs  ispipe )
    ((-gptr- "FILE *") f) 
    ((-gptr- "long *") nsamp) 
    ((-gptr- "long *") sampp) 
    ((-gptr- "short *") samps) 
    ((-gptr- "short *") kind) 
    ((-gptr- "Boolean *") bswap) 
    ((-gptr- "long *") hdrs) 
    ((-int-) ispipe)  
    (int   #{ ReadEsignalHeader(  $f   ,$nsamp ,$sampp ,$samps ,$kind ,$bswap ,$hdrs ,$ispipe  )  #} )
)


;; ********************************************************

(dhc-make-with-libs () (list htk-libhtk)
  dummy_htk_wave
  initwave
  openwaveinput
  closewaveinput
  zeromeanwave
  framesinwave
  sampsinwaveframe
  getwave
  getwavedirect
  openwaveoutput
  putwavesample
  closewaveoutput
  waveformat
  format2str
  str2format
  readhtkheader
  writehtkheader
  storeesigfieldlist
  retrieveesigfieldlist
  readesignalheader
)
