'From Squeak3.2gamma of 15 January 2002 [latest update: #4811] on 25 July 2002 at 11:41:53 pm'! Object subclass: #SineWaveGenerator instanceVariableNames: 'magnitude step current initialPhase ' classVariableNames: '' poolDictionaries: '' category: 'Sound-Waves'! !SineWaveGenerator methodsFor: 'initialize' stamp: 'tf 7/25/2002 21:25'! initialPhase:phase initialPhase _ phase.! ! !SineWaveGenerator methodsFor: 'initialize' stamp: 'tf 7/25/2002 21:27'! initialize initialPhase _ 0.0. magnitude _ 1.0. step _ 1.0. current _ initialPhase.! ! !SineWaveGenerator methodsFor: 'initialize' stamp: 'tf 7/25/2002 21:24'! magnitude:aMagnitude magnitude _ aMagnitude. ! ! !SineWaveGenerator methodsFor: 'initialize' stamp: 'tf 7/25/2002 21:25'! oneCycle:oneCycle step _ (360 /oneCycle) asFloat. ! ! !SineWaveGenerator methodsFor: 'initialize' stamp: 'tf 7/25/2002 21:24'! step:aStep step _ aStep.! ! !SineWaveGenerator methodsFor: 'accessing' stamp: 'tf 7/25/2002 21:28'! initialPhase ^initialPhase! ! !SineWaveGenerator methodsFor: 'accessing' stamp: 'tf 7/25/2002 21:28'! magnitude ^magnitude! ! !SineWaveGenerator methodsFor: 'accessing' stamp: 'tf 7/25/2002 21:01'! next | ans | ans _ (current degreeSin * magnitude). current _ current + step. (current >= 360) ifTrue:[ current _ current \\ 360. ]. ^ans.! ! !SineWaveGenerator methodsFor: 'accessing' stamp: 'tf 7/25/2002 21:28'! oneCycle ^360.0 / step.! ! !SineWaveGenerator methodsFor: 'accessing' stamp: 'tf 7/25/2002 22:17'! reset current _ initialPhase.! ! !SineWaveGenerator methodsFor: 'accessing' stamp: 'tf 7/25/2002 21:28'! step ^step.! ! !SineWaveGenerator methodsFor: 'testing' stamp: 'tf 7/25/2002 22:22'! showOnDisplay | xOrigin yOrigin y | xOrigin _ 30. yOrigin _ 130. self reset. Display fillBlack: (xOrigin@(yOrigin - 100) extent: 1@100). xOrigin to:(xOrigin + 200) do:[ :x | y _ (self next * 100.0) + yOrigin. Display fillBlack: ((x - 1)@(y - 1) extent: 2@2). Display fillBlack: (x@yOrigin extent: 1@1). x _ x + 1 ]. ! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! SineWaveGenerator class instanceVariableNames: ''! !SineWaveGenerator class methodsFor: 'examples' stamp: 'tf 7/25/2002 21:30'! example1 | tmp | tmp _ self new initialize. tmp oneCycle:20. 22 timesRepeat:[ Transcript show:(tmp next printString); cr. ]. ! ! !SineWaveGenerator class methodsFor: 'examples' stamp: 'tf 7/25/2002 22:22'! example2 ((SineWaveGenerator new initialize magnitude:1.0) oneCycle:100.0) showOnDisplay. ! !