[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SOUNDly TRAPped



At  7:25 PM 8/29/93 +0000, Niksa Radovic wrote:
>I, being new to both trap calls and sound manager routines, have a debugging
>problem that may be simply my lack of experience in both areas and I beg your
>forgiveness if I've forgotten to do/not done something obvious.
>
>My problem is simple: I wish to play a 'snd ' resource (created with an older
>version of MacREcorder or something) from within MCL 2.0. The code that I have
>written does that fine -- once. If I try to do it 2 times or more in a row then
>"anything goes" so to speak. 
>
>The code I wrote is:
>
>(with-pstrs ((res_file "sound-test.rsrc"))
>   (#_openresfile :ptr res_file :word))
>
>(rlet ((channel :pointer)
>       (procptr :pointer))   ;;; no call back is used for now
>      (#_sndnewchannel channel 0 0 procptr)
>      (#_sndplay :ptr (%get-ptr channel) 
>                 :ptr (#_getresource :ostype "snd " :word 12977 :ptr)
>                 :word 0 :word)
>      (#_snddisposechannel :ptr (%get-ptr channel) :word 0 :word))
>
>Well, there it is. Any comment/suggestions/help would be greatly appreciated.

First off, to accomplish what your code is doing, you can
simply pass (%null-ptr) to #_SndPlay for the channel:

(#_sndplay (%null-ptr) (#_getresource "snd " 12977) nil)

This forces the playback to be synchronous.

To do it with an explicitly allocated channel, you need to allocate
storage for the SndChannel record and pass that to #_SdnNewChannel
(see IM VI, p. 22-37).

You also need to pass (%null-ptr) as the completion routine (you
were doing a synchronous #_SndPlay, so the completion routine was
never called, but had it been, that would also have caused your
machine to crash).

(rlet ((channel :pointer)
       (sndChannel :sndChannel))
  (setf (%get-ptr channel) sndChannel)
  (#_sndnewchannel channel 0 0 (%null-ptr))
  (#_sndplay
    (%get-ptr channel) 
    (#_getresource :ostype "snd " :word 12977 :ptr)
    nil)
  (#_snddisposechannel (%get-ptr channel) nil))

It would also be a good idea to check for errors on the results
of each of the trap calls.