home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14610 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.1 KB  |  60 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!gumby!kzoo!k044477
  3. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  4. Subject: Re: Still trying to get this stupid sound stuff to work...
  5. Message-ID: <1992Aug27.161727.23885@hobbes.kzoo.edu>
  6. Organization: Kalamazoo College
  7. References: <1992Aug26.192610.14018@utkux1.utk.edu>
  8. Date: Thu, 27 Aug 1992 16:17:27 GMT
  9. Lines: 49
  10.  
  11. danny@utkux1.utk.edu (Danny W. McCampbell) writes:
  12. >What is happening now is the sound sound starts playing,
  13. >the dialog comes up, but you cannot do anything until the sound 
  14. >finishes.
  15. >
  16. > [Silly Modula-2-ish header stuff removed :-]
  17. >
  18. > begin
  19. >  mySndChan := nil;
  20. >  mySndHandle := GetResource('snd ', soundID);
  21. >  if mySndHandle <> nil then
  22. >   begin
  23. >    err := SndPlay(mySndChan, mySndHandle, kAsync);
  24. >    if err <> noErr then
  25. >     ExitToShell;
  26. >   end;
  27. > end;
  28.  
  29. If the Sound Manager allocates your memory for you, which it is doing
  30. since you passed it a reference to a NULL SndChannelPtr, it won't let
  31. you play async.  Them's the breaks.  If you allocate the memory
  32. yourself, you can play async, but then you have to worry about
  33. deallocating it.
  34.  
  35. Usually, you'll see someone write a callback routine that will set a
  36. flag to let you know that the sound's done;  then your program will
  37. check the flag every so often, and SndDisposeChannel() and DisposPtr()
  38. on the memory when it sees it set.  Personally, I don't do this
  39. because I can never remember whether SndPlay() will give me a callback.
  40. (I'm a masochist, I use SndDoCommand() and other nasty stuff instead of
  41. the happy, cheerful, easy-to-use-as-long-as-you're-synchronous high
  42. level calls.)  And you really _should_ dispose of the channel shortly
  43. after the sound's done, or the system beep may not play, and other
  44. unfriendly stuff.
  45.  
  46. But, ignoring the deallocation problem, you might write:
  47.  
  48. begin
  49.  mySndChan := NewPtrClear(sizeof(SndChannel)); { does Pascal have sizeof!? }
  50.  mySndChan.qLength := stdQLength; { stdQLength = 128, BTW }
  51.  ...
  52.  err := SndPlay(mySndChan, mySndHandle, kAsync);
  53.  ...
  54. end;
  55. -- 
  56.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  57.  Memo to myself:
  58.  Do The Dumb Things I Gotta Do.
  59.  Touch The Puppet Head.
  60.