The Trunk: Sound-mt.56.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Sound-mt.56.mcz

commits-2
Marcel Taeumel uploaded a new version of Sound to project The Trunk:
http://source.squeak.org/trunk/Sound-mt.56.mcz

==================== Summary ====================

Name: Sound-mt.56
Author: mt
Time: 28 April 2016, 2:34:02.190031 pm
UUID: 24fb4170-db03-d446-88d6-bc68d542761c
Ancestors: Sound-mt.55

Due to excessive use of the shut-down-mechanism in sound code, fix all the places where #shutDown was called but nowadays #shutDown: is implemented.

Now, you can safely to this again:

SoundPlayer stopReverb. "revert with #startReverb"
TrashCanMorph playDeleteSound.

=============== Diff against Sound-mt.55 ===============

Item was changed:
  ----- Method: AbstractSound class>>testFMInteractively (in category 'examples') -----
  testFMInteractively
  "Experiment with different settings of the FM modulation and multiplier settings interactively by moving the mouse. The top-left corner of the screen is 0 for both parameters. Stop when the mouse is pressed."
  "AbstractSound testFMInteractively"
 
  | s mousePt lastVal status mod ratio |
  SoundPlayer startPlayerProcessBufferSize: 1100 rate: 11025 stereo: false.
  s := FMSound pitch: 440.0 dur: 200.0 loudness: 0.2.
 
  SoundPlayer playSound: s.
  lastVal := nil.
  [Sensor anyButtonPressed] whileFalse: [
  mousePt := Sensor cursorPoint.
  mousePt ~= lastVal ifTrue: [
  mod := mousePt x asFloat / 20.0.
  ratio := mousePt y asFloat / 20.0.
  s modulation: mod ratio: ratio.
  lastVal := mousePt.
  status :=
  'mod: ', mod printString, '
  ratio: ', ratio printString.
  status displayOn: Display at: 10@10]].
 
+ SoundPlayer shutDown: true.
- SoundPlayer shutDown.
  !

Item was changed:
  ----- Method: MIDISynth class>>example (in category 'examples') -----
  example
  "Here's one way to run the MIDI synth. It will get a nice Morphic UI later. Click the mouse to stop running it. (Mac users note: be sure you have MIDI interface adaptor plugged in, or Squeak will hang waiting for the external clock signal.)."
  "MIDISynth example"
 
  | portNum synth |
  portNum := SimpleMIDIPort inputPortNumFromUser.
  portNum ifNil: [^ self].
  SoundPlayer useShortBuffer.
  synth := MIDISynth new
  midiPort: (SimpleMIDIPort openOnPortNumber: portNum).
  synth midiParser ignoreCommand: 224.  "filter out pitch bends"
  1 to: 16 do: [:i |
  (synth channel: i) instrument:
    (AbstractSound soundNamed: 'oboe1')].
  1 to: 16 do: [:ch | synth volumeForChannel: ch put: 0.2].
 
  synth processMIDIUntilMouseDown.
+ SoundPlayer shutDown: true; initialize.  "revert to normal buffer size"
- SoundPlayer shutDown; initialize.  "revert to normal buffer size"
  !

Item was changed:
  ----- Method: MIDISynth>>stopMIDITracking (in category 'as yet unclassified') -----
  stopMIDITracking
 
  process ifNotNil: [
  process terminate.
  process := nil].
+ SoundPlayer shutDown: true; initialize.  "revert to normal buffer size"
- SoundPlayer shutDown; initialize.  "revert to normal buffer size"
  !

Item was changed:
  ----- Method: SoundPlayer class>>boinkScale (in category 'primitive test') -----
  boinkScale
  "Tests the sound output primitives by playing a scale."
  "SoundPlayer boinkScale"
 
  | sineTable pan |
+ self shutDown: true.
- self shutDown.
  SamplingRate := 11025.
  Stereo := true.
  sineTable := self sineTable: 1000.
  Buffer := SoundBuffer newStereoSampleCount: 1000.
  BufferIndex := 1.
  self primSoundStartBufferSize: Buffer stereoSampleCount
  rate: SamplingRate
  stereo: Stereo.
  pan := 0.
  #(261.626 293.665 329.628 349.229 391.996 440.001 493.884 523.252) do: [:p |
  self boinkPitch: p dur: 0.3 loudness: 300 waveTable: sineTable pan: pan.
  pan := pan + 125].
 
  self boinkPitch: 261.626 dur: 1.0 loudness: 300 waveTable: sineTable pan: 500.
  self primSoundStop.
+ self shutDown: true.
- self shutDown.
  SoundPlayer initialize.  "reset sampling rate, buffer size, and stereo flag"
  !

Item was changed:
  ----- Method: SoundPlayer class>>playLoop (in category 'player process') -----
  playLoop
  "The sound player process loop."
  | bytesPerSlice count willStop mayStop |
  mayStop := self stopSoundWhenDone.
  bytesPerSlice := Stereo ifTrue: [4] ifFalse: [2].
  [
  [(count := self primSoundAvailableBytes // bytesPerSlice) > 100]
  whileFalse: [ReadyForBuffer wait].
 
  count := count min: Buffer stereoSampleCount.
  PlayerSemaphore critical: [
  ActiveSounds := ActiveSounds select: [:snd | snd samplesRemaining > 0].
  ActiveSounds do: [:snd |
  snd ~~ SoundJustStarted ifTrue: [
  snd playSampleCount: count into: Buffer startingAt: 1]].
  ReverbState == nil ifFalse: [
  ReverbState applyReverbTo: Buffer startingAt: 1 count: count].
  self primSoundPlaySamples: count from: Buffer startingAt: 1.
  willStop := mayStop and:[
  (ActiveSounds size = 0) and:[
  self isAllSilence: Buffer size: count]].
  LastBuffer ifNotNil:[
  LastBuffer replaceFrom: 1 to: LastBuffer size with: Buffer startingAt: 1.
  ].
  willStop
+ ifTrue:[self shutDown: true. PlayerProcess := nil]
- ifTrue:[self shutDown. PlayerProcess := nil]
  ifFalse:[Buffer primFill: 0].
  SoundJustStarted := nil].
  willStop ifTrue:[^self] ] repeat
  !

Item was changed:
  ----- Method: SoundPlayer class>>useShortBuffer (in category 'initialization') -----
  useShortBuffer
  "Experimental support for real-time MIDI input. This only works on platforms whose hardware allows very short buffer sizes. It has been tested on a Macintosh Powerbook G3."
  "SoundPlayer useShortBuffer"
 
+ self shutDown: true.
- self shutDown.
  BufferMSecs := 15.
  SoundPlayer
  startPlayerProcessBufferSize: (BufferMSecs * SamplingRate) // 1000
  rate: SamplingRate
  stereo: Stereo.
  !

Item was changed:
  ----- Method: SoundRecorder>>startRecording (in category 'recording controls') -----
  startRecording
  "Turn on the sound input driver and start the recording process. Initially, recording is paused.
  If the primStartRecordingDesiredSampleRate:... fails it almost certainly means we have no usable
  sound input device. Rather than having the prim raise a failure error we let it quietly do nothing
  (since I hate trying to debug errors inside a critical block) and check the actual sampling rate later.
  If the sampling rate is 0 we know the startup failed and raise an application level Signal to let any
  user code know about the problem.
  You might think we should also use the stopRecording message to close things down cleanly but
  that simply results in astorm of attempts to start recording so it is simpler to let it be deluded. An
  attempts to start recording will repeat the test and thereby handle any plug-in hardware etc."
 
  recordLevel ifNil: [recordLevel := 0.5].  "lazy initialization"
+ CanRecordWhilePlaying ifFalse: [SoundPlayer shutDown: true].
- CanRecordWhilePlaying ifFalse: [SoundPlayer shutDown].
  recordProcess ifNotNil: [self stopRecording].
  paused := true.
  meteringBuffer := SoundBuffer newMonoSampleCount: 1024.
  meterLevel := 0.
  self allocateBuffer.
  Smalltalk newExternalSemaphoreDo: [ :semaphore :index |
  bufferAvailableSema := semaphore.
  self primStartRecordingDesiredSampleRate: samplingRate asInteger
  stereo: stereo
  semaIndex: index ].
  RecorderActive := true.
  samplingRate := self primGetActualRecordingSampleRate.
  samplingRate = 0 ifTrue: [ Warning signal: 'SoundRecorder: unable to connect to sound input device'].
  self primSetRecordLevel: (1000.0 * recordLevel) asInteger.
  recordProcess := [self recordLoop] newProcess.
  recordProcess priority: Processor userInterruptPriority.
  recordProcess resume!