Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!umich!terminator!usenet From: potts@itl.itd.umich.edu (Paul Potts) Newsgroups: comp.sys.mac.programmer Subject: System 7.0 Sound Manager Functionality Keywords: Sound, System 7.0 Message-ID: <1991Apr18.203859.26265@terminator.cc.umich.edu> Date: 18 Apr 91 20:38:59 GMT Sender: usenet@terminator.cc.umich.edu (usenet news) Distribution: usa Organization: Instructional Technology Laboratory, University of Michigan Lines: 121 Hi all, I've got a number of questions and concerns about the Sound Manager. I'm currently working with System 7.0B6, Think C with the revisions and header files from the Beta 4 CD, a standalone version of Rez, and the .r files from the Beta 4 CD as well. My current project is a simulation of an audiometer, a device used to test hearing. The device generates tones at precise pitches and levels (750Hz at 60 dB, for example). These pitches must be generated for an arbitrary length of time, say, for as long as the mouse is held down. Since this is a simulation, the dB levels played through the headphones don't need to be very accurate, but the pitches should be reasonably so. The simulation is in Hypercard, but I have experience writing XCMDs and intend to move the sound- play functions to an XCMD. For the prototype of this stack, I first used SoundEdit to create samples of sine waves at various frequencies, and saved them as tenth-of-a-second samples. I then hand- edited the endpoints of the waves to eliminate, as much as possible, any clicking, and play these sounds using repeated calls to Hypercard's "play" function. The results are surprisingly good. Some of the frequencies generate clicks when played back-to-back like this, but most of the lower ones don't. SoundEdit can only produce these tones at volumes ranging from 0..100%, and I would eventually like to have finer control than that, but hey, the prototype works. Now that it is time to turn the project from prototye into a development version, I want to use the square- wave synthesizer to generate these tones. According to the documentation on the beta 1 CD (until recently, all I had), it was possible to use freqCmds and noteCmds (now called freqDurationCmds) to play tones in two ways. The first was to pass a value in param2 of the sound command in the range 1..127. The value was to be interpreted as a MIDI note value. The second was to send the actual frequency at which to play the note (as long as the frequency was greater than 127). This is the method I began attempting to use, and wrote code to set up a sound channel and pass the appropriate commands to it. I immediately began to notice a problem. Values in the range 1..127 played properly, but larger values didn't. Values between 127 and 255 seemed to map back to values in the range 1..127, producing strange tones. Values like 250, 500, 750, 1000, etc. - the exact tones I want my simulation to reproduce - all produced the same extremely high pitch. 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. All this magic happens in one of the snth resources. When I finally got access to the beta 4 CD/ROM and a later draft of IM-6, I found that, in fact, the documentation had been changed to reflect what was actually going on. It seems that it is now only legal to pass values in the range 1..127 to either freqCmds or freqDurationCmds. Also, the SoundHeader data structure has been slightly redefined. The field baseFrequency, formerly a word, has been altered to two Byte fields. The high byte is now used to select the encoding option, and only a byte is left to select the base frequency. This was altered to support different encoding options, but perhaps a better method of extending the data structure could have been found, one which didn't require cutting the baseFrequency down to one byte. Now I've got to look at other ways to play the sounds. I have created a wave table out of a single sine wave, but I can't use rateCmds with a waveTable, and have to use the MIDI values again. I can play the single wave using the sampled sound synthesizer, but it can only be played at note values, comes out too low. I will try using rateCmd to play the wave at various frequencies, but I'm not sanguine about my ability to use the base frequency together with rateCmds to come up with appropriate pitches. 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? I would attempt to do this myself using the older Sound Driver calls, but they look very difficult, and besides, they probably will not be well-supported in the future. If any Apple employees are reading, perhaps you have a better perspective on the reasons that this important functionality was removed from the Sound Manager. Since this is my first project using the Sound Manager, I'm not dead-certain that playing notes at arbitrary frequencies ever worked (especially since the documentation I was using was a draft). But it is something I would dearly love to use. Sorry to be so long-winded, and thanks for reading. 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 :x