// ---- End Project Data ---- // ---- File SoundTricks.t ---- // Before Script for "mainView" // copyright © 1993,1994 by Apple Computer, Inc. All rights reserved. mainView := {viewBounds: {left: -12, top: 49, right: 106, bottom: 199}, viewSetupFormScript: func() begin if not originalSound then originalSound := ROM_funbeep; if not twiceSpeedSound then begin // Note that there are currently only two allowed rates which you // can import sound resources at...11 and 22 kHz // Anything else will not work. // However, you can manipulate the samplingRate to change pitch on the fly. // See the Bitchin Piano or Heavy Metal Disco sample code for a good example of how to do this. twiceSpeedSound := Clone(ROM_funbeep); // Conveniently gets the sound. twiceSpeedSound.samplingRate := twiceSpeedSound.samplingRate * 2; // Changes speed and pitch by 2 end; /* // could set up the backward sound here directly. Or, could do it in a deferred action // so that the main view was visible immediately. However, if we do this, should provide // some visible indication that there is setting up happening. // Instead, look at the playBackwardSound button. (We defer setting up until the sound is // required the first time... if not backWardSound then AddDeferredAction(func(context) context:SetupBackwardsSound(), [self]); */ end, originalSound: nil, twiceSpeedSound: nil, backwardSound: nil, viewFlags: 581, declareSelf: 'base, viewClickScript: func(unit) begin self:Drag(unit,nil); return nil; //We haven't really handled the click end, viewQuitScript: func() begin // it's bad form to leave large structures in RAM when // the app is closed. If they must be kept around, stuff // them in a soup. (We'll just nil them out.) backwardSound := nil; originalSound := nil; twiceSpeedSound := nil; end, SetupBackwardsSound: func() begin backwardSound := DeepClone(ROM_funbeep); local sampleHolder := Clone(backwardsound.samples); local theSize := Length(sampleHolder) - 1; // subtract one because loop is 0-based. local timeCount := Ticks(); local singleSample, place; local samples := backwardSound.samples; for i := 0 to (theSize div 2) do // samples are always multiples of 4 bytes long, so div 2 is safe. begin place := theSize - i; singleSample := ExtractByte(samples, i); StuffByte(samples, i, ExtractByte(samples, place)); StuffByte(samples, place, singleSample); end; Print("Setting up with div 2 algorithm took:" && (Ticks() - timeCount)); /* // This algorithm takes up twice as much memory, but is simpler // Copies bytes from one end of the binary object to the other. local timeCount := Ticks(); local samples := backwardSound.samples; for i := 0 to theSize do StuffByte(samples, i, ExtractByte(sampleHolder,theSize-i)); Print("Setting up backwards with lame algorithm took:"&& (Ticks() - timeCount)); */ end, _proto: protoFloatNGo, debug: "mainView" }; _view000 := /* child of mainView */ {text: "Sound Tricks", viewBounds: {left: 27, top: 16, right: 94, bottom: 34}, _proto: protoStaticText }; playOriginalSoundButton := /* child of mainView */ {text: "Play Sound", viewBounds: {left: 14, top: 42, right: 106, bottom: 62}, buttonPressedScript: func() begin PlaySound(originalSound); end, _proto: protoTextButton, debug: "playOriginalSoundButton" }; // View playOriginalSoundButton is declared to mainView playTwiceSpeedSoundButton := /* child of mainView */ {text: "Play Twice Speed", viewBounds: {left: 14, top: 74, right: 106, bottom: 94}, buttonPressedScript: func() begin PlaySound(twiceSpeedSound); end, _proto: protoTextButton, debug: "playTwiceSpeedSoundButton" }; // View playTwiceSpeedSoundButton is declared to mainView playBackwardSoundButton := /* child of mainView */ {text: "Play Backwards", viewBounds: {top: 106, left: 14, right: 106, bottom: 126}, buttonPressedScript: func() begin if not backwardSound then begin SetValue(self, 'text, "Setting up..."); RefreshViews(); :Parent():SetupBackwardsSound(); RemoveSlot(self, 'text); :Dirty(); RefreshViews(); end; PlaySound(backwardSound); end, viewFlags: 515, _proto: protoTextButton, debug: "playBackwardSoundButton" }; // View playBackwardSoundButton is declared to mainView // ---- Beginning of section for non used Layout files ---- // End of output