Skip to content

Commit

Permalink
Granulator update
Browse files Browse the repository at this point in the history
  • Loading branch information
JorenSix committed Jul 26, 2016
1 parent a42666d commit 4e429e9
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Every "release of TarsosDSP":http://0110.be/releases/TarsosDSP/ contains the fol
* @TarsosDSP-x.x-bin.jar@ Jar library for inclusion in Java projects, withouth source files included.
* @TarsosDSP-x.x.jar@ Jar library for inclusion in Java projects, with source files included.

The source code of TarsosDSP are compatible with Java 1.6. The jar files are compiled for 1.7.

h2. TarsosDSP on Android

If you want to do audio processing on Android TarsosDSP is a great fit. The main distribution has no dependencies on @javax.sound.xxx@ and does work well on Android by default. To add TarsosDSP to an Android Studio project download the latest "TarsosDSP Android release":http://0110.be/releases/TarsosDSP/TarsosDSP-latest/TarsosDSP-Android-latest.jar and place it in the @/app/libs/@ folder of your project. By default Gradle includes jar files placed in that directory in your classpath.
Expand Down
13 changes: 9 additions & 4 deletions src/core/be/tarsos/dsp/granulator/Grain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Grain{
double age;

/** The grain size of the grain. Fixed at instantiation. */
double grainSize;
double grainSize;

boolean active;

/**
* Sets the given Grain to start immediately.
Expand All @@ -22,9 +24,12 @@ class Grain{
* @param time
* the time
*/
void reset(double grainSize,double randomness,double position){
this.position = position + (grainSize * randomness * (Math.random() * 2.0 - 1.0));
void reset(double grainSize,double randomness,double position,double timeStretchFactor,double pitchShiftFactor){
double randomTimeDiff = (Math.random() > 0.5 ? +1 : -1) * grainSize * randomness;
double actualGrainSize = (grainSize + randomTimeDiff) * 1.0/timeStretchFactor + 1;
this.position = position - actualGrainSize;
this.age = 0f;
this.grainSize = grainSize;
this.grainSize = actualGrainSize;
this.active =true;
}
}
12 changes: 7 additions & 5 deletions src/core/be/tarsos/dsp/granulator/Granulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import be.tarsos.dsp.AudioProcessor;

/**
* GranularSamplePlayer plays back a {@link Sample} using granular synthesis. GranularSamplePlayer inherits its main behaviour from {@link SamplePlayer} but replaces the direct {@link Sample} lookup with a granular process.
* {@link UGen}s can be used to control playback rate, pitch, loop points, grain size, grain interval, grain randomness and position (this last case assumes that the playback rate is zero).
* Granulator plays back samples using granular synthesis.
* Methods can be used to control playback rate, pitch, grain size,
* grain interval and grain randomness and position (this last case assumes that the playback rate is zero).
*
*
*
* @see SamplePlayer Sample
* @beads.category sample players
* @author ollie
* @author Joren
*/
public class Granulator implements AudioProcessor {

Expand Down Expand Up @@ -147,7 +149,7 @@ public boolean process(AudioEvent audioEvent) {
} else {
g = new Grain();
}
g.reset(grainSize, grainRandomness, position);
g.reset(grainSize, grainRandomness, position,timeStretchFactor,pitchFactor);
grains.add(g);
timeSinceLastGrain = 0f;
//System.out.println(grains.size());
Expand Down
Loading

0 comments on commit 4e429e9

Please sign in to comment.