Ignore:
Timestamp:
03/08/16 23:22:09 (8 years ago)
Author:
davidb
Message:

Generalization of audio support to allow playback/mixer to be stereo, plus some edits to comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/gui/DualPeakTroughWaveFormRenderer.java

    r353 r1007  
    1414       
    1515        private int sampleSize;
     16        private int numChannels;
    1617        private boolean isBigEndian;
    1718        private boolean isSigned;
     
    3637
    3738                sampleSize = audioFormat.getSampleSizeInBits();
     39                numChannels = audioFormat.getChannels();
    3840                isSigned = audioFormat.getEncoding().toString().startsWith("PCM_SIGN");
    3941                isBigEndian = audioFormat.isBigEndian();
     
    8183                if (sampleSize == 16) {
    8284                                         
     85                        int shift_multiplier = numChannels; // <<1=16-bit-mono, <<2=16-bit-stereo
    8386                        for (int i = 0; i < aggregationCount; i++) {
    8487                               
    8588                                int max = 0, min = 0, sample; // could use short, but int avoids casting everywhere
    8689                               
    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);
    8992                               
    9093                                for (int k = startFrameIndex; k < endFrameIndex; k+=2) {
    9194                       
     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                                         
    92100                                        int lsb, msb;
    93101                                                                 
     
    128136                } else if (sampleSize == 8) {
    129137                       
     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                       
    130143                        if (isSigned) {
    131144                 
     145                               
    132146                                // Find the peak within the block of aggregated frames
    133147                                for (int i = 0; i < amplitudes.length; i++) {
     
    135149                                        byte max = 0, absmax = -1, sample, abssample;
    136150
    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);
    139153                                       
    140154                                        for (int k = startFrameIndex; k < endFrameIndex; k++) {
     
    160174                                        int max = 0, absmax = -1, sample, abssample; // could use short, but int avoid casting everywhere
    161175
    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);
    164178                                       
    165179                                        for (int k = startFrameIndex; k < endFrameIndex; k++) {
Note: See TracChangeset for help on using the changeset viewer.