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

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

#? * (dummy_htk_model)
#? * (initmodel)
#? * (quantiseobservation <hset> <obs> <frame>)
#? * (newmacro <hset> <fidx> <type> <id> <structure>)
#? * (deletemacro <hset> <p>)
#? * (deletemacrostruct <hset> <type> <structure>)
#? * (findmacroname <hset> <type> <id>)
#? * (findmacrostruct <hset> <type> <structure>)
#? * (hasmacros <hset> <types>)
#? * (setvfloor <hset> <vfloor> <minvar>)
#? * (printhmmprofile <f> <hmm>)
#? * (printhsetprofile <f> <hset>)
#? * (createhmmset <hset> <heap> <allowtmods>)
#? * (addmmf <hset> <fname>)
#? * (makehmmset <hset> <fname>)
#? * (makeonehmm <hset> <hname>)
#? * (loadhmmset <hset> <hmmdir> <hmmext>)
#? * (resethmmset <hset>)
#? * (saveinonefile <hset> <fname>)
#? * (savehmmset <hset> <hmmdir> <hmmext> <binary>)
#? * (savehmmlist <hset> <fname>)
#? * (isseen <flag>)
#? * (touch <flag>)
#? * (untouch <flag>)
#? * (clearseenflags <hset> <depth>)
#? * (maxmixtures <hmm>)
#? * (maxmixinset <hset>)
#? * (maxmixins <hmm> <s>)
#? * (maxmixinsets <hset> <s>)
#? * (maxstatesinset <hset>)
#? * (durkind2str <dkind> <buf>)
#? * (covkind2str <ckind> <buf>)
#? * (precomputetmix <hset> <x> <tmthresh> <topm>)
#? * (outp <x> <hmm> <state>)
#? * (poutp <hset> <x> <si>)
#? * (soutp <hset> <s> <x> <se>)
#? * (moutp <x> <mp>)
#? * (dprob2short <p>)
#? * (short2dprob <s>)
#? * (fixfullgconst <mp> <ldet>)
#? * (fixlltgconst <mp>)
#? * (fixinvdiaggconst <mp>)
#? * (fixdiaggconst <mp>)
#? * (fixgconsts <hmm>)
#? * (fixallgconsts <hset>)

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



(de InitModel (  )
    #{ InitModel(  );  #} 
    ()
)


(de QuantiseObservation (  hset  obs  frame )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "Observation *") obs) 
    ((-int-) frame)  
    #{ QuantiseObservation(  $hset   ,$obs   ,$frame  );  #} 
    ()
)


(de NewMacro (  hset  fidx  type  id  structure )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) fidx)                   ;; short -> int
    ((-int-) type)                   ;; char -> int
    ((-gptr- "NameCell *") id) 
    ((-gptr-) structure)  
    (gptr   #{ NewMacro(  $hset   ,$fidx   ,$type   ,$id   ,$structure  )  #} )       ;; MLink -> gptr
)


(de DeleteMacro (  hset  p )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "MacroDef *") p)  
    #{ DeleteMacro(  $hset   ,$p  );  #} 
    ()
)


(de DeleteMacroStruct (  hset  type  structure )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) type)                   ;; char -> int
    ((-gptr-) structure)  
    #{ DeleteMacroStruct(  $hset   ,$type   ,$structure  );  #} 
    ()
)


(de FindMacroName (  hset  type  id )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) type)                   ;; char -> int
    ((-gptr- "NameCell *") id)  
    (gptr   #{ FindMacroName(  $hset   ,$type   ,$id  )  #} )              ;; MLink -> gptr
)


(de FindMacroStruct (  hset  type  structure )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) type)                   ;; char -> int
    ((-gptr-) structure)  
    (gptr   #{ FindMacroStruct(  $hset   ,$type   ,$structure  )  #} )         ;; MLink -> gptr
)


(de HasMacros (  hset  types )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") types)  
    (int   #{ HasMacros(  $hset   ,$types  )  #} )
)


(de SetVFloor (  hset  vfloor  minvar )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "Vector *") vfloor) 
    ((-float-) minvar)  
    #{ SetVFloor(  $hset   ,$vfloor   ,$minvar  );  #} 
    ()
)


(de PrintHMMProfile (  f  hmm )
    ((-gptr- "FILE *") f) 
    ((-gptr- "HMMDef *") hmm)  
    #{ PrintHMMProfile(  $f   ,$hmm  );  #} 
    ()
)


(de PrintHSetProfile (  f  hset )
    ((-gptr- "FILE *") f) 
    ((-gptr- "HMMSet *") hset)  
    #{ PrintHSetProfile(  $f   ,$hset  );  #} 
    ()
)


(de CreateHMMSet (  hset  heap  allowtmods )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "MemHeap *") heap) 
    ((-int-) allowtmods)  
    #{ CreateHMMSet(  $hset   ,$heap   ,$allowtmods  );  #} 
    ()
)


(de AddMMF (  hset  fname )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") fname)  
    (gptr   #{ AddMMF(  $hset   ,$fname  )  #} )            ;; MILink -> gptr
)


(de MakeHMMSet (  hset  fname )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") fname)  
    (int   #{ MakeHMMSet(  $hset   ,$fname  )  #} )       ;; ReturnStatus -> int
)


(de MakeOneHMM (  hset  hname )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") hname)  
    (int   #{ MakeOneHMM(  $hset   ,$hname  )  #} )       ;; ReturnStatus -> int
)


(de LoadHMMSet (  hset  hmmdir  hmmext )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") hmmdir) 
    ((-gptr- "char *") hmmext)  
    (int   #{ LoadHMMSet(  $hset   ,$hmmdir   ,$hmmext  )  #} )       ;; ReturnStatus -> int
)


(de ResetHMMSet (  hset )
    ((-gptr- "HMMSet *") hset)  
    #{ ResetHMMSet(  $hset  );  #} 
    ()
)


(de SaveInOneFile (  hset  fname )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") fname)  
    #{ SaveInOneFile(  $hset   ,$fname  );  #} 
    ()
)


(de SaveHMMSet (  hset  hmmdir  hmmext  binary )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") hmmdir) 
    ((-gptr- "char *") hmmext) 
    ((-int-) binary)  
    (int   #{ SaveHMMSet(  $hset   ,$hmmdir   ,$hmmext   ,$binary  )  #} )       ;; ReturnStatus -> int
)


(de SaveHMMList (  hset  fname )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "char *") fname)  
    (int   #{ SaveHMMList(  $hset   ,$fname  )  #} )       ;; ReturnStatus -> int
)


(de IsSeen (  flag )
    ((-int-) flag)  
    (int   #{ IsSeen(  $flag  )  #} )
)


(de Touch (  flag )
    ((-gptr- "int *") flag)  
    #{ Touch(  $flag  );  #} 
    ()
)


(de Untouch (  flag )
    ((-gptr- "int *") flag)  
    #{ Untouch(  $flag  );  #} 
    ()
)


(de ClearSeenFlags (  hset  depth )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) depth)                                ;; ClearDepth (enum) -> int
    #{ ClearSeenFlags(  $hset   ,$depth  );  #} 
    ()
)


(de MaxMixtures (  hmm )
    ((-gptr- "HMMDef *") hmm)  
    (int   #{ MaxMixtures(  $hmm  )  #} )
)


(de MaxMixInSet (  hset )
    ((-gptr- "HMMSet *") hset)  
    (int   #{ MaxMixInSet(  $hset  )  #} )
)


(de MaxMixInS (  hmm  s )
    ((-gptr- "HMMDef *") hmm) 
    ((-int-) s)  
    (int   #{ MaxMixInS(  $hmm   ,$s  )  #} )
)


(de MaxMixInSetS (  hset  s )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) s)  
    (int   #{ MaxMixInSetS(  $hset   ,$s  )  #} )
)


(de MaxStatesInSet (  hset )
    ((-gptr- "HMMSet *") hset)  
    (int   #{ MaxStatesInSet(  $hset  )  #} )
)


(de DurKind2Str (  dkind  buf )
    ((-int-) dkind)                           ;; DurKind (enum) -> int
    ((-gptr- "char *") buf)  
    (gptr #{ DurKind2Str(  $dkind   ,$buf  )  #} )            ;; char *   -> gptr
)


(de CovKind2Str (  ckind  buf )
    ((-int-) ckind)                               ;; CovKind (enum) -> int 
    ((-gptr- "char *") buf)  
    (gptr #{ CovKind2Str(  $ckind   ,$buf  )  #} )            ;; char *   -> gptr
)


(de PrecomputeTMix (  hset  x  tmthresh  topm )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "Observation *") x) 
    ((-float-) tmthresh) 
    ((-int-) topm)  
    #{ PrecomputeTMix(  $hset   ,$x   ,$tmthresh   ,$topm  );  #} 
    ()
)


(de OutP (  x  hmm  state )
    ((-gptr- "Observation *") x) 
    ((-gptr- "HMMDef *") hmm) 
    ((-int-) state)  
    (double    #{ OutP(  $x   ,$hmm   ,$state  )  #} )         ;; float -> double 
)


(de POutP (  hset  x  si )
    ((-gptr- "HMMSet *") hset) 
    ((-gptr- "Observation *") x) 
    ((-gptr- "StateInfo *") si)  
    (double   #{ POutP(  $hset   ,$x   ,$si  )  #} )         ;; float -> double 
)


(de SOutP (  hset  s  x  se )
    ((-gptr- "HMMSet *") hset) 
    ((-int-) s) 
    ((-gptr- "Observation *") x) 
    ((-gptr- "StreamElem *") se)  
    (double   #{ SOutP(  $hset   ,$s   ,$x   ,$se  )  #} )         ;; float -> double 
)


(de MOutP (  x  mp )
    ((-gptr- "float *") x) 
    ((-gptr- "MixPDF *") mp)  
    (double   #{ MOutP(  $x   ,$mp  )  #} )         ;; float -> double 
)


(de DProb2Short (  p )
    ((-float-) p)  
    (int   #{ DProb2Short(  $p  )  #} )              ;; short -> int
)


(de Short2DProb (  s )
    ((-int-) s)                    ;; short -> int
    (double   #{ Short2DProb(  $s  )  #} )         ;; float -> double 
)


(de FixFullGConst (  mp  ldet )
    ((-gptr- "MixPDF *") mp) 
    ((-float-) ldet)  
    #{ FixFullGConst(  $mp   ,$ldet  );  #} 
    ()
)


(de FixLLTGConst (  mp )
    ((-gptr- "MixPDF *") mp)  
    #{ FixLLTGConst(  $mp  );  #} 
    ()
)


(de FixInvDiagGConst (  mp )
    ((-gptr- "MixPDF *") mp)  
    #{ FixInvDiagGConst(  $mp  );  #} 
    ()
)


(de FixDiagGConst (  mp )
    ((-gptr- "MixPDF *") mp)  
    #{ FixDiagGConst(  $mp  );  #} 
    ()
)


(de FixGConsts (  hmm )
    ((-gptr- "HMMDef *") hmm)  
    #{ FixGConsts(  $hmm  );  #} 
    ()
)


(de FixAllGConsts (  hset )
    ((-gptr- "HMMSet *") hset)  
    #{ FixAllGConsts(  $hset  );  #} 
    ()
)


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

(dhc-make-with-libs () (list htk-libhtk)
  dummy_htk_model
  initmodel
  newmacro
  deletemacro
  deletemacrostruct
  findmacroname
  findmacrostruct
  hasmacros
  setvfloor
  printhmmprofile
  printhsetprofile
  createhmmset
  addmmf
  makehmmset
  makeonehmm
  loadhmmset
  resethmmset
  saveinonefile
  savehmmset
  savehmmlist
  isseen
  touch
  untouch
  clearseenflags
  maxmixtures
  maxmixinset
  maxmixins
  maxmixinsets
  maxstatesinset
  durkind2str
  covkind2str
  precomputetmix
  outp
  poutp
  soutp
  moutp
  dprob2short
  short2dprob
  fixfullgconst
  fixlltgconst
  fixinvdiaggconst
  fixdiaggconst
  fixgconsts
  fixallgconsts
)


;;  quantiseobservation