[comp.sys.mac.programmer] How to get rid of clicking?

gurney@cpsin2.uucp (Eddy J Gurney) (06/04/90)

Well, I'm glad to say I'm making some progress generating sound on the Mac -
Thanks mostly to a some suggestions and some very helpful sample code from
a couple of c.s.m.programmer's.

Basically, I've given up on using the Sound Manager, at least until I get
some sample code on how that works.  (Does anyone know if the WaveFormSynth
is working on Mac Plus/SE's yet?  If not, it's probably useless to me anyway.
I'm running a Mac IIcx, but I want my program to run on at LEAST a Plus and
an SE.)

So... I'm using the Sound Driver to generate the simple tones I need.  I've
generated a really nice-sounding 256-byte sine-wave table, which I use as the 
waveform for the FourToneSynth.

Then I use StartSound to produce a few tones in a row, and, whatdya know,
I get TONE*crackle*TONE*crackle*TONE*crackle*.  (Sometimes.  Other times it
sounds perfect.)  IM II says something about getting rid of this, but I don't
quite understand how to do it correctly.  At most I need three tones in a
row (I'm only using two of the four channels, BTW) - sometimes there will be
a rest between the tones, sometimes, their will be none.

Also, while I'm posting... has anybody come up with a way to specify a
FREQUENCY to FTSoundRec.sound1Rate instead of the rate?  IM II gives the
equation: 
             frequency = FixMul(rate,FixRatio(22257,256))
I solved this for frequency, and got: (Actually, I had my HP-48SX do it.  I
didn't want to be flamed for not solving correctly :-)
             rate = FixRatio(frequency,FixRatio(22257,256))
Great you say, right?  BUT: FixRatio only accepts INTEGER parameters, so the
second FixRatio calculation doesn't work.  For now, I'm just using the integer
value '87', since (22257/256) = 86.94140625.  Any ideas on how to make this
more exact?  (Not that my application is that critical, I'm just curious :-)

Thanks for any help!  (MacDTS: I anxiously await seeing "SoundApp" in the
Sample Code on 'apple.com'!)

--
Eddy J. Gurney, N8FPW -- gurney@frith.egr.msu.edu   OR   17158EJG@MSU.BITNET
                         (reachable via uucp also)

oster@well.sf.ca.us (David Phillip Oster) (06/07/90)

In article <1990Jun4.020601.9644@msuinfo.cl.msu.edu> gurney@cpsin2.uucp (Eddy J Gurney) writes:
>Also, while I'm posting... has anybody come up with a way to specify a
>FREQUENCY to FTSoundRec.sound1Rate instead of the rate?  IM II gives the
>equation: 
>             frequency = FixMul(rate,FixRatio(22257,256))
>I solved this for frequency, and got: (Actually, I had my HP-48SX do it.  I
>didn't want to be flamed for not solving correctly :-)
>             rate = FixRatio(frequency,FixRatio(22257,256))
in floating point, this is:
	rate = frequency / (22257. / 256.);
Or, in fixed point:
	rate = FixDiv(FixRatio(frequency, 1), FixRatio(22257,256))

If the FixRatio(frequency, 1) offends you , you can also say:
#define FIXED(f) ( ((long) (f)) << 16)
and say	FIXED(frequency)

-- 
-- David Phillip Oster - Note new address. Old one has gone Bye Bye.
-- oster@well.sf.ca.us = {backbone}!well!oster