A new version of Sound was added to project The Inbox:
http://source.squeak.org/inbox/Sound-ul.39.mcz ==================== Summary ==================== Name: Sound-ul.39 Author: ul Time: 24 October 2014, 3:35:35.769 am UUID: 1213f069-b625-4066-9ee8-8ea1619f2af0 Ancestors: Sound-nice.38 - use ExternalSemaphoreTable directly =============== Diff against Sound-nice.38 =============== Item was changed: ----- Method: SoundPlayer class>>startPlayerProcessBufferSize:rate:stereo:sound: (in category 'player process') ----- startPlayerProcessBufferSize: bufferSize rate: samplesPerSecond stereo: stereoFlag sound: aSound "Start the sound player process. Terminate the old process, if any." "SoundPlayer startPlayerProcessBufferSize: 1000 rate: 11025 stereo: false" self stopPlayerProcess. aSound ifNil:[ActiveSounds := OrderedCollection new] ifNotNil:[ActiveSounds := OrderedCollection with: aSound]. Buffer := SoundBuffer newStereoSampleCount: (bufferSize // 4) * 4. LastBuffer ifNotNil:[LastBuffer := SoundBuffer basicNew: Buffer basicSize]. PlayerSemaphore := Semaphore forMutualExclusion. SamplingRate := samplesPerSecond. Stereo := stereoFlag. + ReadyForBuffer := ExternalSemaphoreTable newExternalSemaphore. - ReadyForBuffer := Semaphore new. SoundSupported := true. "Assume so" UseReadySemaphore := true. "set to false if ready semaphore not supported by VM" self primSoundStartBufferSize: Buffer stereoSampleCount rate: samplesPerSecond stereo: Stereo + semaIndex: ReadyForBuffer indexInExternalObjectsArray. - semaIndex: (Smalltalk registerExternalObject: ReadyForBuffer). "Check if sound start prim was successful" + SoundSupported ifFalse:[ + ExternalSemaphoreTable unregisterExternalObject: ReadyForBuffer. + ^self]. - SoundSupported ifFalse:[^self]. UseReadySemaphore ifTrue: [PlayerProcess := [SoundPlayer playLoop] newProcess] ifFalse: [PlayerProcess := [SoundPlayer oldStylePlayLoop] newProcess]. UseReverb ifTrue: [self startReverb]. PlayerProcess priority: Processor userInterruptPriority. PlayerProcess resume.! Item was changed: ----- Method: SoundPlayer class>>stopPlayerProcess (in category 'player process') ----- stopPlayerProcess "Stop the sound player process." "SoundPlayer stopPlayerProcess" (PlayerProcess == nil or:[PlayerProcess == Processor activeProcess]) ifFalse:[PlayerProcess terminate]. PlayerProcess := nil. self primSoundStop. ActiveSounds := OrderedCollection new. Buffer := nil. PlayerSemaphore := Semaphore forMutualExclusion. ReadyForBuffer ifNotNil: + [ExternalSemaphoreTable unregisterExternalObject: ReadyForBuffer]. - [Smalltalk unregisterExternalObject: ReadyForBuffer]. ReadyForBuffer := nil. ! Item was changed: ----- Method: SoundRecorder>>startRecording (in category 'recording controls') ----- startRecording "Turn of the sound input driver and start the recording process. Initially, recording is paused." - | semaIndex | recordLevel ifNil: [recordLevel := 0.5]. "lazy initialization" CanRecordWhilePlaying ifFalse: [SoundPlayer shutDown]. recordProcess ifNotNil: [self stopRecording]. paused := true. meteringBuffer := SoundBuffer newMonoSampleCount: 1024. meterLevel := 0. self allocateBuffer. + bufferAvailableSema := ExternalSemaphoreTable newExternalSemaphore. - bufferAvailableSema := Semaphore new. - semaIndex := Smalltalk registerExternalObject: bufferAvailableSema. self primStartRecordingDesiredSampleRate: samplingRate asInteger stereo: stereo + semaIndex: bufferAvailableSema indexInExternalObjectsArray. - semaIndex: semaIndex. RecorderActive := true. samplingRate := self primGetActualRecordingSampleRate. self primSetRecordLevel: (1000.0 * recordLevel) asInteger. recordProcess := [self recordLoop] newProcess. recordProcess priority: Processor userInterruptPriority. + recordProcess resume! - recordProcess resume. - ! Item was changed: ----- Method: SoundRecorder>>stopRecording (in category 'recording controls') ----- stopRecording "Stop the recording process and turn of the sound input driver." recordProcess ifNotNil: [recordProcess terminate]. recordProcess := nil. self primStopRecording. RecorderActive := false. + ExternalSemaphoreTable unregisterExternalObject: bufferAvailableSema. - Smalltalk unregisterExternalObject: bufferAvailableSema. ((currentBuffer ~~ nil) and: [nextIndex > 1]) ifTrue: [self emitPartialBuffer]. self initializeRecordingState. ! |
Free forum by Nabble | Edit this page |