// Text of project SoundTricks written on 5/9/95 at 6:02 PM // Beginning of file SoundTricks.t // Before Script for "mainView" // copyright © 1993-1995 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 native () begin local int singleSample, place; local int i; backwardSound := DeepClone(ROM_funbeep); local int theSize := Length(backwardsound.samples) - 1; // subtract one because loop is 0-based. local samples := backwardSound.samples; local int timeCount := Ticks(); // gentlemen, start your engines! place := theSize; for i := 0 to (theSize div 2) do // samples are always multiples of 4 bytes long, so div 2 is safe. begin singleSample := ExtractByte(samples, i); StuffByte(samples, i, ExtractByte(samples, place)); StuffByte(samples, place, singleSample); place := place - 1; end; Print("Reversing the sound samples took:" && (Ticks() - timeCount)); end, debug: "mainView", _proto: @180 }; _view000 := {text: "Sound Tricks", viewBounds: {left: 27, top: 16, right: 94, bottom: 34}, _proto: @218 }; AddStepForm(mainView, _view000); playOriginalSoundButton := {text: "Play Sound", viewBounds: {left: 14, top: 42, right: 106, bottom: 62}, buttonPressedScript: func() begin PlaySound(originalSound); end, debug: "playOriginalSoundButton", _proto: @226 }; AddStepForm(mainView, playOriginalSoundButton); StepDeclare(mainView, playOriginalSoundButton, 'playOriginalSoundButton); playTwiceSpeedSoundButton := {text: "Play Twice Speed", viewBounds: {left: 14, top: 74, right: 106, bottom: 94}, buttonPressedScript: func() begin PlaySound(twiceSpeedSound); end, debug: "playTwiceSpeedSoundButton", _proto: @226 }; AddStepForm(mainView, playTwiceSpeedSoundButton); StepDeclare(mainView, playTwiceSpeedSoundButton, 'playTwiceSpeedSoundButton); playBackwardSoundButton := {text: "Play Backwards", viewBounds: {left: 14, top: 106, 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, debug: "playBackwardSoundButton", _proto: @226 }; AddStepForm(mainView, playBackwardSoundButton); StepDeclare(mainView, playBackwardSoundButton, 'playBackwardSoundButton); constant |layout_SoundTricks.t| := mainView; // End of file SoundTricks.t