[comp.sys.amiga] Audio device problems

mwm@eris.BERKELEY.EDU (Mike (My watch has windows) Meyer) (10/23/87)

I've got a program that needs two simple sounds. One can run sync,
but the other wants to be async.

I allocate a port, an IOAudio struct and let OpenDevice allocate a
channel for me.

I then have a pair of routines that issue the do a CMD_WRITE with the
appropriate waveform. The sync sounds just then does a WaitIO on the
IOAudio request. The async versions returns after the BeginIO, and a
third function is called later to do the WaitIO.

Everything work as expected (and is working in the background, even as
I type this). Except every once in a while, the thing hangs.
Apparently in the WaitIO for the async sound (the sequence is: async
sound, a little cleanup, sync sound). Everything worked fine before I
added the sound code, so that's presumable the problem. Changing the
async code to run sync (start function does it all, third function a
nop) doesn't help.

Things seem to be working just fine now. But the async WaitIO has been
replaced by a loop:

	while (GetMsg(audio_port) != NULL)
		;

Ugly. Not right. Anyone got a fix?

Oh yeah - nothing else that would want to touch the audio is running.

	Thanx,
	<mike
--
I went down to the hiring fair,				Mike Meyer
For to sell my labor.					mwm@berkeley.edu
I noticed a maid in the very next row,			ucbvax!mwm
I hoped she'd be my neighbor.				mwm@ucbjade.BITNET

gbbrooks@sybil.cs.Buffalo.EDU (G. Brandon Brooks) (03/17/90)

	I've been trying to program the audio device over this past week, and
for the past 2 days I've been stuck - wondering what I've done wrong.
	I wrote a program in Modula-2 (I'm sure any 'C' fan can read the code
without much effort) that tries to open the audio device, play a note from unit
1 and then closes the device.
	The program (I think) properly opens and closes the device, but the
note that I play is only about 1/10th of a second long, or a quick 'bpfdth'
from the speakers of my monitor.
	THE PROBLEM - Why does the note play for so short? If I change the
ioaCycles parameter to AN number (including 0), the program still emits a
'bpfdth' sound for much under a second.
	ioaVolume works, the waveform (from what I can hear of it) [ioadata]
works, and the 'frequency' [1/ioaperiod] works. But why doesn't the length,
ioaCycles work?
	If I use a DoIO command to dispatch the request, it will wait
longer depending on larger values of ioaCycles, but no note will be played.
	If I use a BeginIO command, the note will play as a 'bpfdth' but not
of the right length. What does BeginIO do that DoIO does not do? - Oh, SendIO
will send the request as BeginIO does, but STILL without a sound coming from
my speakers!
	The Modula-2 program follows, if it would help:

					-Brandon

The program:
---------------------------------------------------------------------------

MODULE AudioTest;
  FROM AudioDevice   IMPORT AudioChannelsSet,Left1,ADCmdPerVol,
                            ADIOPerVol,IOAudio,IOAudioPtr;
  FROM IODevices     IMPORT OpenDevice,CloseDevice,CheckIO,SendIO,DoIO,WaitIO,
                            IOFlagsSet,CmdWrite,CmdStart,CmdUpdate,IOQuick,
                            BeginIO;
  FROM Memory        IMPORT AllocMem,MemReqSet,MemChip;
  FROM Nodes         IMPORT NTMessage;
  FROM RandomNumbers IMPORT Seed,Random;
  FROM Ports         IMPORT MsgPort,MsgPortPtr;
  FROM PortsUtil     IMPORT CreatePort,DeletePort;
  FROM SSTEM        IMPORT ADDRESS,ADR,BTE;
  FROM InOut         IMPORT WriteString,WriteCard,WriteInt,WriteLn;

VAR  Request : IOAudio;
     MSGPortPtr : MsgPortPtr;
     Wave,A : ADDRESS;
     i : CARDINAL;
     error : LONGCARD;
     a : ARRA [1..15] OF BTE;

BEGIN

  (* Request unit 1 *)
  a[1] := BTE(1);

  (* Initialize a request structure *)
  MSGPortPtr := CreatePort(ADR("audioport"),0);
  Request.ioaRequest.ioMessage.mnReplyPort   := MSGPortPtr;
  Request.ioaRequest.ioMessage.mnNode.lnType := NTMessage;
  Request.ioaRequest.ioMessage.mnNode.lnPri  := BTE(0);
  Request.ioaData      := ADR(a);
  Request.ioaLength    := 7;

  (* Open the audio device channel 0 (left speaker) *)
  error := OpenDevice(ADR("audio.device"),1D,ADR(Request),0D);
  IF error # 0D THEN WriteString("Error: "); WriteCard(error,0); WriteLn;
     HALT; END;
  WriteString("Unit: "); WriteCard(CARDINAL(Request.ioaRequest.ioUnit),0); WriteLn;
  WriteString("Alloc:"); WriteCard(CARDINAL(Request.ioaAllocKey),0); WriteLn;

  (* Set up a wave *)
  Seed := 1235D;
  Wave := AllocMem(500D,MemReqSet{MemChip});
  A := Wave;
  FOR i := 0 TO 499 DO
    A^ := BTE(Random(255));
    INC(A);
  END;

  WriteString("Playing....\n");

  (* Play a note *)
  Request.ioaRequest.ioCommand := CmdWrite;
  Request.ioaRequest.ioFlags   := IOFlagsSet{ADIOPerVol};
  (* Request.ioaAllocKey       := CARDINAL(AudioChannelsSet{Left1}); *)
  Request.ioaData              := Wave;
  Request.ioaLength            := 500D;
  Request.ioaPeriod            := 3000;
  Request.ioaVolume            := 60;
  Request.ioaCycles            := 0;
  
  BeginIO(ADR(Request));
  CloseDevice(ADR(Request));

END AudioTest.