emj365 / as3wavsound

Automatically exported from code.google.com/p/as3wavsound
Other
0 stars 0 forks source link

leftPeak & rightPeak values don't seem to correspond to volume #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Added function to measure volume: 
(100 * ((channel.leftPeak + channel.rightPeak) / 2.0))

2. Value was always very low (or 0), so I decided to measure each value in 
function buffer.

Recorded sample was soft, then loud, then soft. The number seem all over the 
place.

Sample output attached.

Original issue reported on code.google.com by jordanth...@gmail.com on 25 May 2012 at 5:05

Attachments:

GoogleCodeExporter commented 9 years ago
here is a fix that gives a more useable value
Replace this code in WavSoundChannel.as (buffer function)
            if (!finished) {
                for (var i:int = 0; i < sampleBufferLength; i++) {
                    if (!finished) {                    
                        // write (transformed) samples to buffer
                        var sampleLeft:Number = samplesLeft[phase] * volumeLeft;
                        sampleBufferLeft[i] += sampleLeft;
                        leftPeakRecord = Math.max(Math.abs(sampleLeft), leftPeakRecord);
                        var channelValue:Number = ((needRightChannel && hasRightChannel) ? samplesRight[phase] : samplesLeft[phase]);
                        var sampleRight:Number = channelValue * volumeRight;
                        sampleBufferRight[i] += sampleRight;
                        rightPeakRecord = Math.max(Math.abs(sampleRight), rightPeakRecord);

                        // check playing and looping state
                        if (++phase >= samplesLength) {
                            phase = startPhase;
                            finished = loopsLeft-- == 0;
                        }
                    }
                }

                if (finished) {
                    dispatchEvent(new Event(Event.SOUND_COMPLETE));
                }
            }

            _leftPeak = leftPeakRecord;
            _rightPeak = rightPeakRecord;

Original comment by marc...@gmail.com on 5 Jun 2014 at 11:46