Class SamplePlayer

  • java.lang.Object
    • UGen
      • uk.ac.qmul.eecs.depic.daw.beads.SamplePlayer
  • All Implemented Interfaces:
    SoundWaveListener


    public class SamplePlayer
    extends UGen
    implements SoundWaveListener
    This is actually responsible for play the audio file in a track when the play button is pressed. It implements a SoundWaveListener because it updates its lenght when the sound wave changes
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static class  SamplePlayer.LoopType
      Used to determine which kind of loop the sample player will use.
    • Constructor Summary

      Constructors 
      Constructor and Description
      SamplePlayer(AudioContext context, ClipList clips)
      Instantiates a new SamplePlayer with given number of outputs.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void calculateBuffer() 
      protected void calculateNextPosition(int i)
      Used at each sample in the perform routine to determine the next playback position.
      Bead getEndListener()
      Gets the current endListener.
      float getLenght() 
      Range<java.lang.Float> getLoop() 
      SamplePlayer.LoopType getLoopType()
      Gets the loop type.
      UGen getPitchUGen()
      Gets the rate UGen (this method is provided so that SamplePlayer and GranularSamplePlayer can be used interchangeably).
      double getPosition()
      Gets the playback position.
      UGen getRateUGen()
      Gets the rate UGen.
      float getSampleRate()
      Gets the sample rate.
      boolean inLoop()
      Determines whether the playback position is within the loop points.
      void reset()
      Resets the position to the start of the Sample.
      void reTrigger()
      Re trigger the SamplePlayer from the beginning.
      void setEndListener(Bead endListener)
      Sets a Bead that will be triggered when this SamplePlayer gets to the end.
      void setLength(float length) 
      void setLoopEnabled(boolean enabled) 
      void setLoopPointsFraction(float start, float end)
      Sets both loop points to static values as fractions of the Sample length, overriding any UGens that were controlling the loop points.
      void setLoopType(SamplePlayer.LoopType loopType)
      Sets the loop type.
      void setPitch(UGen rateUGen)
      Sets the rate UGen (this method is provided so that SamplePlayer and GranularSamplePlayer can be used interchangeably).
      void setPosition(double position)
      Sets the playback position.
      void setRate(UGen rateUGen)
      Sets the rate to a UGen.
      void setToEnd()
      Sets the playback position to the end of the Sample.
      void setToLoopStart()
      Sets the playback position to the loop start point.
      void start(float msPosition)
      Starts the sample at the given position.
      void update(SoundWaveEvent evt)
      Updates the lenght when the sound wave changes
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ADAPTIVE_INTERP_HIGH_THRESH

        public static final float ADAPTIVE_INTERP_HIGH_THRESH
        See Also:
        Constant Field Values
      • ADAPTIVE_INTERP_LOW_THRESH

        public static final float ADAPTIVE_INTERP_LOW_THRESH
        See Also:
        Constant Field Values
      • loopEnd

        protected float loopEnd
        The loop end. Calculated and used internally from the loop end envelope.
      • loopStart

        protected float loopStart
        The loop start. Calculated and used internally from the loop start envelope.
      • position

        protected double position
        The position in milliseconds.
      • positionIncrement

        protected double positionIncrement
        The millisecond position increment per sample. Calculated from the ratio of the AudioContext's sample rate and the Sample's sample rate.
      • rate

        protected float rate
        The rate. Calculated and used internally from the rate envelope.
      • rateEnvelope

        protected UGen rateEnvelope
        The rate envelope.
      • startLoop

        protected boolean startLoop
        Flag to determine whether playback starts at the beginning of the sample or at the beginning of the loop.
    • Constructor Detail

      • SamplePlayer

        public SamplePlayer(AudioContext context,
                            ClipList clips)
        Instantiates a new SamplePlayer with given number of outputs.
        Parameters:
        context - the AudioContext.
        outs - the number of outputs.
    • Method Detail

      • setToEnd

        public void setToEnd()
        Sets the playback position to the end of the Sample.
      • inLoop

        public boolean inLoop()
        Determines whether the playback position is within the loop points.
        Returns:
        true if the playback position is within the loop points.
      • setToLoopStart

        public void setToLoopStart()
        Sets the playback position to the loop start point.
      • start

        public void start(float msPosition)
        Starts the sample at the given position.
        Parameters:
        msPosition - the position in milliseconds.
      • reset

        public void reset()
        Resets the position to the start of the Sample.
      • getPosition

        public double getPosition()
        Gets the playback position.
        Returns:
        the position in milliseconds.
      • setPosition

        public void setPosition(double position)
        Sets the playback position. This will not work if the position envelope is not null.
        Parameters:
        position - the new position in milliseconds.
      • getRateUGen

        public UGen getRateUGen()
        Gets the rate UGen.
        Returns:
        the rate UGen.
      • setRate

        public void setRate(UGen rateUGen)
        Sets the rate to a UGen.
        Parameters:
        rateUGen - the new rate UGen.
      • getPitchUGen

        public UGen getPitchUGen()
        Gets the rate UGen (this method is provided so that SamplePlayer and GranularSamplePlayer can be used interchangeably).
        Returns:
        the rate envelope.
      • setPitch

        public void setPitch(UGen rateUGen)
        Sets the rate UGen (this method is provided so that SamplePlayer and GranularSamplePlayer can be used interchangeably).
        Parameters:
        rateUGen - the new rate UGen.
      • setLoopPointsFraction

        public void setLoopPointsFraction(float start,
                                          float end)
        Sets both loop points to static values as fractions of the Sample length, overriding any UGens that were controlling the loop points.
        Parameters:
        start - the start value, as fraction of the Sample length.
        end - the end value, as fraction of the Sample length.
      • getLoop

        public Range<java.lang.Float> getLoop()
      • setLoopType

        public void setLoopType(SamplePlayer.LoopType loopType)
        Sets the loop type.
        Parameters:
        loopType - the new loop type.
      • setLoopEnabled

        public void setLoopEnabled(boolean enabled)
      • getSampleRate

        public float getSampleRate()
        Gets the sample rate.
        Returns:
        the sample rate, in samples per second.
      • calculateBuffer

        public void calculateBuffer()
      • getLenght

        public float getLenght()
      • setLength

        public void setLength(float length)
      • calculateNextPosition

        protected void calculateNextPosition(int i)
        Used at each sample in the perform routine to determine the next playback position.
        Parameters:
        i - the index within the buffer loop.
      • setEndListener

        public void setEndListener(Bead endListener)
        Sets a Bead that will be triggered when this SamplePlayer gets to the end. This occurs when the SamplePlayer's position reaches then end when playing forwards in a non-looping mode, or reaches the the beginning when playing backwards in a non-looping mode. It is never triggered in a looping mode. As an alternative, you can use the method {@link Bead.#setKillListener(Bead)} as long as #setKillOnEnd(boolean) is set to true. In other words, you set this SamplePlayer to kill itself when it reaches the end of the sample, and then use the functionality of Bead, which allows you to create a trigger whenever a Bead is killed. Set to null to remove the current listener.
        Parameters:
        endListener - the Bead that responds to this SamplePlayer reaching its end.
      • getEndListener

        public Bead getEndListener()
        Gets the current endListener.
        Returns:
        the current endListener.
      • reTrigger

        public void reTrigger()
        Re trigger the SamplePlayer from the beginning.