Class TutorialOne_06_WB_Retrofit

java.lang.Object
processing.core.PApplet
net.paulhertz.pixelaudio.example.TutorialOne_03_Drawing
net.paulhertz.pixelaudio.example.TutorialOne_06_WB_Retrofit
All Implemented Interfaces:
processing.core.PConstants

public class TutorialOne_06_WB_Retrofit extends TutorialOne_03_Drawing
Eclipse-only example of how to retrofit WaveBuffer feature to Drawing tutorial. A continuation of TutorialOne_03_Drawing that keeps the drawing, brush, sampler, granular, bounds, and envelope code from TutorialOne_03_Drawing, but changes the audio source model: - anthemSignal / anthemBuffer hold the entire loaded audio file. - windowBuff is a moving window over anthemSignal. - audioSignal / playBuffer / mapImage hold only the current visible window. - Display coordinates map first to the visible window, then to the backing full-file source by adding windowBuff.getIndex(). This file is intentionally small: it is a retrofit layer over the newer TutorialOne_03_Drawing rather than a refactor of the older TutorialOne_06 code. It is not ported to Processing. The programming model in Eclipse provides better support for the Java classes than Processing does. See TutorialOne_03_Drawing
  • Field Details

    • anthemSignal

      float[] anthemSignal
      Full-file mono source, padded to at least mapper.getSize().
    • anthemBuffer

      ddf.minim.MultiChannelBuffer anthemBuffer
      Full-file source buffer used by the Sampler instrument pool.
    • windowBuff

      WindowedBuffer windowBuff
      Moving view onto anthemSignal, with window size == mapper.getSize().
    • windowHopSize

      int windowHopSize
      Hop size for automatic window traversal.
    • isWindowing

      boolean isWindowing
      If true, draw() advances windowBuff each frame and refreshes the display.
    • oldIsWindowing

      boolean oldIsWindowing
      Save animation state when file loading or windowing temporarily suspends it.
    • isRaining

      boolean isRaining
      Optional random point-event texture while windowing.
    • windowAudioReady

      boolean windowAudioReady
      WindowBuffer initialized or not? see initAudio()
    • samplerSourceRef

      ddf.minim.MultiChannelBuffer samplerSourceRef
      Sampler instruments use anthemBuffer, not the current visible playBuffer.
    • samplerSourceRateRef

      float samplerSourceRateRef
      sampling rate of samplerSourceRef
    • poolSize

      int poolSize
    • samplerMaxVoices

      int samplerMaxVoices
  • Constructor Details

    • TutorialOne_06_WB_Retrofit

      public TutorialOne_06_WB_Retrofit()
  • Method Details

    • main

      public static void main(String[] args)
    • setup

      public void setup()
      Overrides:
      setup in class TutorialOne_03_Drawing
    • initAudio

      public void initAudio()
      Initializes audio using the TutorialOne_03_Drawing defaults, then creates an initial full-file backing source from the empty playBuffer.
      Overrides:
      initAudio in class TutorialOne_03_Drawing
    • loadAudioFile

      public void loadAudioFile(File audFile)
      Loads an audio file through TutorialOne_03_Drawing's normal path. The override of updateAudioChain(...) below receives the full resampled signal and installs it as the backing source instead of truncating it before instrument playback.
      Overrides:
      loadAudioFile in class TutorialOne_03_Drawing
      Parameters:
      audFile - an audio file
    • suspendWindowAudio

      void suspendWindowAudio()
    • updateAudioChain

      void updateAudioChain(float[] sig, float sourceSampleRate)
      Commit a new full-file source, then expose only the current mapSize window through audioSignal/playBuffer/mapImage.
      Overrides:
      updateAudioChain in class TutorialOne_03_Drawing
      Parameters:
      sig - an audio signal
      sourceSampleRate - audio sample rate for sig, usually obtained when reading from an audio file
    • updateAudioChain

      void updateAudioChain(float[] sig)
      Overrides:
      updateAudioChain in class TutorialOne_03_Drawing
    • installBackingSource

      void installBackingSource(float[] sig, float sourceSampleRate)
      Installs a full-file backing source for WindowedBuffer and instruments. Sets the window size to mapper.getSize()
    • refreshWindowFromBacking

      void refreshWindowFromBacking(boolean advance)
      Copies the current window into audioSignal and playBuffer. The Sampler and Granular instruments still read from anthemSignal / anthemBuffer.
    • ensureSamplerReady

      void ensureSamplerReady()
      Description copied from class: TutorialOne_03_Drawing
      Ensures that all resources and variable necessary for the Sampler synth are ready to go.
      Overrides:
      ensureSamplerReady in class TutorialOne_03_Drawing
    • ensureGranularReady

      void ensureGranularReady()
      Granular gestures use anthemSignal as their source.
      Overrides:
      ensureGranularReady in class TutorialOne_03_Drawing
    • getSamplePos

      public int getSamplePos(int x, int y)
      Display coordinate -> visible window index -> backing file index.
      Overrides:
      getSamplePos in class TutorialOne_03_Drawing
      Parameters:
      x - an x coordinate within mapImage and display bounds
      y - a y coordinate within mapImage and display bounds
      Returns:
      the index of the sample corresponding to (x,y) on the signal path
    • backingIndexFromLocal

      int backingIndexFromLocal(int localIndex)
    • getCoordFromSignalPos

      public processing.core.PVector getCoordFromSignalPos(int pos)
      Backing-file index -> visible display coordinate, relative to the current window.
      Overrides:
      getCoordFromSignalPos in class TutorialOne_03_Drawing
      Parameters:
      pos - an index into an audio signal, must be between 0 and width * height - 1.
      Returns:
      a PVector with the x and y coordinates
    • handleClickOutsideBrush

      public int handleClickOutsideBrush(int x, int y)
      Point clicks are copied from TutorialOne_03_Drawing, but the initial samplePos is the backing source index. Long granular bursts still create display points in the current window; playGranularGesture(...) remaps them to backing indices.
      Overrides:
      handleClickOutsideBrush in class TutorialOne_03_Drawing
    • scheduleGranularBrushClick

      void scheduleGranularBrushClick(TutorialOne_03_Drawing.AudioBrushLite b)
      Brush granular playback uses the full backing signal and backing indices.
      Overrides:
      scheduleGranularBrushClick in class TutorialOne_03_Drawing
      Parameters:
      b - an AudioBrushLite instance
    • backingGranularSignal

      float[] backingGranularSignal()
    • playGranularGesture

      public void playGranularGesture(float[] buf, GestureSchedule sched, GestureGranularParams params, float pitchRatio)
      Same as TutorialOne_03_Drawing, but startIndices are offset by the current WindowedBuffer origin so grains read from the full backing file.
      Overrides:
      playGranularGesture in class TutorialOne_03_Drawing
      Parameters:
      buf - an audio signal as an array of float
      sched - an GestureSchedule with coordinate and timing information
      params - a bundle of control parameters for granular synthesis
    • playSample

      public int playSample(int samplePos, int samplelen, float amplitude, ADSRParams env, float pitch, float pan)
      Description copied from class: TutorialOne_03_Drawing
      Plays an audio sample with with a custom envelope, pitch and stereo pan.
      Overrides:
      playSample in class TutorialOne_03_Drawing
      Parameters:
      samplePos - position of the sample in the audio buffer
      samplelen - length of the sample (will be adjusted)
      amplitude - amplitude of the sample on playback
      env - an ADSR envelope for the sample
      pitch - pitch scaling as deviation from default (1.0), where 0.5 = octave lower, 2.0 = octave higher
      pan - position of sound in the stereo audio field (-1.0 = left, 0.0 = center, 1.0 = right)
      Returns:
    • draw

      public void draw()
      Advance the visible audio window during draw().
      Overrides:
      draw in class TutorialOne_03_Drawing
    • parseKey

      public void parseKey(char key, int keyCode)
      Add WindowBuffer controls, then pass all other commands to TutorialOne_03_Drawing. T toggle automatic window traversal { } jump backward / forward one whole window [ ] jump backward / forward one half window R rewind the audio window Y toggle random point events while windowing
      Overrides:
      parseKey in class TutorialOne_03_Drawing
      Parameters:
      key - the key that was pressed, as a char
      keyCode - keyCode for the key that was pressed
    • resetAudioWindow

      public void resetAudioWindow()
    • moveAudioWindow

      public void moveAudioWindow(int delta)
    • raindrops

      public void raindrops(int count)
      Random point events along the upper part of the current window, useful for hearing time-structured files while the window is advancing.
    • showHelp

      public void showHelp()
      Description copied from class: TutorialOne_03_Drawing
      to generate help output, run RegEx search/replace on parseKey case lines with: // case ('.'): // (.+) // println(" * Press $1 to $2.");
      Overrides:
      showHelp in class TutorialOne_03_Drawing