startmacro
!
! Test sinkrtp.
!
! Author:  L. Tursky
! Version: $Id: test_sinkrtp.mm,v 1.5 2006/11/29 22:41:16 jxc Exp $
!
switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE


warn "^reg.main.name: Audio tests have been moved to the AUDIO option tree."
stop


if interAct then
 pipe init
   call createAudioFile
    set s:instructions "Audio data has been generated using &
                        the waveform primitive, and the data &
                        has been input to sinkrtp, which has &
                        created a Midas Type 100 file. Click &
                        on the 'Play Audio' button to hear it. &
                        If you hear a dialtone, press the PASS button."
    panel/msgid=MAIN/setup/controls=gc

    gcontrol text idtext "Instructions" "^instructions" 24 7 /title
    gcontrol button play "Play Audio" "Play" /tleft
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}

!  Need to figure out how to use sourcedg to allow testing of sinkrtp's
!  option of sending audio as RTP over UDP
!  sourcedg/on/id=sdg/midassi/xdelta=xdel/packets/verbose _sd
!  sinkrtp/packets/verbose dialtone.tmp ,, "127.0.0.1" 18800
!  sinkaudio _sd

!  For now, test sinkrtp's option to send audio to file
   sinkrtp temp_dial_tone temp_dial_toneRTP
  pipe off

endif

endmacro

!******************************************************************************!
procedure processMessage m:msg

  if msg.name eqs "MAIN" then
    assert/text="sinkrtp test" msg.data eqss "PASS"
    FILES/F=myfiles temp_dial_tone*
    FORALL myfiles erase #
    erase myfiles
    pipe stop
  elseif msg.name eqs "PLAY" then
    sinkaudio temp_dial_toneRTP
  else
    say "Unhandled message: msg.name ^msg.name, data ^msg.data"
  endif

return

!******************************************************************************!

procedure createAudioFile

  set samplerate 22000
  set format "SI"
  set length 5
  set shape  "SIN"
  set amp 2000
  set freq1 480
  set freq2 620
  waveform temp_dial_tone1 format length*samplerate shape amp freq1 0 0 1/samplerate
  waveform temp_dial_tone2 format length*samplerate shape amp freq2 0 0 1/samplerate
  fcalc temp_dial_tone{FORMAT=^format} temp_dial_tone1 temp_dial_tone2 +

return

!******************************************************************************!