(*********************************************************************c*********
 *
 * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1992, 1993
 * Commodore-Amiga, Inc.  All rights reserved.
 *
 * DISCLAIMER: This software is provided "as is".  No representations or
 * warranties are made with respect to the accuracy, reliability, performance,
 * currentness, or operation of this software, and all use is at your own risk.
 * Neither commodore nor the authors assume any responsibility or liability
 * whatsoever with respect to your use of this software.
 *
 ******************************************************************************
 * ramsound.c
 * This shows how to play a sound of type DTST_RAM.
 * Written by David N. Junod
 * ported to Oberon by Albert Weinert (Feb. 1994) needs V40 Interfaces
 *
 *)
MODULE ramsound;

IMPORT
  clf := Classface,
  Dos,
  e := Exec,
  dt := Datatypes,
  I := Intuition,
  u := Utility,
  y := SYSTEM;

(*****************************************************************************)

VAR
  i, samplelength, clock, frequency, samplecycle, duration : LONGINT;
  dtt : dt.Trigger;
  sample : UNTRACED POINTER TO ARRAY MAX(INTEGER) OF SHORTINT;
  o : I.ObjectPtr;

BEGIN
  IF dt.base # NIL THEN HALT( 20 ) END;
  samplelength := 2;
  clock := 3579545;
  frequency := 440;
  samplecycle := 1;
  duration := 30;
  sample := e.AllocVec( samplelength, LONGSET{e.chip} );
  IF sample # NIL THEN
    sample[0] := 127;
    sample[1] := -127;

    o := dt.NewDTObject ( "sound.test",
                         dt.sourceType,      dt.stRam,
                         dt.groupID,         dt.sound,
                         dt.sample,          sample,
                         dt.sampleLength,    samplelength,
                         dt.volume,          0,
                         dt.period,          ((clock*samplecycle) DIV (samplelength*frequency)),
                         dt.cycles,          ((frequency*duration) DIV samplecycle),
                         u.done );
    IF o # NIL THEN
      (* Play the sound *)
      dtt.msg.methodID := dt.mTrigger;
      dtt.gInfo    := NIL;
      dtt.function := dt.play;
      dtt.data     := NIL;
      IF clf.DoMethodA (o, dtt) = 0 THEN END;
      FOR i := 0 TO 63 DO
        IF dt.SetDTAttrs (o, NIL, NIL, dt.volume, i, u.done) = 0 THEN END;
        Dos.Delay (2);
      END;

      FOR  i := 64 TO 0 BY -1 DO
        IF dt.SetDTAttrs (o, NIL, NIL, dt.volume, i, u.done) = 0 THEN END;
        Dos.Delay (2);
      END;

      (* Get rid of the object *)
      dt.DisposeDTObject (o);

    ELSE
      Dos.PrintF ("couldn't create sound object\n");
    END;
    e.FreeVec (sample);
  END;
END ramsound.
