- Timestamp:
- 03/08/16 23:22:09 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/gui/DualPeakTroughWaveFormRenderer.java
r353 r1007 14 14 15 15 private int sampleSize; 16 private int numChannels; 16 17 private boolean isBigEndian; 17 18 private boolean isSigned; … … 36 37 37 38 sampleSize = audioFormat.getSampleSizeInBits(); 39 numChannels = audioFormat.getChannels(); 38 40 isSigned = audioFormat.getEncoding().toString().startsWith("PCM_SIGN"); 39 41 isBigEndian = audioFormat.isBigEndian(); … … 81 83 if (sampleSize == 16) { 82 84 85 int shift_multiplier = numChannels; // <<1=16-bit-mono, <<2=16-bit-stereo 83 86 for (int i = 0; i < aggregationCount; i++) { 84 87 85 88 int max = 0, min = 0, sample; // could use short, but int avoids casting everywhere 86 89 87 int startFrameIndex = (startFrame + (i * aggregationSize)) << 1;88 int endFrameIndex = startFrameIndex + (aggregationSize << 1);90 int startFrameIndex = (startFrame + (i * aggregationSize)) << shift_multiplier; 91 int endFrameIndex = startFrameIndex + (aggregationSize << shift_multiplier); 89 92 90 93 for (int k = startFrameIndex; k < endFrameIndex; k+=2) { 91 94 95 // k+=2 works for both mono and stereo 96 // in the case of stereo k+=2 alternates between L and R values. 97 // net effect is that it still finds the min and max values across 98 // all samples: startFrameIndex .. endFrameIndex 99 92 100 int lsb, msb; 93 101 … … 128 136 } else if (sampleSize == 8) { 129 137 138 int shift_multiplier = numChannels-1; // <<0=8-bit-mono, <<1=8-bit-stereo 139 140 // 'i' loop below works for either mono or stereo without any adjustment 141 // for same reason above given for 'k' loop 142 130 143 if (isSigned) { 131 144 145 132 146 // Find the peak within the block of aggregated frames 133 147 for (int i = 0; i < amplitudes.length; i++) { … … 135 149 byte max = 0, absmax = -1, sample, abssample; 136 150 137 int startFrameIndex = startFrame + (i * aggregationSize);138 int endFrameIndex = startFrameIndex + aggregationSize;151 int startFrameIndex = (startFrame + (i * aggregationSize)) << shift_multiplier; 152 int endFrameIndex = startFrameIndex + (aggregationSize << shift_multiplier); 139 153 140 154 for (int k = startFrameIndex; k < endFrameIndex; k++) { … … 160 174 int max = 0, absmax = -1, sample, abssample; // could use short, but int avoid casting everywhere 161 175 162 int startFrameIndex = startFrame + (i * aggregationSize);163 int endFrameIndex = startFrameIndex + aggregationSize;176 int startFrameIndex = (startFrame + (i * aggregationSize)) << shift_multiplier; 177 int endFrameIndex = startFrameIndex + (aggregationSize<<shift_multiplier); 164 178 165 179 for (int k = startFrameIndex; k < endFrameIndex; k++) {
Note:
See TracChangeset
for help on using the changeset viewer.