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.