;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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_sigp

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

#? * (dummy_htk_sigp)
#? * (initsigp)
#? * (zeromean <data> <nsamples>)
#? * (ham <s>)
#? * (preemphasise <s> <k>)
#? * (wave2lpc <s> <a> <k> <re> <te>)
#? * (lpc2refc <a> <k>)
#? * (refc2lpc <k> <a>)
#? * (lpc2cepstrum <a> <c>)
#? * (cepstrum2lpc <c> <a>)
#? * (fvec2spectrum <fzero> <f> <s>)
#? * (fft <s> <invert>)
#? * (realft <s>)
#? * (specmodulus <s> <m>)
#? * (speclogmodulus <s> <m> <invert>)
#? * (specphase <s> <m>)
#? * (mel <k> <fres>)
#? * (initfbank <x> <framesize> <sampperiod> <numchans> <lopass> <hipass> <usepower> <takelogs> <doublefft> <alpha> <warplowcut> <warpupcut> <result>)
#? * (wave2fbank <s> <fbank> <te> <info>)
#? * (fbank2mfcc <fbank> <c> <n>)
#? * (fbank2melspec <fbank>)
#? * (melspec2fbank <melspec>)
#? * (fbank2c0 <fbank>)
#? * (initplp <info> <lpcorder> <eql> <cm>)
#? * (fbank2aspec <fbank> <as> <eql> <compressfact> <info>)
#? * (aspec2lpcep <as> <ac> <lp> <c> <cm>)
#? * (weightcepstrum <c> <start> <count> <cepliftering>)
#? * (unweightcepstrum <c> <start> <count> <cepliftering>)
#? * (fzeromean <data> <vsize> <n> <step>)
#? * (addregression <data> <vsize> <n> <step> <offset> <delwin> <head> <tail> <simplediffs>)
#? * (addheadregress <data> <vsize> <n> <step> <offset> <delwin> <simplediffs>)
#? * (addtailregress <data> <vsize> <n> <step> <offset> <delwin> <simplediffs>)
#? * (normaliselogenergy <data> <n> <step> <silfloor> <escale>)

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


(de InitSigP (  )
    #{ InitSigP(  );  #} 
    ()
)


(de ZeroMean (  data  nsamples )
    ((-gptr- "short *") data) 
    ((-int-) nsamples)                    ;; long -> int
    #{ ZeroMean(  $data   ,$nsamples  );  #} 
    ()
)


(de Ham ( s )
    ((-gptr- "float *") s)  
    #{ Ham (  $s  );  #} 
    ()
)


(de PreEmphasise (   s  k )
    ((-gptr- "float *") s) 
    ((-float-) k)  
    #{ PreEmphasise (  $s   ,$k  );  #} 
    ()
)


(de Wave2LPC (   s  a  k  re  te )
    ((-gptr- "float *") s) 
    ((-gptr- "float *") a) 
    ((-gptr- "float *") k) 
    ((-gptr- "float *") re) 
    ((-gptr- "float *") te)  
    #{ Wave2LPC (  $s   ,$a   ,$k   ,$re   ,$te  );  #} 
    ()
)


(de LPC2RefC (   a  k )
    ((-gptr- "float *") a) 
    ((-gptr- "float *") k)  
    #{ LPC2RefC (  $a   ,$k  );  #} 
    ()
)


(de RefC2LPC (   k  a )
    ((-gptr- "float *") k) 
    ((-gptr- "float *") a)  
    #{ RefC2LPC (  $k   ,$a  );  #} 
    ()
)


(de LPC2Cepstrum (   a  c )
    ((-gptr- "float *") a) 
    ((-gptr- "float *") c)  
    #{ LPC2Cepstrum (  $a   ,$c  );  #} 
    ()
)


(de Cepstrum2LPC (   c  a )
    ((-gptr- "float *") c) 
    ((-gptr- "float *") a)  
    #{ Cepstrum2LPC (  $c   ,$a  );  #} 
    ()
)


(de FVec2Spectrum (   fzero  f  s )
    ((-float-) fzero) 
    ((-gptr- "float *") f) 
    ((-gptr- "float *") s)  
    #{ FVec2Spectrum (  $fzero   ,$f   ,$s  );  #} 
    ()
)


(de FFT (  s  invert )
    ((-gptr- "float *") s) 
    ((-int-) invert)  
    #{ FFT(  $s   ,$invert  );  #} 
    ()
)


(de Realft (   s )
    ((-gptr- "float *") s)  
    #{ Realft (  $s  );  #} 
    ()
)


(de SpecModulus (  s  m )
    ((-gptr- "float *") s) 
    ((-gptr- "float *") m)  
    #{ SpecModulus(  $s   ,$m  );  #} 
    ()
)


(de SpecLogModulus (  s  m  invert )
    ((-gptr- "float *") s) 
    ((-gptr- "float *") m) 
    ((-int-) invert)  
    #{ SpecLogModulus(  $s   ,$m   ,$invert  );  #} 
    ()
)


(de SpecPhase (  s  m )
    ((-gptr- "float *") s) 
    ((-gptr- "float *") m)  
    #{ SpecPhase(  $s   ,$m  );  #} 
    ()
)


(de Mel (  k  fres )
    ((-int-) k) 
    ((-float-) fres)  
    (double   #{ Mel(  $k   ,$fres  )  #} )         ;; float -> double 
)


(de InitFBank (  x  framesize  sampperiod  numchans  lopass  hipass  usepower  takelogs  doublefft  alpha  warplowcut  warpupcut result)
    ((-gptr- "MemHeap *") x) 
    ((-int-) framesize) 
    ((-int-) sampperiod)                   ;; long -> int
    ((-int-) numchans) 
    ((-float-) lopass) 
    ((-float-) hipass) 
    ((-int-) usepower) 
    ((-int-) takelogs) 
    ((-int-) doublefft) 
    ((-float-) alpha) 
    ((-float-) warplowcut) 
    ((-float-) warpupcut)  
    ((-gptr- "FBankInfo *") result)             ;; return struct -> pointer
    #{ {
    FBankInfo tmp;
    tmp = InitFBank(  $x   ,$framesize   ,$sampperiod   ,$numchans   ,$lopass   ,$hipass   ,$usepower   ,$takelogs   ,$doublefft   ,$alpha   ,$warplowcut   ,$warpupcut  );
    memcpy($result, &tmp, sizeof(FBankInfo));
    } #}
    ()
)


(de Wave2FBank (  s  fbank  te  info )
    ((-gptr- "float *") s) 
    ((-gptr- "float *") fbank) 
    ((-gptr- "float *") te) 
    ((-gptr- "FBankInfo *") info)                      ;; struct -> pointer 
    #{ Wave2FBank(  $s   ,$fbank   ,$te   ,*$info  );  #} 
    ()
)


(de FBank2MFCC (  fbank  c  n )
    ((-gptr- "float *") fbank) 
    ((-gptr- "float *") c) 
    ((-int-) n)  
    #{ FBank2MFCC(  $fbank   ,$c   ,$n  );  #} 
    ()
)


(de FBank2MelSpec (  fbank )
    ((-gptr- "float *") fbank)  
    #{ FBank2MelSpec(  $fbank  );  #} 
    ()
)


(de MelSpec2FBank (  melspec )
    ((-gptr- "float *") melspec)  
    #{ MelSpec2FBank(  $melspec  );  #} 
    ()
)


(de FBank2C0 (  fbank )
    ((-gptr- "float *") fbank)  
    (double   #{ FBank2C0(  $fbank  )  #} )         ;; float -> double 
)


(de InitPLP (  info  lpcorder  eql  cm )
    ((-gptr- "FBankInfo *") info) 
    ((-int-) lpcorder) 
    ((-gptr- "float *") eql) 
    ((-gptr- "double **") cm)  
    #{ InitPLP(  *$info   ,$lpcorder   ,$eql   ,$cm  );  #} 
    ()
)


(de FBank2ASpec (  fbank  as  eql  compressfact  info )
    ((-gptr- "float *") fbank) 
    ((-gptr- "float *") as) 
    ((-gptr- "float *") eql) 
    ((-float-) compressfact) 
    ((-gptr- "FBankInfo *") info)  
    #{ FBank2ASpec(  $fbank   ,$as   ,$eql   ,$compressfact   , *$info  );  #} 
    ()
)


(de ASpec2LPCep (  as  ac  lp  c  cm )
    ((-gptr- "float *") as) 
    ((-gptr- "float *") ac) 
    ((-gptr- "float *") lp) 
    ((-gptr- "float *") c) 
    ((-gptr- "double **") cm)  
    #{ ASpec2LPCep(  $as   ,$ac   ,$lp   ,$c   ,$cm  );  #} 
    ()
)


(de WeightCepstrum (  c  start  count  cepliftering )
    ((-gptr- "float *") c) 
    ((-int-) start) 
    ((-int-) count) 
    ((-int-) cepliftering)  
    #{ WeightCepstrum (  $c   ,$start   ,$count   ,$cepliftering  );  #} 
    ()
)


(de UnWeightCepstrum (  c  start  count  cepliftering )
    ((-gptr- "float *") c) 
    ((-int-) start) 
    ((-int-) count) 
    ((-int-) cepliftering)  
    #{ UnWeightCepstrum(  $c   ,$start   ,$count   ,$cepliftering  );  #} 
    ()
)


(de FZeroMean (  data  vsize  n  step )
    ((-gptr- "float *") data) 
    ((-int-) vsize) 
    ((-int-) n) 
    ((-int-) step)  
    #{ FZeroMean(  $data   ,$vsize   ,$n   ,$step  );  #} 
    ()
)


(de AddRegression (  data  vsize  n  step  offset  delwin  head  tail  simplediffs )
    ((-gptr- "float *") data) 
    ((-int-) vsize) 
    ((-int-) n) 
    ((-int-) step) 
    ((-int-) offset) 
    ((-int-) delwin) 
    ((-int-) head) 
    ((-int-) tail) 
    ((-int-) simplediffs)  
    #{ AddRegression(  $data   ,$vsize   ,$n   ,$step   ,$offset   ,$delwin   ,$head   ,$tail   ,$simplediffs  );  #} 
    ()
)


(de AddHeadRegress (  data  vsize  n  step  offset  delwin  simplediffs )
    ((-gptr- "float *") data) 
    ((-int-) vsize) 
    ((-int-) n) 
    ((-int-) step) 
    ((-int-) offset) 
    ((-int-) delwin) 
    ((-int-) simplediffs)  
    #{ AddHeadRegress(  $data   ,$vsize   ,$n   ,$step   ,$offset   ,$delwin   ,$simplediffs  );  #} 
    ()
)


(de AddTailRegress (  data  vsize  n  step  offset  delwin  simplediffs )
    ((-gptr- "float *") data) 
    ((-int-) vsize) 
    ((-int-) n) 
    ((-int-) step) 
    ((-int-) offset) 
    ((-int-) delwin) 
    ((-int-) simplediffs)  
    #{ AddTailRegress(  $data   ,$vsize   ,$n   ,$step   ,$offset   ,$delwin   ,$simplediffs  );  #} 
    ()
)


(de NormaliseLogEnergy (  data  n  step  silfloor  escale )
    ((-gptr- "float *") data) 
    ((-int-) n) 
    ((-int-) step) 
    ((-float-) silfloor) 
    ((-float-) escale)  
    #{ NormaliseLogEnergy(  $data   ,$n   ,$step   ,$silfloor   ,$escale  );  #} 
    ()
)

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

(dhc-make-with-libs () (list htk-libhtk)
  dummy_htk_sigp
  initsigp
  zeromean
  ham
  preemphasise
  wave2lpc
  lpc2refc
  refc2lpc
  lpc2cepstrum
  cepstrum2lpc
  fvec2spectrum
  fft
  realft
  specmodulus
  speclogmodulus
  specphase
  mel
  initfbank
  wave2fbank
  fbank2mfcc
  fbank2melspec
  melspec2fbank
  fbank2c0
  initplp
  fbank2aspec
  aspec2lpcep
  weightcepstrum
  unweightcepstrum
  fzeromean
  addregression
  addheadregress
  addtailregress
  normaliselogenergy
)
