Class MovingBalls

  • All Implemented Interfaces:
    Balls

    public class MovingBalls
    extends java.lang.Object
    implements Balls
    An implementation of Balls that moves the balls around in a rectangle, and plays a sound for each ball that changes when it hits a wall.
    Author:
    trebor
    • Constructor Summary

      Constructors 
      Constructor Description
      MovingBalls​(int ballCount, int width, int height, int sampleCount)
      Grow a set of balls.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static double addSignal​(int frequency, int sampleRate, double volume, double progress, short[] samples)
      Add a signal of a given frequency to a set of audio samples.
      short[] getAudioFrame​(int sampleRate)
      Get the next set of audio for the balls.
      java.awt.image.BufferedImage getVideoFrame​(long elapsedTime)
      Get a picture of a set of balls.
      • Methods inherited from class java.lang.Object

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

      • MovingBalls

        public MovingBalls​(int ballCount,
                           int width,
                           int height,
                           int sampleCount)
        Grow a set of balls.
    • Method Detail

      • getVideoFrame

        public java.awt.image.BufferedImage getVideoFrame​(long elapsedTime)
        Description copied from interface: Balls
        Get a picture of a set of balls. Each new call should provide the right picture assuming elapsedTime, in MICROSECONDS, has passed.
        Specified by:
        getVideoFrame in interface Balls
        Parameters:
        elapsedTime - the time in MICROSECONDS which has elapsed since the last video frame
      • getAudioFrame

        public short[] getAudioFrame​(int sampleRate)
        Description copied from interface: Balls
        Get the next set of audio for the balls. Samples returned should assume they are contiguous to the last samples returned.
        Specified by:
        getAudioFrame in interface Balls
        Parameters:
        sampleRate - the number of samples in a second
      • addSignal

        public static double addSignal​(int frequency,
                                       int sampleRate,
                                       double volume,
                                       double progress,
                                       short[] samples)
        Add a signal of a given frequency to a set of audio samples. If the total signal value exceeds the percision of the samples, the signal is clipped.
        Parameters:
        frequency - the frequency of the signal to add
        sampleRate - the number samples in a second
        volume - the amplitude of the signal
        progress - the start position the signal, initally should be zero, it will be updated by addSignal and returned, pass the returned value into subsquent calls to addSignal
        samples - the array to which the samples will be added
        Returns:
        the progress at the end of the sample period