startmacro
!******************************************************************************!
! Test sinkaudio.
!
! Author:  L. Tursky / Neon Ngo
! Version: $Id: test_sinkaudio.mm,v 1.5 2011/08/02 16:14:29 ntn Exp $
!******************************************************************************!
switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
if interAct then
  set L:type1000AudioLen 10
  call createAudioFile type1000AudioLen
  pipe init
    set instructions "Select an audio file to play from the choice control. &
                      Click on the PLAY Button to hear the selected file played. &
                      If all audio is played correctly, press the PASS button. &
                      Toggle the mute audio while playing the Type1000 (^type1000AudioLen sec) clip."
    panel/msgid=MAIN/setup/controls=gc

    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}
    gcontrol text idtext "Instructions" "^instructions" 24 7 /title
    gcontrol menu opts "Audio File Type" "Type1000 (^type1000AudioLen secs; mutable),WAV (16-bit welcome),WAV (8-bit welcome),AU (16-bit PCM)" &
             "WAV (16-bit welcome)" /flags=+ChkBox
    gcontrol button play "Play Audio" "Play" /tleft
    gcontrol button mute "Mute Audio" "ON,OFF" "OFF" /tleft

  pipe off

endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
! say "msg.name ^msg.name, data ^msg.data"

if msg.name eqs "MAIN" then
  assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
  files/F=myfiles temp_audio_file*
  forall myfiles erase #
  erase myfiles
  pipe stop
elseif msg.name eqs "OPTS"
  !say "File to play is ^gc.opts.value"

elseif msg.name eqs "PLAY"
  set gc.mute.value "off"  ! reset mute gcontrol
  if gc.opts.value eqss "TYPE1000"
    sinkaudio/id=sinkaudio_mutable temp_audio_file /bg
  elseif gc.opts.value eqss "WAV (8-bit"
   ! test case for BUG 1860
    sinkaudio nxm.audio.dat.welcome_8bits.wav
  elseif gc.opts.value eqss "WAV" ! 16-bit welcome
    sinkaudio nxm.audio.dat.welcome.wav
  elseif gc.opts.value eqss "AU (16-bit PCM"
    sinkaudio nxm.audio.dat.sample.au
  endif

elseif msg.name eqs "MUTE"
  if reg.sinkaudio_mutable rexists then
    ! this only mutes the reg.sinkaudio_mutable instance
    set reg.sinkaudio_mutable.mute msg.data
  endif
else
  ! do nothing
  say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^msg.data"
endif

return

!******************************************************************************!
procedure createAudioFile D:length[4.0]
  set samplerate 22000
  set format "SI"
  set shape  "SIN"
  set amp 2000
  set freq1 480
  set freq2 620
  waveform temp_audio_file1 format length*samplerate shape amp freq1 0 0 1/samplerate
  waveform temp_audio_file2 format length*samplerate shape amp freq2 0 0 1/samplerate
  fcalc temp_audio_file{FORMAT=^format} temp_audio_file1 temp_audio_file2 +
return
