Package com.avpkit.mediatool.demos
Class MovingBalls
- java.lang.Object
-
- com.avpkit.mediatool.demos.MovingBalls
-
- All Implemented Interfaces:
Balls
public class MovingBalls extends java.lang.Object implements Balls
An implementation ofBallsthat 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 doubleaddSignal(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.BufferedImagegetVideoFrame(long elapsedTime)Get a picture of a set of balls.
-
-
-
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:BallsGet a picture of a set of balls. Each new call should provide the right picture assuming elapsedTime, in MICROSECONDS, has passed.- Specified by:
getVideoFramein interfaceBalls- Parameters:
elapsedTime- the time in MICROSECONDS which has elapsed since the last video frame
-
getAudioFrame
public short[] getAudioFrame(int sampleRate)
Description copied from interface:BallsGet the next set of audio for the balls. Samples returned should assume they are contiguous to the last samples returned.- Specified by:
getAudioFramein interfaceBalls- 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 addsampleRate- the number samples in a secondvolume- the amplitude of the signalprogress- 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 addSignalsamples- the array to which the samples will be added- Returns:
- the progress at the end of the sample period
-
-