home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 20757 < prev    next >
Encoding:
Text File  |  1993-01-06  |  4.2 KB  |  121 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!apple!mumbo.apple.com!gallant.apple.com!NewsWatcher!user
  3. From: REEKES@applelink.apple.com (Jim Reekes)
  4. Subject: Re: help- sound playing w/ bufferCmd
  5. Sender: news@gallant.apple.com
  6. Message-ID: <REEKES-050193163250@90.10.20.67>
  7. Date: Wed, 6 Jan 1993 00:36:46 GMT
  8. Distribution: comp
  9. References: <TMORROW.93Jan2151912@af4hp.oracle.com>
  10. Organization: Apple Computer, Inc.
  11. Followup-To: comp.sys.mac.programmer
  12. Lines: 107
  13.  
  14. In article <TMORROW.93Jan2151912@af4hp.oracle.com>, tmorrow@oracle.com
  15. (Thomas Morrow) wrote:
  16. > I am having trouble using SndDoCommand to play a sampled sound header.
  17. > I do:
  18. >     SndCommand mySndCmd;
  19. >     
  20. >     /* mySndH is a handle to a sound header and data */
  21. >     /* mySndChan is already properly opened */
  22. >     mySndCmd.cmd;
  23. >     mySndCmd.param1 = 0;
  24. >     mySndCmd.param2 = (long)(*mySndH) & 0xffffff;
  25. >     SndDoCommand(mySndChan, mySndCmd, false);
  26. > This does not work for some reason; I can't figure out why because if
  27. > I replace the SndDoCommand with a Snd Play, it works:
  28. >     SndPlay(mySndChan, mySndH, true);
  29. >     
  30. > So the channel and header must be alright.  I am new to Mac
  31. > programming, and wasn't sure exactly how to set param2 (a long) to the
  32. > header address (Ptr)... The IM IV uses ORD4() to do the type
  33. > conversion, but I am using Think C rather than Lisa Pascal. My way
  34. > seems to work, but what is the elegant way?
  35. > Anyway, I use SndChannelStatus to get the status every event loop
  36. > cycle, and the SCStatus returned is blank (zero) in all except CPUload
  37. > (24),  ChannelAttributes (initMono), and ChannelBusy (true).  How can
  38. > the channel be busy if StartTime == endTime == 0?
  39.  
  40. You cannot use the 'snd ' resource for the bufferCmd. You must point to the
  41. SoundHeader within the resource.  Also, the code above didn't set the cmd
  42. to bufferCmd. Here's some code anyone can use to find the sound header in a
  43. 'snd ' resource. Then change your code above into...
  44.  
  45.     mySndCmd.cmd = bufferCmd;
  46.     mySndCmd.param1 = 0;
  47.     mySndCmd.param2 = (long) *mySndH + offset;
  48.     err = SndDoCommand(mySndChan, &mySndCmd, true);
  49.  
  50.  
  51. // find the sound header inside of the given snd handle
  52.  
  53. OSErr GetBufferOffset(Handle sndHandle, long *offset)
  54. {
  55.     short       howManyCmds;
  56.     Ptr         cruisePtr;
  57.     OSErr       result;
  58.  
  59.     if (sndHandle == nil)
  60.         return nilHandleErr;
  61.         
  62.     if (*sndHandle == nil)
  63.         return nilHandleErr;
  64.  
  65.     result = noErr;
  66.     *offset = 0;
  67.  
  68.     // set the pointer past the first two words of the snd
  69.     // this is correct for both format 1 and 2 resources
  70.     cruisePtr = *sndHandle + offsetof(SndListResource, modifierPart);
  71.  
  72.     // if it's a format 1, then point past the modifier parts
  73.     if ( ((SndListPtr)*sndHandle)->format == firstSoundFormat )
  74.         cruisePtr += sizeof(ModRef) *
  75. ((SndListPtr)*sndHandle)->numModifiers;
  76.  
  77.     // now pointing at number of cmds
  78.     howManyCmds = *((short *)cruisePtr);
  79.     cruisePtr += sizeof(howManyCmds);
  80.  
  81.     // cruisePtr is now at the first sound command
  82.     // cruise all commands and find a soundCmd or bufferCmd
  83.     do {
  84.         switch (((SndCmdPtr)cruisePtr)->cmd) {
  85.  
  86.             case (soundCmd | dataOffsetFlag):
  87.             case (bufferCmd | dataOffsetFlag):
  88.                 *offset = ((SndCmdPtr)cruisePtr)->param2;
  89.                 howManyCmds = 0;                // done, get out of loop
  90.                 break;
  91.  
  92.             default:                            // catch any other type of
  93. cmd
  94.                 cruisePtr += sizeof(SndCommand);
  95.                 howManyCmds -= 1;
  96.                 break;
  97.         }
  98.     } while (howManyCmds >= 1);                 // done with all the
  99. commands
  100.  
  101.     if (*offset == 0)                           // never found sound header
  102.         return badFormat;
  103.         
  104.     return(result);
  105. }
  106.  
  107.  
  108.  
  109. -----------------------------------------------------------------------
  110. Jim Reekes, Polterzeitgeist  |     Macintosh Toolbox Engineering
  111.                              |          Sound Manager Expert
  112. Apple Computer, Inc.         | "All opinions expressed are mine, and do
  113. 20525 Mariani Ave. MS: 81-KS |   not necessarily represent those of my
  114. Cupertino, CA 95014          |       employer, Apple Computer Inc."
  115.