home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!spool.mu.edu!news.nd.edu!mentor.cc.purdue.edu!noose.ecn.purdue.edu!samsung!transfer!ceylon!choffman.gte.com!user
- From: chuck@gte.com (Chuck Hoffman)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Need small example of playing a sound in THINK C.
- Message-ID: <chuck-090992095031@choffman.gte.com>
- Date: 9 Sep 92 14:19:17 GMT
- References: <1992Sep7.001953.570@nynexst.com>
- Sender: news@ceylon.gte.com
- Followup-To: comp.sys.mac.programmer
- Organization: GTE Laboratories
- Lines: 71
-
- In article <1992Sep7.001953.570@nynexst.com>, rsilvers@powwow.nynexst.com
- (Rob Silvers) wrote:
- >
- > I have gotton the Mac to play sampled sound resources in
- > THINK C, but I am having trouble playing a synthesized square wave.
- > Could someone send me a small example of playing a simple note?
-
- I did it recently this way, to play a sound asynchronously:
-
- I used ResEdit to create (and preview play) a 'snd ' resource (trailing
- blank required) with the following hexidecimal values. Actually, I created
- a template for ResEdit to make this easy. Sound resource number should be
- above 8191. I used 9000.
-
- ============ 'snd ' RESOURCE:
-
- 0001 Format 1
- 0001 Number of mod/synth's is 1
- 000100000000 Note synth id is 1, and null initial parm
- 0003 Number of commands
- 002B00FF00000000 Amplitude command (full blast)
- 002C008000000000 Timbre command (half between square and sine)
- 002803E800000036 Note command (1000 half miliseconds, F-sharp/A-flat)
-
- ============ TO PLAY THE SOUND:
-
- SndCommand myCallbk;
-
- ------------
- disposeAlmaMater = FALSE;
- myCallbk.cmd = callBackCmd;
- myCallbk.param1 = NIL;
- myCallbk.param2 = (long) &disposeAlmaMater;
- SetItem (myMenuHandle[3], AlmaMaterItem, myStifleStr);
- mySoundH = GetResource ('snd ', 9000);
- HLock (mySoundH);
- mySndChPtr = NIL;
- myErr = SndNewChannel (&mySndChPtr, NIL, NIL,
- (ProcPtr) myCallBack);
- myErr = SndPlay (mySndChPtr, mySoundH, TRUE);
- myErr = SndDoCommand (mySndChPtr, &myCallbk, TRUE);
-
- ============ TO STOP THE SOUND
-
- sndRC = SndDisposeChannel (mySndChPtr, TRUE);
- HUnlock (mySoundH);
- ReleaseResource (mySoundH);
- disposeAlmaMater = FALSE;
-
- ============ CALLBACK ROUTINE
-
- pascal void myCallBack(SndChannelPtr workChPtr, SndCommand workCmd)
- {
- *((Ptr) workCmd.param2) = (char) 0x08; /* set flag in disposeAlmaMater */
- return;
- }
-
- ============
-
- I'm a real beginner at this sound stuff, so postings of any other ways
- would be of interest to me as well.
-
-
- Chuck Hoffman
- chuck@gte.com
- GTE Laboratories, Waltham, Massachusetts, USA
- (617) 466-2131
- =====================================
- I'm not sure why we're here, but I am sure that while we're here we're
- supposed to help each other.
- =====================================
-