Path: utzoo!attcan!uunet!husc6!mailrus!ncar!tank!nucsrl!accuvax.nwu.edu!bob From: bob@accuvax.nwu.edu (Bob Hablutzel) Newsgroups: comp.sys.mac.programmer Subject: Re: How to play snds? Message-ID: <10050070@accuvax.nwu.edu> Date: 25 Jan 89 16:32:49 GMT References: <99000002@silver> Organization: Northwestern U, Evanston IL, USA Lines: 69 > I program the Mac in assembly language, and appear to be the only person > in all of Bloomington to do so. Thus, I have no recourse but to seek > experienced programmers elsewhere. It's always nice to hear from another assembler language nut. (But, _no_, I will not discuss how nice assembler language is. Headaches like that I don't need again :-)) > I've heard that the Inside Mac Volume V description of the Sound Manager > is badly written and self-contradictory. Apple admits that the old Sound Manager chapter is "ambiguous, inaccurate, and often contradics itself". They have put out a new sound manager chapter (in Word format) which is designed to clear things up. I think it was posted to Comp.Binaries.Mac a while back, if not I can post it. > ALL I WANT TO DO > is play a particular type 2 'snd ' resource, which is a digitally-sampled > sound. No fancy pitch changes. No frills. Just play the damn thing as > recorded! One of the first things the new document does is give the sample code for playing a simple 'snd ' resource. They give it in Pascal: myChan := NIL; sndHandle := GetNamedResource( 'snd ', 'myBeep' ); myErr := SndPlay( myChan, sndHandle, FALSE ); In assembler, this would be: subq.l #4,sp move.l #'snd ',-(sp) pea myBeep _GetNamedResource move.l (sp)+,D0 beq NoGood tst.w ResErr bne NoGood subq.l #2,sp clr.l -(sp) move.l D0,-(sp) sf.b -(sp) _SndPlay tst.w (sp)+ bne NoGood > As a side question: I want this sound to be played whenever the user > hits a key, but ONLY when TextEdit is active. When the user is in the > Finder or anywhere else where keystrokes do not produce characters on > the screen, I do NOT want my sound to be played. The way I'm doing this > now is by redirecting the trap _TEKey. I haven't tested it in many > different applications yet, but this seems to work as I want it too. This sounds like a good way to go about things. You get the additional advantage that you are ensured that the heap is in a consistant state, since TEKey can't be called when the heap isn't. (Neither can SndPlay, I think, but IM V isn't here). > Be seeing you... Later > Phaedrus > (aka Colin Klipsch) > sl161022@silver.bacs.indiana.edu > Indiana University at Bloomington Bob Hablutzel Wildwood Software BOB@NUACC.ACNS.NWU.EDU