Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!waikato.ac.nz!ldo From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) Newsgroups: comp.sys.mac.programmer Subject: Re: System 7.0 Sound Manager Functionality Message-ID: <1991Apr26.152439.3551@waikato.ac.nz> Date: 26 Apr 91 03:24:39 GMT References: <1991Apr18.203859.26265@terminator.cc.umich.edu> Distribution: usa Organization: University of Waikato, Hamilton, New Zealand Lines: 48 I recently implemented an XCMD in HyperCard 2.0 that puts up a window on which you can play notes. You hold down the mouse button anywhere within the window, and it works out a pitch based on the position of the pointer. While holding the button down, you can move the pointer within the window, and the pitch changes accordingly. It even changes smoothly, if you don't move the pointer too fast. The way I did this is as follows. * As soon as the button is pressed, I find my sound data and allocate a sound channel. * I feed a soundCmd command into the channel to specify the sound to be played, followed by an ampCmd command to set the amplitude to zero, and finally a freqCmd to start an indefinite-duration sound playing, at the pitch of the sound's base note. * I then use a getRateCmd to find the current relative sampling rate. Note that some versions of the sound documentation indicate that getRateCmd returns the current rate in param2; this is INCORRECT. Instead, you must pass the address of a variable of type Fixed in param2, and this will be set to the current rate. By the way, I send all my commands in this application with SndDoImmediate, as I don't need any queueing, but this is probably unimportant. + I determine the current mouse position, and work out a new sample rate, if I remember correctly as follows (noteNumber may have a fractional part, and may be negative after the second line): noteNumber := (mousePos.h - leftWindowEdge) / windowWidth * scale; noteNumber := noteNumber - baseNoteOfSound; newRate := originalRate * 2 ** (noteNumber / 12) * I then set the new rate with a rateCmd, followed by an ampCmd to change the amplitude to 255 (maximum), so the user actually hears the sound playing. * If the mouse position should change before the button is released, I loop again from the step marked "+". * When the user releases the mouse button, I send a quietCmd to cut the sound, and deallocate the channel. 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 You are in a twisty little maze of Word 4.0 dialog boxes, all different.