Ignore:
Timestamp:
05/19/21 09:01:33 (3 years ago)
Author:
davidb
Message:

A set of changes that spans three things: beat detection, time stretching; and a debug class motivated by the need to look at a canvas redraw issue most notable when a waveform widget is playing

File:
1 edited

Legend:

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

    r1146 r1561  
    33import java.awt.Graphics2D;
    44import java.util.LinkedList;
     5import java.util.List;
    56
    67import javax.sound.sampled.AudioFormat;
     
    269270                                                        for (int i = 0; i < amps.length; i+=2) {
    270271                                                               
     272                                                                g.setColor(SwingConversions.toSwingColor(ApolloColorIndexedModels.WAVEFORM_COLOR));
     273                                                               
    271274                                                                float peak = amps[i];
    272275                                                                float trough = amps[i + 1];
     
    293296                                                                }
    294297                                                               
     298                                                                int frameSize = 4;
     299                                                                int bi_start = (currentTask.startFrame + renderStart);
     300                                                                int bi_end = bi_start + (renderLength);
     301
     302                                                                for (int bi = bi_start; bi<bi_end; bi++) {
     303                                                                        if (currentTask.frameIsBeat[bi]) {
     304                                                                                g.setColor(SwingConversions.toSwingColor(ApolloColorIndexedModels.WAVEFORM_SELECTION_COLOR));
     305                                                                                g.drawLine(x, halfMaxHeight, x, -halfMaxHeight);
     306                                                                                break;
     307                                                                        }
     308                                                                }
     309
    295310                                                                currentAmplitude ++;
    296311                                                        }
     
    303318                                } // next pass
    304319                               
    305                                 // Lession learnt: do not request lots of requests to repaint
    306                                 // later on the AWT Event queu otherwise it will get congested
     320                                // Lesson learnt: do not request lots of requests to repaint
     321                                // later on the AWT Event queue otherwise it will get congested
    307322                                // and will freeze up the interact for annoying periods of time.
    308323                                currentTask.setState(WaveFormRenderTask.STATE_STOPPED);
     
    348363                private Image imageBuffer; // nullified when stopped.
    349364                private byte[] audioBytes; // nullified when stopped. - Arrays (not contents) are immutable so no need to worry about threading issues with indexes
     365                private boolean[] frameIsBeat;
     366               
    350367                private final int startFrame;
    351368                private final int frameLength; // in frames
     
    357374                                byte[] audioBytes,
    358375                                AudioFormat format,
     376                                List<Double> detectedBeats,
    359377                                int startFrame,
    360378                                int frameLength,
     
    371389                        this.frameLength = frameLength;
    372390                        this.recommendInvalidations = recommendInvalidations;
     391                                               
     392                        this.frameIsBeat = new boolean[frameLength];
     393                        if (detectedBeats != null) {
     394                                for (double beat_in_secs: detectedBeats){
     395                                        int frame_pos = (int)Math.round(beat_in_secs * format.getSampleRate());
     396                                        frameIsBeat[frame_pos] = true;
     397                                }
     398                        }
     399
    373400                        renderer = new DualPeakTroughWaveFormRenderer(format);
    374401                }
     
    384411                        if (state == STATE_STOPPED) {
    385412                                audioBytes = null;
     413                                frameIsBeat = null;
    386414                                imageBuffer = null;
    387415                        }
Note: See TracChangeset for help on using the changeset viewer.