[comp.sys.mac.programmer] Sound Manager callback routine in Think Pascal

ingemar@isy.liu.se (Ingemar Ragnemalm) (06/29/91)

I have spent a lot of time banging my head against Sound Manager, and it
still does't work...

What I want to do is the usual problem: playing sounds anynchronously.

Is there some problem with Think Pascal? The examples from UMPG doesn't work
properly. If I try to make a callback routine according to my Sound Manager
chapter (oct 1988 version), my Mac crashes violently, probably because of
the callback routine being called at interupt time. This includes the example
code by Larry Rosenstein, which I expect works fine under MPW Pascal.

In my experiemnts with callback routines, after creating a new channel
and started the sound with SndPlay, I install the callback routine with:

with myWish do { myWish is a SndCommand }
	begin
		cmd := callBackCmd;
		param1 := 0;
		param2 := SetCurrentA5; 
	end; {with}
	err := SndDoCommand(chan, myWish, false);

If SetCurrentA5 is wrong, note that I also tried the GetA5 from
Rosenstein's example to get the current A5, but it didn't work either:

function GetA5: longint;
Inline: $2E8D; { that is MOVE.L A5, (A7) }

My callback routine looks like:

procedure CallBack(ch: sndChannelPtr; cmd: SndCommand);
var theA5: Longint;
begin
	TheA5 := SetA5(cmd.param2); { Set A5 so we can use our globals }
	SoundDoneFlag := True;
	TheA5 := SetA5(TheA5);	{ Put back A5 }
end;

SoundDoneFLag is reset when I start playing a sound, and I inspect
SoundDoneFlag in my event loop, and call SndDisposeChannel when it
is switches to true.

I think this is pretty well by the book...


Is there a way to know when a channel has finished playing, so I can dispose
it without a callback routine? I've tried to find ways by inspecting the
private fields (qhead, qtail) in the SndChannel, but they are after all
for internal use, so it would be foolish to expect the code to work in the
future with such solutions.

Is there a way to access "lost" SndChannel's, for example channels left by
a sound-using application that has "unexpectedly quit"? It is quite tiresome
to reboot just because of some stupid error - or for jumping out from a program
with interrupt, which I often do. A kind of re-initialization of Sound Manager?
No such routines are documented in my docs.

If you can't help me with my specific questions, do you know about any
example code that works with Think Pascal? No, UMPG doesn't help.


-- 
Ingemar Ragnemalm
Dept. of Electrical Engineering	     ...!uunet!mcvax!enea!rainier!ingemar
                  ..
University of Linkoping, Sweden	     ingemar@isy.liu.se