The Trunk: Sound-nice.38.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-nice.38.mcz

commits-2
Nicolas Cellier uploaded a new version of Sound to project The Trunk:
http://source.squeak.org/trunk/Sound-nice.38.mcz

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

Name: Sound-nice.38
Author: nice
Time: 25 December 2013, 11:27:25.908 pm
UUID: b626daf0-be23-4fb8-b2d5-04b9cd370539
Ancestors: Sound-fbs.37

Change a few print:(aFloat roundTo: 0.01) into nextPutAll:(aFloat printShowingMaxDecimalPlaces: 2)

=============== Diff against Sound-fbs.37 ===============

Item was changed:
  ----- Method: FWT>>viewPhiAndPsi (in category 'testing') -----
  viewPhiAndPsi  "(FWT new nSamples: 256 nLevels: 6) viewPhiAndPsi"
  "View the scaling function and mother wavelets for this transform"
  | p |
  Display fillWhite: (0@0 extent: 300@300).
  Display border: (0@0 extent: 300@300) width: 2.
  [Sensor anyButtonPressed] whileFalse:
  ["Move mouse around in the outer rectangle to explore"
  p := Sensor cursorPoint min: 300@300.
  self setAlpha: (p x - 150) / 150.0 * Float pi
  beta: (p y - 150) / 150.0 * Float pi.
+ 'alpha=', (alpha printShowingMaxDecimalPlaces: 2), '   ',
+ 'beta=', (beta printShowingMaxDecimalPlaces: 2), '    ' displayAt: 50@5.
- 'alpha=', (alpha roundTo: 0.01) printString, '   ',
- 'beta=', (beta roundTo: 0.01) printString, '    ' displayAt: 50@5.
  transform do: [:w | w atAllPut: 0.0].
  (transform at: transform size - 1) at: (nSamples>>nLevels) put: 1.0.
  self transformForward: false.
  FFT new plot: (samples copyFrom: 1 to: nSamples) in: (20@30 extent: nSamples@100).
 
  transform do: [:w | w atAllPut: 0.0].
  (transform at: transform size) at: (nSamples>>nLevels) put: 1.0.
  self transformForward: false.
  FFT new plot: (samples copyFrom: 1 to: nSamples) in: (20@170 extent: nSamples@100)].
  Sensor waitNoButton!

Item was changed:
  ----- Method: SoundRecorder>>segmentsAbove:normalizedVolume: (in category 'trimming') -----
  segmentsAbove: threshold normalizedVolume: percentOfMaxVolume
  "Break the current recording up into a sequence of sound segments separated by silences."
 
  | dcOffset firstPlace endPlace resultBuf nFactor lastPlace segments gapSize minDur minLull soundSize restSize max min sum totalSamples |
  stereo ifTrue: [self error: 'stereo trimming is not yet supported'].
  paused ifFalse: [self error: 'must stop recording before trimming'].
  (recordedSound == nil or: [recordedSound sounds isEmpty]) ifTrue:[^ self].
  "Reconstruct buffers so old trimming code will work"
  recordedBuffers := recordedSound sounds collect: [:snd | snd samples].
  soundSize := restSize := 0.
 
  max := min := sum := totalSamples := 0.
  recordedBuffers do: [:buf | | bufSize s |
  bufSize := buf size.
  totalSamples := totalSamples + buf size.
  1 to: bufSize do: [:i |
  s := buf at: i.
  s > max ifTrue: [max := s].
  s < min ifTrue: [min := s].
  sum := sum + s]].
  dcOffset := sum // totalSamples.
 
  minDur := (samplingRate/20.0) asInteger.  " 1/20 second "
  minLull := (samplingRate/4.0) asInteger.  " 1/2 second "
  segments := SequentialSound new.
  endPlace := self endPlace.
  lastPlace := #(1 1).
  [firstPlace := self scanForStartThreshold: threshold
  dcOffset: dcOffset
  minDur: minDur
  startingAt: lastPlace.
  firstPlace = endPlace]
  whileFalse:
  [firstPlace = lastPlace ifFalse:
  ["Add a silence equal to the gap size"
  "Wasteful but simple way to get gap size..."
  gapSize := (self copyFrom: lastPlace to: firstPlace
  normalize: 1000 dcOffset: dcOffset) size - 2.
  "... -2 makes up for overlap of one sample on either end"
  segments add: (RestSound dur: gapSize asFloat / samplingRate).
  restSize := restSize + gapSize.
  "Transcript cr; print: firstPlace; space; print: lastPlace; space; print: gapSize; space; show: 'gap'."
  ].
  lastPlace := self scanForEndThreshold: threshold
  dcOffset: dcOffset
  minLull: minLull + minDur
  startingAt: firstPlace.
  "Allow room for lead time of next sound"
  lastPlace := self place: lastPlace plus: minDur negated.
  nFactor := self normalizeFactorFor: percentOfMaxVolume
  min: min max: max dcOffset: dcOffset.
  resultBuf := self copyFrom: firstPlace to: lastPlace
  normalize: nFactor dcOffset: dcOffset.
  soundSize := soundSize + resultBuf size.
  "Transcript cr; print: firstPlace; space; print: lastPlace; space; print: resultBuf size; space; show: 'sound'."
  segments add: (codec == nil
  ifTrue: [SampledSound new setSamples: resultBuf samplingRate: samplingRate]
  ifFalse: [codec compressSound: (SampledSound new setSamples: resultBuf samplingRate: samplingRate)])].
 
  "Final gap for consistency"
  gapSize := (self copyFrom: lastPlace to: self endPlace
  normalize: 1000 dcOffset: dcOffset) size - 1.
  segments add: (RestSound dur: gapSize asFloat / samplingRate).
  restSize := restSize + gapSize.
+ self inform: (soundSize+restSize/samplingRate printShowingMaxDecimalPlaces: 1) , ' secs reduced to ' , (soundSize/samplingRate printShowingMaxDecimalPlaces: 1).
- self inform: ((soundSize+restSize/samplingRate) roundTo: 0.1) printString , ' secs reduced to ' , ((soundSize/samplingRate) roundTo: 0.1) printString.
  recordedBuffers := nil.
  ^ segments!

Item was changed:
  ----- Method: TempoEvent>>printOn: (in category 'as yet unclassified') -----
  printOn: aStream
 
  aStream nextPut: $(.
  time printOn: aStream.
  aStream nextPutAll: ': tempo '.
+ aStream nextPutAll:  (120.0 * (500000.0 / tempo) printShowingMaxDecimalPlaces: 2).
- ((120.0 * (500000.0 / tempo)) roundTo: 0.01) printOn: aStream.
  aStream nextPut: $).
  !