[comp.sys.mac.programmer] Sound Manager

hpoppe@scdpyr.UUCP (Herb Poppe) (03/10/88)

In article <21736@bbn.COM>, levin@bbn.com (Joel B Levin) writes:
>...
> IM V (final glossy version) says that the Sound Manager is in both the
> SE and the II.  I am using an SE and the System Release 5.0 stuff (w/o
> MultiFinder).  What goes on?
>...
I too just started working (playing :-)) with sound on the Mac this week
and was researching the Sound Driver (and Tech Note 19) vs. the Sound
Manager. There is no doubt that the Sound Manager is the method of choice.

I have the 17 AUG 87 final APDA draft of IM-V and though the Sound Manager
chapter does not say that the Sound Manager is only for the Mac II, and
though the warning [Macintosh II] does NOT appear next to the procedure
descriptions, the statement (on page 2): "In addition, the synthesizers
of the Sound Manager, utilizing the power of the new Apple Sound Chip,
use only a fraction of the processing time of the 68020" made me suspicious
that the Sound Manager would work only on the Mac II.

I wrote a simple program using NGetTrapAddress (see Tech Note 156) which
tested for the availability of the Sound Manager traps. They were present
on the Mac II, but were not patched in by either System 4.1 or 4.2 tailored
for the MacPlus or SE or the "universal" 4.2 system.

I then discovered the reference that Joel Levin mentions above. It appears
on page 2 of the Preface under "What's New?". "The Macintosh II and SE
computers both contain new capabilities not present in earlier Macintosh
models. They include: Sophisticated sound. Your application can now generate
sophisticated music and sound effects, using special resource types."

While this does not categorically say that the Sound Manager is present on
the SE, it sure sounds like it.

I hope that the next version of the System File will include patches that
will implement the Sound Manager on the SE, Plus, etc. (It certainly
wouldn't hurt to know in advance, hint, hint!) I appreciate that
because these machines don't have the Apple Sound Chip, certain capabilities
(like stereo) will be missing and that performance might be limited.

It would be a shame if developers writing to the installed base have to
forego the elegance of the Sound Manager for the travails of Tech Note 19.
I hope that all future Macs (not just the 020 based machines) have the sound
chip.

(Was the SE, I wonder, meant to have the new sound chip?)

IM-4 and other parts of IM-5 are similarly vague about what functionality
exists in the various models of the Mac ROM and what functionality has
been patched into the System for which Mac models with which System File
version. It would certainly contribute to well-behaved programs if
Apple Tech Support could come up with a (continuously updated) Tech Note
that gave a matrix of which traps (or other system components like the
LaserWriter drivers) were implemented on (or otherwise compatible with)
which systems on which machines.
-- 
Herb Poppe      NCAR                         INTERNET: hpoppe@scdpyr.UCAR.EDU
(303) 497-1296  P.O. Box 3000                   CSNET: hpoppe@ncar.CSNET
		Boulder, CO  80307               UUCP: hpoppe@scdpyr.UUCP

kaufman@polya.Stanford.EDU (Marc T. Kaufman) (08/03/88)

Has anyone made the direct sound manager "frequency" call work for synth 1
(the Note synthesizer)?  Apparently the frequencyCmd doesn't work at all, and
the noteCmd works for 'notes' (values between about 60 and 127), but not
for 'frequencies' (24 bits of direct frequency data).  I am running system 6.0
on a Mac II.  I recall some earlier postings on this issue which have expired.

Marc Kaufman (kaufman@polya.stanford.edu)

mystone@caen.engin.umich.edu (Dean Yu) (09/24/88)

   I'm writing a game for the Mac, and I'm using the Sound Manager
routines in it to produce some sound effects.  Unfortunately, I've got
a bug that may or may not be a bug in the new System.
  Basically, it's a maze game, and whenever a player runs into a wall,
it'll play a digitized "Ow!" sound.  This works fine the first time, but
it you try to run into the wall several times in succession really quickly,
the sound will cut off a fraction of a second into the second time the
sound plays, then there's no sound whatsoever after that point.  Then, when
I try to quit out of the game, it hangs on SndDisposeChannel.
  At first, I thought it might be a bug in my program, but when I try it
on a Mac II, the sound works correcctly.  (I've got other problems with
the Mac II, but that's another story...)  So I'm totally at a loss.  Any
ideas?
  I've got a Mac 512K Enhanced with 2 Megs RAM, SCSI port, Jasmine DirectDrive
40, System 6.0.2, and I'm writing this in MPW Pascal 2.0.  Here are the
questionable routines:

procedure InitSounds;

var err	:	OSErr;

begin
	sChannel:=nil;     { sChannel is a SndChannelPtr } 
	err:=SndNewChannel(sChannel,5,initSRate22k+initMono,nil);
	OwSnd:=GetNamedResource('snd ','Ow!');
	HLock(OwSnd);
	ExitSnd:=GetNamedResource('snd ','Hallelujah');
	HLock(ExitSnd);
end;

procedure PlaySound(sound	:	Handle);

var	Err	:	OSErr;

begin
	Err:=SndPlay(sChannel,sound,TRUE);   { Play async sound } 
end;

procedure ExitRoutine;

var	Err	:	OSErr;

begin
	Err:=SndDisposeChannel(sChannel,false);   { Hangs here on my Mac } 
	DisposeWindow(gPtr);
	DisposeWindow(pw[1]);
	DisposeWindow(pw[2]);
	ClosePort(ScPtr);
	DisposPtr(pointer(ScPtr));
   SetEventMask(everyEvent-keyUpMask);
end;


--------------------
Dean Yu, mystone@caen.engin.umich.edu
I don't have an opinion...
--------------------

lsr@Apple.COM (Larry Rosenstein) (11/12/88)

In article <3ea47cbb.b097@shadow.engin.umich.edu> mystone@caen.engin.umich.edu (Dean Yu) writes:
>
>it'll play a digitized "Ow!" sound.  This works fine the first time, but
>it you try to run into the wall several times in succession really quickly,
>the sound will cut off a fraction of a second into the second time the
>sound plays, then there's no sound whatsoever after that point.  Then, when
>I try to quit out of the game, it hangs on SndDisposeChannel.

There was a message on AppleLink recently disussing this.  

Basically, you should only allocate a sound channel when you intend to play
sounds, and dispose of it whe nthe sound finishes.  Allocating a channel
prevents other code from making sounds (eg, it prevents SysBeep from
working).

In addition, when you play a snd resource, it is likely that a synthesizer
is added to the channel, since most resources specify this.  This means that
you should create the sound channel unlinked to any synthesizer.  It also
means that if you place the resource twice in the same channel, the
synthesizer will be added twice.  This probably accounts for the degradation
in the sound (and possibly the crashes on SndDisposeChannel).

-- 
		 Larry Rosenstein,  Object Specialist
 Apple Computer, Inc.  20525 Mariani Ave, MS 46-B  Cupertino, CA 95014
	    AppleLink:Rosenstein1    domain:lsr@Apple.COM
		UUCP:{sun,voder,nsc,decwrl}!apple!lsr

kaufman@polya.Stanford.EDU (Marc T. Kaufman) (11/27/88)

For some reason, I cannot get the "actual frequency" form of the noteCmd to
work with either the Note Synthesizer or the Wave Table Synthesizer.  Scale
pitches (<127) work OK, but I get no sound for values > 128.  The duration
portion of the command seems to be OK.  It must be me, as I have not seen
anything about this in the Tech Notes or elsewhere.  Help?

Marc Kaufman (kaufman@polya.stanford.edu)

mleonard@garnet.berkeley.edu (Michael Leonard) (02/18/89)

Hi, I have several questions about the sound manager.
I am able to create a sound channel using SndNewChannel.
I want to play a simple note using NoteCmd.
I can put the noteCmd into the channel using SndDoCommand, but
it just seems to sit there.
How can I get it to play?

Note: I am calling the Mac II traps from Allegro CommonLisp.

Thanks!

(mleonard@garnet.berkeley.edu)


Michael Leonard
(mleonard@garnet.berkeley.edu)

mleonard@garnet.berkeley.edu (Michael Leonard) (02/22/89)

In article <20533@agate.BERKELEY.EDU> mleonard@garnet.berkeley.edu (Michael Leonard) writes:
Hi, I have several questions about the sound manager.
I am able to create a sound channel using SndNewChannel.
I want to play a simple note using NoteCmd.
I can put the noteCmd into the channel using SndDoCommand, but
it just seems to sit there.
How can I get it to play?

Note: I am calling the Mac II traps from Allegro CommonLisp.

>Thanks!
>
>(mleonard@garnet.berkeley.edu)

Does nobody have the answer to this question?

Michael Leonard
(mleonard@garnet.berkeley.edu)

boone@neptune.oce.orst.edu (Jeff Boone) (03/25/89)

I'm trying to implement the Karplus/Strong plucked string algorithm using
the wave table synthesizer in the sound manager.  The algorithm requires
changing the wave table as the sound is playing.  Has anyone found a way
to do this?  Any helpful hints would be appreciated.

Jeff Boone
boone@neptune.oce.orst.edu

angst@cornu.ucsb.edu (08/06/89)

Hi, I'm posting this for a friend who does not have net access,
and I don't read this group so please send responses to me rather 
than posting them.  I will post a summary if interested parties
send me email (or if I go to some interesting parties...)

Here is what he has to say:

"I know I may be asking an old or dumb question but I need to know 
if it is possible, and if so how, to play multiple (mixed) sounds
('snd ') on a Mac (Mac II).  I'm using Think C 3.0 and I can't seem 
to get more than one sound to play at a time.

Falcon (F-16 Flight Sim) plays more than one sound at a time.  I read
in MacWeek, however, that System 7.0 WILL allow multiple sounds.  I'm
fed up with trying to read between the lines of the Inside Mac V Sound 
Manager description.  

Thanks for the help,

Christopher Bladon

life born addict breathe angel whatever paint |           Dave Stein
it up so closer to farther apart meat seeking |    angst%cornu@hub.ucsb.edu
missiles consuming rain forest infested veins |   angst%cornu@ucsbuxa.bitnet
the river flow urban needle inject carcinogen |  ...ucbvax!ucsbcsl!cornu!angst

hpoppe@bierstadt.scd.ucar.edu (Herb Poppe) (01/19/90)

I posted this previously, but I don't think it got out.

I have a Sound Manager problem:

I would like to write code that would play a sampled sound when I click
on a control. I want the "loopback" portion of the sampled sound to
play as long as the mouse button is down. When the mouse button is
released, I want any remainder of the loopback plus the portion
of the sound after the loopback to complete playing. If I then click
on the same or different control I want the same or different sound to play
in the same fashion. If I click on the same or different control while the
first sound is still playing, I don't want the second sound to start until
the first has completely finished, but I do want it to start without any
silence in between the sounds.

I have written code that accomplishes everything except for the condition
expressed in the last sentence. This is what I have done:

For each sound:
  I read the 'snd ' resource into memory.
  I move the handle high and lock the handle.
  I obtain a pointer to the sound header.
I open a sound channel, specifying the sampled synth.
When a control is clicked, TrackControl is called with an action
procedure that performs the following steps the first time (and only
the first time) it is called:
  SndDoCommand is called with a soundCmd to install the appropriate
  sound as an instrument in the channel.
  SndDoCommand is called with a freqCmd to play the sound for an
  indefinite duration.
When control returns after TrackControl, I call SndDoCommand with a
restCmd. This causes the sound to finish playing, PROVIDED no control
is clicked before the sound finishes.

If a control is clicked before the first sound has finished playing
then another soundCmd and freqCmd are queued to the channel. One of
three things will be heard depending on the value specified for the
duration of the previous restCmd:
  1) if the duration is less than the time it would take to
     completely finish playing the first sound, the first sound is truncated
     when the rest duration expires and the second sound starts to play.
  2) if the duration is greater than the time it would take to
     completely finish playing the first sound, then there is silence before
     the second sound starts to play.
  3) if the duration is equal to the time it would take to completely
     finish playing the first sound, then the first sound is not truncated
     nor does any silence occur before the second sound starts to play.

There appears to be no way to dynamically determine a duration for the
restCmd such that 3) above always holds. There appears to be no way to
determine when a sound has finished so as to hold off queueing the second
sound. Nor does there appear to be some other Sound Manager command
("finishCmd"), that I could replace restCmd with, that simply lets a
sound finish playing before the next sound command is dequeued from the
channel.

Is there a way to accomplish what I want with the existing Sound Manager?

If not, can/will a "finishCmd" be added to the next version of the Sound
Manager (the one to be released with System 7)?

Will the new Sound Manager be supported in new versions of System 6?
(Apple has said it will continue to support System 6 since it intends
to continue to sell one megabyte machines after System 7 is released).

--
Herb Poppe      NCAR                         INTERNET: hpoppe@ncar.ucar.edu
(303) 497-1296  P.O. Box 3000                   CSNET: hpoppe@ncar.CSNET
		Boulder, CO  80307               UUCP: hpoppe@ncar.UUCP

hpoppe@bierstadt.scd.ucar.edu (Herb Poppe) (01/19/90)

I posted this previously, but I don't think it got out.


I have a(nother) Sound Manager problem (system 6.0.2, Mac Plus, LSP 2.01):

I am experimenting with pitch bending effects using the rateCmd. (I want
to simulate the Doppler shift a stationary observer experiences when
hearing a sound emitted from a moving platform).

Quoting from IM V p. 490:

  cmd = rateCmd    param1 = NIL   param2 = rate

  Sets the rate at which succeeding buffer commands will be played.
  RateCmd is similar to frequencyCmd except that it lets you specify the
  rate as a multiplier of the original sampling rate; in other words,
  a rate of 2 is an octave higher, 0.667 a fifth lower. The rate is
  specified as a fixed-point number (of type Fixed).

Note the phrase "original sampling rate". I'll come back to that later.

The description above seems to imply that the rateCmd can only be used
in conjunction with the buffer command; fortunately (for what I want
to do), this is not the case. Those of you who would like to use the
rateCmd in conjunction with the bufferCmd in the manner described are 
out of luck. According to "The Sound Manager" by Jim Reekes (October
2nd, 1988) p. 34 (under Sound Manager Bugs - bufferCmd):

  Sending a bufferCmd will reset the channel's amplitude and rate
  settings. Since the amplitude is already being ignored and the rate
  isn't typically used, this problem is not of much concern at this
  time.

But I digress... The rateCmd is described in the following way in
"The Sound Manager" by Jim Reekes (October 2nd, 1988) p. 27:

  cmd=rateCmd    param1=0    param2=rate

  This command is sent by applications to modify the pitch of the
  sampled sound currently playing. The current pitch is multiplied by
  the rate in param2. It is used for pitch bending effects. The default
  rate of a channel is 1.0. To cause a pitch to fall an octave (or
  half of its frequency), send the rateCmd with param2 equal to one
  half as shown below.

  myCmd.cmd := rateCmd;
  myCmd.param1 := 0;
  myCmd.param2 := FixedRatio(1, 2);
  myErr := SndDoImmediate(myChan, myCmd);

To get a sound "currently playing", I do the following:

  I read the 'snd ' resource into memory.
  I move the handle high and lock the handle.
  I obtain a pointer to the sound header.
  I open a sound channel, specifying the sampled synth.
  SndDoCommand is called with a soundCmd to install the appropriate
  sound as an instrument in the channel.
  SndDoCommand is called with a freqCmd to play the sound for an
  indefinite duration (the sound has loopback points set).

I followed this with the code segment shown above to change the pitch of
the sound.

The first problem I had is that there is no ToolBox routine called
"FixedRatio"; rather, it is called "FixRatio".

The second problem is that 
SndDoImmediate is not appropriate for my code: I'm guessing that the sound
had not yet starting playing when the synth got the immediate rateCmd.
In any case, I didn't get any pitch bending until I replaced
SndDoImmediate with SndDoCommand.

The third problem was that a rate of 1/2 on the first sound I tried
resulted in no change in pitch. A rate of 1/1 resulted in a pitch an
octave higher; 1/4 an octave lower. It occurred to me that this effect
might be related to the original sampling rate; which, for the first
sound I tried, was 11khz. I then tried a sound sampled at 22khz. For
this sound, a rate of 1/2 gave a pitch an octave lower; 1/1 gave no
change in pitch and 2/1 gave a pitch an octave higher.

The first Sound Manager documentation quote above says "lets you specify the
rate as a multiplier of the original sampling rate". Apparently this
should read: "lets you specify the rate as a multiplier of a 22khz sampling
rate". Actually, I think the documentation is right and that this is
a Sound Manager bug. THE RATE SPECIFIED IN THE RATECMD OUGHT TO BE
RELATIVE TO THE ORIGINAL SAMPLING RATE. That is, a rate of 1/2 ought to
give a pitch an octave lower regardless of the original sampling rate.

The fourth problem surfaced when I sent a second rate command with the
same rate as the first. I got no change in pitch. The second Sound Manager
documentation quote above says "The current pitch is multiplied by
the rate in param2". Since the current pitch at the time of the second
rate command is 1/2 the original pitch, then I would have expected the
pitch after the second rate command to be 1/4 the original pitch. The first
Sound Manager documentation quote above says "lets you specify the
rate as a multiplier of the original sampling rate". Apparently, the first
quote describes the way the software works (with the exception noted above);
the second quote is wrong.

Is my third problem a bug?

If so, can/will a fix be added to the next version of the Sound
Manager (the one to be released with System 7)?

Will the new Sound Manager be supported in new versions of System 6?
(Apple has said it will continue to support System 6 since it intends
to continue to sell one megabyte machines after System 7 is released).

The rest of my problems seem to be documentation related. Although Jim
Reekes' Sound Manager document purports to replace the Sound Manager
chapter in IM V it does not include all of the information from
IM V (for example, Jim doesn't, but IM V does discuss the result codes
that can occur when calling the various Sound Manager routines), still has
errors (fourth problem) and ambiguities (I have no idea what I should
expect to hear when pauseCmd "suspends processing"). I hope Apple will rework
this documentation yet again for System 7.

--
Herb Poppe      NCAR                         INTERNET: hpoppe@ncar.ucar.edu
(303) 497-1296  P.O. Box 3000                   CSNET: hpoppe@ncar.CSNET
		Boulder, CO  80307               UUCP: hpoppe@ncar.UUCP

carr@unc.cs.unc.edu (Michael Carr) (04/10/90)

Howdy,

I'm using the Sound Manager to play a rapid series of 'snd ' resources
to simulate the sound of a snare drum being played. I had a program to
play a series of sounds in the desired tempo and it worked, but then I
added it to a larger application and the timing is now off.
I'm using the method :
1) allocate a new sound channel (w/o a synthesizer)
2) play a format 2 'snd ' resource
3) dispose of the channel 
to play the sounds. The timing is done by checking the TickCount(). Each
drumbeat has a set amount of time to play before the next one is played.
Everything was working until we took my code and changed it to a procedure
within a larger application. Now the timing is off whenever the type of
sound to play changes. But we Got all the resources before that and are
only changing the handle in SndPlay.
We're using Think C and TransSkel. 
The only things we can think of are internal Mac stuff with memory allocation 
of the snd resources, or maybe TransSkel messed up something. The resources
are preloaded and non-purgeable though. 
It's frustrating because it worked as a smaller stand-alone program but not
as part of the larger application, where it has to. If anyone has any ideas
we'd welcome them. Thanks,

			Mike Carr
			carr@cs.unc.edu

" If I repent anything, it is very likely to be my good behavior.
  What demon possessed me that I behaved so well?"  Henry David Thoreau

  Mike Carr, expressing his own opinions at:  carr@cs.unc.edu

Oi Oi Oi Oi Oi (SPLAT) <GROSSPA@QUCDN.QueensU.CA> (04/10/90)

RE: Your sound manager problems;

When you are playing the snare shots sequentially, are you IN or OUT of the
GetNextEvent loop?.  Perhaps the Mac is busy looking for events and hence
misses timing marks for the snare playback.

Perhaps I don't know what the hell I'm talking about.

tonyg@batserver.cs.uq.oz.au (Tony Gedge) (07/05/90)

I have seen the Sound Manager docs from sumex-aim and I am wondering has there
been any changes/additions to this information recently?  Has there been an
upgrade/patch/kludge released by APDA dealing with the sound manager?

Thanks in Advance,

Tony Gedge.

--
 -------------------------------------------------------------------------
| Computer Science Department,        | tonyg@batserver.cs.uq.oz.au       |
| University of Queensland, Australia.| "cc stands for Cryptic Crossword" |
 -------------------------------------------------------------------------

hpoppe@ncar.ucar.edu (Herb Poppe) (12/07/90)

What with the availability of the latest and greatest Sound Manager in 
System 6.0.7 I though I'd rework a sound application I wrote last year so 
that it will support multi-channel sampled sound. (I don't have the new 
Sound Manager chapter from IM 6; I'm assuming that all the bugs, 
restrictions, and limitations that Jim Reekes discussed in his Oct. '88 
update to the Sound Manager chapter in IM 5 have been removed. Sure would 
be nice, though, if the new Sound Manager chapter could be put up on 
apple.com; or, better yet, if the dts directory on ftp.apple.com could be 
activated.)

This time I thought I would allocate my own SndChannel records and pass a 
pointer to them to SndNewChannel instead of passing nil and having 
SndNewChannel allocate the storage each time it was called. I planned to 
allocate the records statically, and since I never have more than 3 or 4 
SndCommands in the channel I'd take advantage of the innocent sounding 
sentence that accompanies the description of SndNewChannel (page 17):

"Each channel will hold 128 commands as a default size. The length of a 
channel can be expanded by the application creating its own channel in 
memory."

(I assumed that "expanded" really meant "changed" and that I could make 
the channel smaller than 128 commands.)

I then tried to figure out how to tell SndNewChannel what the maximum 
number of SndCommands were in my SndChannel. There is no parameter to 
SndNewChannel that one can use to provide this information, nor does there 
appear to be any field in the SndChannel record:

SndChannel = PACKED RECORD
  nextChan:      SndChannelPtr;
  FirstMod:      ModifierStubPtr;
  callBack:      ProcPtr;
  userInfo:      LONGINT;
  wait:          Time;
  cmdInProgress: SndCommand;
  flags:         INTEGER;
  qLength:       INTEGER;
  qHead:         INTEGER;
  qTail:         INTEGER;
  queue:         ARRAY [0..stdQLength-1] OF SndCommand;
END;

where this information can be provided (I assume the fields qLength, 
qHead, qTail refer to the dynamic length of the channel, and not to its 
maximum size).

It seems to me, then, that SndNewChannel has no way to determine what the 
maximum length of the channel is, unless it uses a call like GetPtrSize, 
which requires that all SndChannel records be allocated in the heap by the 
Memory Manager. This in turn means that it is bad news to statically 
allocate SndChannel records. IF THIS IS SO, THIS REQUIREMENT SHOULD BE 
POINTED OUT IN THE DOCUMENTATION! Is this discussed in the IM 6 
documentation? Can SndChannel records be (safely) statically allocated?

I was just about to post this when it occurred to me that it might be 
prudent to look back at the Sound Manager chapter in IM 5. Although Jim 
Reekes' update was intended to replace the chapter in IM 5, I have 
occasionally discovered little gems of information there that weren't 
carried over into the update document.  On page V-481, "The SndChannel 
Record", it says:

"QLength specifies the number of commands that the channel can hold; it 
must always be ORD(stdQLength)."

I was apparently wrong in assuming that qLength was the dynamic length. 
Presumably I could set qLength to the length of my SndCommand array and 
SndNewChannel (or whoever) could look there for the max channel length 
without resorting to GetPtrSize. Therefore, I could statically allocate my 
SndChannel records. On the other hand, it does say: "it MUST ALWAYS be 
ORD(stdQLength)" which says I can't have records that are different in 
size from the standard, thus contradicting Jim Reekes' update.

The last paragraph on the page goes on to say:

"When you've allocated the SndChannel record yourself, the Sound Manager 
saves the state information from the pointer you pass, (calling 
HGetState)."

This says, I guess, that SndChannel records must be allocated via the 
Memory Manager (no static allocation).

So I'm left asking:

1) Am I permitted to allocate a SndChannel record smaller than the 
standard length one.

2) Must I set qLength to the number of SndCommands I've allocated before I 
call SndNewChannel?
(SndChannel.queue: ARRAY[0..SndChannel.qLength-1] OF SndCommand; in effect)

Herb Poppe             hpoppe@ncar.ucar.edu
NCAR                      (303) 497-1296
1850 Table Mesa Dr.
Boulder, CO  80307-3000

brad@gobi.jpl.nasa.gov (Brad Pickering) (02/01/91)

I know I've had my head in the sand and this has already been covered but
still I must ask, what is going on with the sound manager?  I tried to open
a channel using the calls described in IM V5 and it returns a "resource
problem" error.  I looked in the system file (6.0.5) and didn't find any of
the standard 'snth' resources.  I'm assuming things must have changed
drastically since IM V5 was published.  If this is the case then where can I
get the current information.  The example source code at apple.com for the
sound manager has a file length of 0.  The latest interface files for mpw have
different definitions than those described in IM V5.

Thanks for any help,
  Brad Pickering
  brad@gobi.jpl.nasa.gov
--
--
Brad Pickering
brad@gobi.jpl.nasa.gov
--

mab@ecmwf.co.uk (Baudouin Raoult) (03/31/91)

 I try to use the Sound Manager to play sounds sampled with MacRecorder. What I want is to play a *big* sound that does not fit in memory. I want to read my sound file in several parts and send the data to a sound command (using SoundCmd). Does anyone know how to do it ?

	Thanks, Baudouin.

Note: I have got a MacSE, system 6.0.3 if it may help.

-- 

---------------------------------------------------
Baudouin Raoult. 
European Center for Medium Range Weather Forecast
Reading, UK
---------------------------------------------------

jmunkki@hila.hut.fi (Juri Munkki) (03/31/91)

mab@ecmwf.co.uk (Baudouin Raoult) writes:
> I try to use the Sound Manager to play sounds sampled with
>MacRecorder. What I want is to play a *big* sound that does not fit in
>memory. I want to read my sound file in several parts and send the data
>to a sound command (using SoundCmd).

With system 6.07, you could just call SndStartFilePlay the way that it
is documented in Inside Macintosh VI. The sample source code given their
plays a 'snd ' resource from a file.

Since you said you are using 6.03, you could use bufferCmd and continueCmd,
but IM-VI says that a MacSE is not guaranteed to produce continuous sound
without the click, if you use these commands.

You could also take the less compatible route and find the old version
of technical note 19. This note explains how to play sounds without a
click.  This method can be applied to playing from disk, if you just
take a little time to think about it. Of course this method could break
any minute, although it hasn't, so far.

I recommend upgrading to 6.07 and trying to find a copy of IM-VI. I guess
the same information might be available in the MACE developer package that
at least used to be available from APDA. At least it should have some kind
of documentation for MACE, which should be another way to achieve what you
are trying to do.

>Does anyone know how to do it ?

Yes.

   ____________________________________________________________________________
  / Juri Munkki	    /  Helsinki University of Technology   /  Wind  / Project /
 / jmunkki@hut.fi  /  Computing Center Macintosh Support  /  Surf  /  STORM  /
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

nerm@Apple.COM (Dean Yu) (03/31/91)

In article <1991Mar30.160749.28551@ecmwf.co.uk> mab@ecmwf.co.uk (Baudouin Raoult) writes:
>
> I try to use the Sound Manager to play sounds sampled with MacRecorder. What I want is to play a *big* sound that does not fit in memory. I want to read my sound file in several parts and send the data to a sound command (using SoundCmd). Does anyone know how to do it ?

  Upgrade to 6.0.7 or 7.0 (when we get the silly thing finished) and use
_PlayFromDisk.

  -- Dean Yu
     Blue Meanie, Negative Ethnic Role Model, etc.
     Apple Computer, Inc.
     My opinions and so on and so forth...

boissier@irisa.fr (franck boissiere) (04/02/91)

From article <1991Mar31.004007.26052@santra.uucp>, by jmunkki@hila.hut.fi (Juri Munkki):
> mab@ecmwf.co.uk (Baudouin Raoult) writes:
>> I try to use the Sound Manager to play sounds sampled with
>>MacRecorder. What I want is to play a *big* sound that does not fit in
>>memory. I want to read my sound file in several parts and send the data
>>to a sound command (using SoundCmd).
> 
> With system 6.07, you could just call SndStartFilePlay the way that it
> is documented in Inside Macintosh VI. The sample source code given their
                   ^^^^^^^^^^^^^^^^^^^

Where is it. Is there any electronic version of it available (new SpInside?).

Thanks in advance

Franck
-- 
Franck BOISSIERE                        boissier@irisa.irisa.fr
C.C.E.T.T.   B.P. 59                    boissiere@ccett.fr
35512 CESSON SEVIGNE CEDEX  FRANCE    

ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) (04/03/91)

In article <50989@apple.Apple.COM>, nerm@Apple.COM (Dean Yu) writes:
> In article <1991Mar30.160749.28551@ecmwf.co.uk> mab@ecmwf.co.uk
> (Baudouin Raoult) writes:
>>
>> I try to use the Sound Manager to play sounds sampled with MacRecorder.
>> What I want is to play a *big* sound that does not fit in memory. I want
>> to read my sound file in several parts and send the data to a sound command
>> (using SoundCmd). Does anyone know how to do it ?
>
>   Upgrade to 6.0.7 or 7.0 (when we get the silly thing finished) and use
> _PlayFromDisk.

Sorry, I don't think this is going to work. Double-buffered asynchronous
continuous playback (how's that for a mouthful?) only works on machines
with an Apple Sound Chip.

Lawrence D'Oliveiro                       fone: +64-71-562-889
Computer Services Dept                     fax: +64-71-384-066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
"There is no place for sex and violence in a caring society."
	-- Malaysian government minister, commenting on proposals to
	   tighten censorship laws still further.

jmunkki@hila.hut.fi (Juri Munkki) (04/03/91)

ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
>In article <50989@apple.Apple.COM>, nerm@Apple.COM (Dean Yu) writes:
>> In article <1991Mar30.160749.28551@ecmwf.co.uk> mab@ecmwf.co.uk
>> (Baudouin Raoult) writes:
>>> I try to use the Sound Manager to play sounds sampled with MacRecorder.
>>> What I want is to play a *big* sound that does not fit in memory. I want
>>> to read my sound file in several parts and send the data to a sound command
>>> (using SoundCmd). Does anyone know how to do it ?
>>
>>   Upgrade to 6.0.7 or 7.0 (when we get the silly thing finished) and use
>> _PlayFromDisk.
>
>Sorry, I don't think this is going to work. Double-buffered asynchronous
>continuous playback (how's that for a mouthful?) only works on machines
>with an Apple Sound Chip.

MACE claims to be able to play and decompress in real time even on a MacPlus.
I know there's enough CPU power, so I wouldn't forget the new Sound Manager
before trying it first.

The alternate method is much more complicated and involves the Sound Driver.
I don't konw how well it likes the SCSI driver, but it's worth a try. The
method is described in the old technical note 19, but just in case you are
unable to find that, I'm giving a short summary here.

First, learn how to play a sampled sound buffer with the sound driver. You
should do it with the appropriate _Write (or was it _Control) command, not
with the glue routines. You need to prepare a parameter block. Make the
routine play asynchronously, so that you can do other things while the sound
is playing.

To make timings easier, you might want to install your own VBL task. This
is not absolutely necessary, but it sure helps a lot. In the simple case
of just playing a sound from disk, a VBL task would not be necessary. If
you have to do anything else, you probably need a VBL task. To be compatible
with MultiFinder, you should install a short VBL stub in the system heap.

If your output sampling rate is 22kHz, 370 samples get played between
the times that your vertical blanking routine is called (at 60 Hz).
This is also the amount of samples that are read and written at a time.
For 11kHz, this number is 185 bytes.

This technique is based on the ability to change the ioActCount on the fly.
When ioActCount reaches a certain value (preferably a multiple of 370 bytes),
reset it to the beginning of your buffer. If you filled the first half of
your sound buffer while the second was playing, your sound should play without
breaks. While the first part of the buffer is playing, fill the second half.
As long as you can read faster than the sound can play and the read routines
do not interfere with the sound generator, everything should be fine.

Of course, none of this is guaranteed to work, although I do something like
this quite successfully in another program (that program also now has an
option to use the Sound Manager).

   ____________________________________________________________________________
  / Juri Munkki	    /  Helsinki University of Technology   /  Wind  / Project /
 / jmunkki@hut.fi  /  Computing Center Macintosh Support  /  Surf  /  STORM  /
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~