Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!blob From: blob@Apple.COM (Brian Bechtel) Newsgroups: comp.sys.mac.programmer Subject: Re: System 7.0 Sound Manager Functionality Keywords: Sound, System 7.0 Message-ID: <51825@apple.Apple.COM> Date: 22 Apr 91 18:33:03 GMT References: <1991Apr18.203859.26265@terminator.cc.umich.edu> Distribution: usa Organization: Apple Computer Inc., Cupertino, CA Lines: 79 I asked the sound manager engineer, and he responds as follows: potts@itl.itd.umich.edu (Paul Potts) writes: > After wrestling with my code for some time, and determining that it > was operating correctly, a colleague and I dove into the system > software code to follow the frequency values, and see what happened > to them. As we suspected, the high bytes were getting stripped off, > and the values in the range 0..127 were being used to calculate > offsets from some base note such as middle C. > Meanwhile, does anyone have ideas on a better way to do this? I > can't be the only one out there who needs to be able to play sounds > at arbitrary frequencies. Doesn't anyone need to play notes at > non-Western intervals? > Please reply to me to potts@itl.itd.umich.edu. > If I get interesting responses, I'll post them. > -Paul Potts- > Consultant, Office of Instructional Technology > Information Technology Division, University of Michigan Getting the frequencies that you want only requires some math and the common Sound Manager routines. Here's how to generate arbitrary frequencies using sampled sounds. You have to start with the original sample rate and know the frequency that was sampled. For example, if you sampled a 440 Hz pitch at 11kHz and want it to be played at 460 Hz you calculate a new sample rate. Take the ratio of 460/440 as a fixed point number. Multiply this ratio with the original sample rate of 11kHz. Put this number into the sound header's sample rate and use it with a bufferCmd. You'll play your sound back at 460 Hz. There are some problems to look out for. You have to be careful with getting overflow in you equations. Fixed point numbers have an upper range of 65k, otherwise they become negative numbers. So, some sample rates and pitches cannot be created. You will not be able to take a 22kHz sampled sound and play it back three octaves higher. You could use SANE to calculate the number with more precision, but you still need to be careful with overflow. Also, you cannot use SANE at interrupt level. There has NOT been any "important functionality" that was removed from the Sound Manager. Only frequency values of 0..127 are supported. This is properly documented in Inside Mac VI. Arbitrary frequencies are not, and never been supported. The freqCmd is exactly the same as the freqDurationCmd but does not have an associated duration. All version of the Sound Manager, including what is shipping in System 7, does not support anything other than values of 0..127. The Sound Manager doesn't support this for a few reasons. The Sound Manager has no way of determining the original frequency of the sound. A baseNote of 56 may be a pitch of 440 Hz, but what if the original pitch wasn't in equal temperament (a pitch between the notes of a piano)? It's impossible to represent this in the Sound Header. Additionally, to support frequencies we will need a new sound command. The freqCmd was documented as having its high byte used for amplitude. This only leaves three bytes to represent a frequency, but it should be a Fixed type number. Unfortunately this was not part of the original plans for the new Sound Manager release and it was also not considered important in the big picture. Few developers have asked for the feature. Additionally, at the time we realized we needed a new command for frequencies it was too late to add any new features. Inside Mac and the MPW interfaces was frozen, and we had an agreement with developers not to change the API. The Sound Header was changed when the original MACE package was released. This was done in 1989. The MPW Sound interfaces have been incorrect since then. The former field "baseNote" which was a word (with the high byte always being ignored) is now two fields. This change cause no problems for existing applications. Applications being compiled against the System 7 interfaces may have to be changed slightly, with little effort. Jim Reekes E.O., Macintosh Toolbox Engineering Sound Manager Engineer