[comp.sys.mac.programmer] playing snd 2 resources

bytebug@dhw68k.cts.com (Roger L. Long) (09/01/88)

I've been through the IM-V chapter on the Sound Manager with a fine-toothed
comb, and my supposedly simple quest to have my Mac II play a sound that's
been digitized and is in a 'snd ' type 2 resource has me stumped.

Here's some code (Think-C) that doesn't work:

	#include	"SoundMgr.h"

	#define nil	0L

	main()
	{
		Handle effect;
		SndChannelPtr channel;
		SndCommand sound;

		effect = GetResource('snd ', 10000);
		if (effect == nil)
			panic("can't GetResource");
		HLock(effect);

		channel = nil;
		if (SndNewChannel(&channel, 5, initSRate22k, nil) != noErr)
			panic("can't SndNewChannel");

		if (SndPlay(channel, effect, TRUE) != noErr)
			panic("can't SndPlay");

		sound.cmd = noteCmd;
		sound.param1 = 1000;
		sound.param2 = 0xFF000037;
		if (SndDoCommand(channel, &sound, TRUE) != noErr)
			panic("can't SndDoCommand");
			
		if (SndDisposeChannel(channel, FALSE) != noErr)
			panic("can't SndDisposeChannel");

		HUnlock(effect);
		ReleaseResource(effect);
	}

Now, my interpretation of IM-V is that I have the sound digitized in a snd-2
resource, and that I load it with SndPlay and then I play a note to get it
to come out at whatever frequency and duration.  However, it never gets that
far.  I always get a "can't SndPlay" output, with the error code of "badFormat"
returned.  I've single-stepped through the SndPlay trap, and what it "looks"
like happens is that SndPlay looks at the 'snd' resource type and won't
play anything but snd-1 resources.

So, what's the story?  How do I play a digitized sound, if I'm not supposed to
use SndPlay?

I have a bunch of other Sound Manager questions that I'll defer for the moment.
If anyone would like to volunteer as a Sound Manager expert, I'd appreciate the
help.  If anyone can send me some code that works with the Sound Manager, I'd
appreciate looking at that as well.  At this point I'm frustrated enough by
all of the things that I *have* tried that I'll appreciate *anything*.

Thanks.
-- 
	Roger L. Long
	dhw68k!bytebug

mkg@lzsc.ATT.COM (Marsh Gosnell) (09/02/88)

Playing both type 1 and type 2 snd resources is very easy if you are
running the 6.0 system.  The following code works just fine for me:
	theSound = GetResource('snd ', id);
	LoadResource(theSound);
	HNoPurge(theSound);
	SndPlay(0, theSound, false);
 
  Marsh Gosnell
  att!lzma!mkg