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

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

#? * (dummy_htk_audio)
#? * (initaudio)
#? * (openaudioinput <x> <sampperiod> <windur> <frperiod>)
#? * (attachreplaybuf <a> <bufsize>)
#? * (startaudioinput <a> <sig>)
#? * (stopaudioinput <a>)
#? * (closeaudioinput <a>)
#? * (framesinaudio <a>)
#? * (samplesinaudio <a>)
#? * (getaistatus <a>)
#? * (getcurrentvol <a>)
#? * (sampsinaudioframe <a>)
#? * (getaudio <a> <nframes> <buf>)
#? * (getrawaudio <a> <nsamples> <buf>)
#? * (getreplaybuf <a> <nsamples> <buf>)
#? * (openaudiooutput <x> <sampperiod>)
#? * (startaudiooutput <a> <nsamples> <buf>)
#? * (playreplaybuffer <ao> <ai>)
#? * (closeaudiooutput <a>)
#? * (setvolume <a> <volume>)
#? * (audiodevinput <mask>)
#? * (audiodevoutput <mask>)
#? * (samplestoplay <a>)

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


(de InitAudio (  )
    #{ InitAudio(  );  #} 
    ()
)


(de OpenAudioInput (  x  sampperiod  windur  frperiod )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "HTime *") sampperiod) 
    ((-double-) windur) 
    ((-double-) frperiod)  
    (gptr   #{ OpenAudioInput(  $x   ,$sampperiod   ,$windur   ,$frperiod  )  #} )  ;; AudioIn->gptr
)


(de AttachReplayBuf (  a  bufsize )
    ((-gptr- "struct _AudioIn *") a) 
    ((-int-) bufsize)  
    #{ AttachReplayBuf(  $a   ,$bufsize  );  #} 
    ()
)


(de StartAudioInput (  a  sig )
    ((-gptr- "struct _AudioIn *") a) 
    ((-int-) sig)  
    #{ StartAudioInput(  $a   ,$sig  );  #} 
    ()
)


(de StopAudioInput (  a )
    ((-gptr- "struct _AudioIn *") a)  
    #{ StopAudioInput(  $a  );  #} 
    ()
)


(de CloseAudioInput (  a )
    ((-gptr- "struct _AudioIn *") a)  
    #{ CloseAudioInput(  $a  );  #} 
    ()
)


(de FramesInAudio (  a )
    ((-gptr- "struct _AudioIn *") a)  
    (int   #{ FramesInAudio(  $a  )  #} )
)


(de SamplesInAudio (  a )
    ((-gptr- "struct _AudioIn *") a)  
    (int   #{ SamplesInAudio(  $a  )  #} )
)


(de GetAIStatus (  a )
    ((-gptr- "struct _AudioIn *") a)  
    (int   #{ GetAIStatus(  $a  )  #} )        ;; AudioInStatus -> int
)


(de GetCurrentVol (  a )
    ((-gptr- "struct _AudioIn *") a)  
    (double   #{ GetCurrentVol(  $a  )  #} )     ;; float -> double
)


(de SampsInAudioFrame (  a )
    ((-gptr- "struct _AudioIn *") a)  
    (int   #{ SampsInAudioFrame(  $a  )  #} )
)


(de GetAudio (  a  nframes  buf )
    ((-gptr- "struct _AudioIn *") a) 
    ((-int-) nframes) 
    ((-gptr- "float *") buf)  
    #{ GetAudio(  $a   ,$nframes   ,$buf  );  #} 
    ()
)


(de GetRawAudio (  a  nsamples  buf )
    ((-gptr- "struct _AudioIn *") a) 
    ((-int-) nsamples) 
    ((-gptr- "short *") buf)  
    #{ GetRawAudio(  $a   ,$nsamples   ,$buf  );  #} 
    ()
)


(de GetReplayBuf (  a  nsamples  buf )
    ((-gptr- "struct _AudioIn *") a) 
    ((-int-) nsamples) 
    ((-gptr- "short *") buf)  
    (int   #{ GetReplayBuf(  $a   ,$nsamples   ,$buf  )  #} )
)


(de OpenAudioOutput (  x  sampperiod )
    ((-gptr- "MemHeap *") x) 
    ((-gptr- "HTime *") sampperiod)  
    (gptr   #{ OpenAudioOutput(  $x   ,$sampperiod  )  #} )          ;; AudioOut -> gptr
)


(de StartAudioOutput (  a  nsamples  buf )
    ((-gptr- "struct _AudioOut *") a) 
    ((-int-) nsamples)                   ;; long -> int
    ((-gptr- "short *") buf)  
    #{ StartAudioOutput(  $a   ,$nsamples   ,$buf  );  #} 
    ()
)


(de PlayReplayBuffer (  ao  ai )
    ((-gptr- "struct _AudioOut *") ao) 
    ((-gptr- "struct _AudioIn *") ai)  
    #{ PlayReplayBuffer(  $ao   ,$ai  );  #} 
    ()
)


(de CloseAudioOutput (  a )
    ((-gptr- "struct _AudioOut *") a)  
    #{ CloseAudioOutput(  $a  );  #} 
    ()
)


(de SetVolume (  a  volume )
    ((-gptr- "struct _AudioOut *") a) 
    ((-int-) volume)  
    #{ SetVolume(  $a   ,$volume  );  #} 
    ()
)



(de AudioDevInput (  mask )
    ((-gptr- "int *") mask)  
    (int   #{ AudioDevInput(  $mask  )  #} )
)


(de AudioDevOutput (  mask )
    ((-gptr- "int *") mask)  
    (int   #{ AudioDevOutput(  $mask  )  #} )
)


(de SamplesToPlay (  a )
    ((-gptr- "struct _AudioOut *") a)  
    (int   #{ SamplesToPlay(  $a  )  #} )
)

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

(dhc-make-with-libs () (list htk-libhtk)
  dummy_htk_audio
  initaudio
  openaudioinput
  attachreplaybuf
  startaudioinput
  stopaudioinput
  closeaudioinput
  framesinaudio
  samplesinaudio
  getaistatus
  getcurrentvol
  sampsinaudioframe
  getaudio
  getrawaudio
  getreplaybuf
  openaudiooutput
  startaudiooutput
  playreplaybuffer
  closeaudiooutput
  setvolume
  audiodevinput
  audiodevoutput
  samplestoplay
)
