d6maca@dtek.chalmers.se (Martin Carlberg) (07/27/90)
I want to generate sounds consisting of two simultaneous tones of different frequencies (the sounds generated by a touchtone telephone). Reading Inside Macintosh about the Sound Manager I find out that I would probably get the desired effect by using the wave table synthesizer, which can deliver up to four simultaneous tones. There is a Sound Manager command called freqCmd where IM says: "If no sound is playing, it causes the synthesizer to begin playing at the specified frequency for an indefinite duration." and "A frequency value is sent in the lower three bytes of param2, where the frequency desired is multiplied by 256." This is fine for me, I create two channels using the wave table synth, makes a sine wave table, and send one freqCmd to each channel, and sound doesn't stream out of my speaker. It's very quiet (well, there is a fan and a hard disk in my Mac). This is a piece of Pascal code that does not produce sound: PROGRAM Frequency; USES Sound; VAR channel: SndChannelPtr; firstCmd, secondCmd: SndCommand; FUNCTION SineWave: Ptr; EXTERNAL; { Makes nice waves } PROCEDURE BombOnError (result: OSErr); EXTERNAL; { Tests for error } BEGIN channel := NIL; BombOnError (SndNewChannel (channel, waveTableSynth, 0, NIL)); firstCmd.cmd := waveTableCmd; firstCmd.param1 := 512; firstCmd.param2 := LONGINT (SineWave); BombOnError (SndDoCommand (channel, firstCmd, TRUE)); { The following should start a continious sound } secondCmd.cmd := freqCmd; secondCmd.param1 := 0; secondCmd.param2 := 440 * 256; BombOnError (SndDoCommand (channel, secondCmd, TRUE)); WHILE (TRUE) DO; { Sound forever... } BombOnError (SndDisposeChannel (channel, TRUE)); END. It could use the old faithful Sound Driver, but I don't like to use something that has got a replacement. Anyone has a clue? Thanks in advance, - Martin Carlberg (d6maca@dtek.chalmers.se) - Chalmers University of Technology, Goteborg, Sweden
oster@well.sf.ca.us (David Phillip Oster) (07/29/90)
If you read the restrictions and limitations section of the Sound Manager chapter, you will see that you can't generate two simultaneous tones (or more) with it on a MacPlus or an SE. It simply doesn't work. Probably the best thing to do is check the hardware in SysEnvirons, and if it is an original mac, a Mac XL, a Mac 512k, 512KE, Plus or SE use sound driver, and use sound manager for everything else. This should protect you from future machines failing to implement sound driver, but it is a pain. Since you have to write the sound driver stuff anyway to get it to work on the 6 machine types I've already listed, and since Sound Driver works on all current macs, there is a strong temptation to just do it in Sound Driver and be done with it. I've dissassembled hypercard, looking to see how it does it. It calls Sound Driver on all machines, for touch tone sounds. -- -- David Phillip Oster - Note new signature. Old one has gone Bye Bye. -- oster@well.sf.ca.us = {backbone}!well!oster