home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-23 | 2.2 KB | 111 lines | [TEXT/CWIE] |
- unit MyPlayAsyncSound;
-
- interface
-
- uses
- Memory;
-
- procedure StartupPlayAsyncSound;
- procedure PlayAsyncSound (theSound: Handle);
- procedure PlayAsyncSoundID (id: integer);
-
- implementation
-
- uses
- Resources, Sound, PreserveA5, MyStartup;
-
- var
- playing: boolean;
- finished: boolean;
- sound: handle;
- chan: SndChannelPtr;
- gChanCallBackProc:SndCallBackUPP;
-
- { Called at interupt level! }
- procedure ChanCallBack (chan: SndChannelPtr; cmd: SndCommand);
- var
- old_a5:Ptr;
- begin
- chan := chan; { Unused }
- cmd := cmd; { Unused }
- old_a5 := SetPreservedA5;
- finished := true;
- RestoreA5(old_a5);
- end;
-
- procedure FinishSound;
- var
- junk: OSErr;
- begin
- HUnlock(sound);
- playing := false;
- finished := false;
- junk := SndDisposeChannel(chan, false);
- chan := nil;
- end;
-
- procedure PlayAsyncSound (theSound: Handle);
- var
- err, junk: OSErr;
- myWish: SndCommand;
- begin
- if (theSound <> nil) & (theSound^ <> nil) & not playing then begin
- chan^.qLength := stdQLength;
- err := SndNewChannel(chan, 0, 0, gChanCallBackProc);
- if err = noErr then begin
- playing := true;
- HLock(theSound);
- junk := SndPlay(chan, SndListHandle(theSound), true);
-
- { set up a sound mgr command block }
- myWish.cmd := callBackCmd;
- myWish.param1 := 0;
- myWish.param2 := 0;
- junk := SndDoCommand(chan, myWish, false);
- { If any of these commands return with an error, we aren't going to get anywhere anyway }
- end;
- end;
- end;
-
- procedure PlayAsyncSoundID (id: integer);
- var
- sound: handle;
- begin
- if not playing then begin
- sound := GetResource('snd ', id);
- PlayAsyncSound(sound);
- end;
- end;
-
- function InitPlayAsyncSound(var msg: integer): OSStatus;
- begin
- msg := msg; { Unused }
- gChanCallBackProc:=NewSndCallBackProc(@ChanCallBack);
- playing := false;
- finished := false;
- sound := nil;
- chan := nil;
- InitPlayAsyncSound := noErr;
- end;
-
- procedure FinishPlayAsyncSound;
- begin
- if playing then begin
- FinishSound;
- end;
- end;
-
- procedure IdleAsyncSound;
- begin
- if finished then begin
- FinishSound;
- end;
- end;
-
- procedure StartupPlayAsyncSound;
- begin
- StartupPreserveA5;
- SetStartup(InitPlayAsyncSound, IdleAsyncSound, 60, FinishPlayAsyncSound);
- end;
-
- end.