use of net.beadsproject.beads.data.Sample in project narchy by automenta.
the class LFO_Granulation_01 method main.
public static void main(String[] args) {
// instantiate the AudioContext
AudioContext ac = new AudioContext();
// load the source sample from a file
Sample sourceSample = null;
try {
sourceSample = new Sample("/tmp/Vocal/wav/Laugh1.wav");
} catch (Exception e) {
/*
* If the program exits with an error message,
* then it most likely can't find the file
* or can't open it. Make sure it is in the
* root folder of your project in Eclipse.
* Also make sure that it is a 16-bit,
* 44.1kHz audio file. These can be created
* using Audacity.
*/
System.out.println(e.getMessage());
e.printStackTrace();
System.exit(1);
}
// instantiate a GranularSamplePlayer
GranularSamplePlayer gsp = new GranularSamplePlayer(ac, sourceSample);
// tell gsp to loop the file
gsp.setLoopType(SamplePlayer.LoopType.LOOP_FORWARDS);
// set up a custom function to convert a WavePlayer LFO to grain duration values
WavePlayer wpGrainDurationLFO = new WavePlayer(ac, 0.03f, WaveFactory.SINE);
FuncGen grainDurationLFO = new FuncGen(wpGrainDurationLFO) {
@Override
public float floatValueOf(float[] x) {
return 1.0f + ((x[0] + 1.0f) * 50.0f);
}
};
// set the grain size to the LFO
gsp.setGrainSize(grainDurationLFO);
// set up a custom function to convert a WavePlayer LFO to grain interval values
WavePlayer wpGrainIntervalLFO = new WavePlayer(ac, 0.02f, WaveFactory.SINE);
FuncGen grainIntervalLFO = new FuncGen(wpGrainIntervalLFO) {
@Override
public float floatValueOf(float[] x) {
return 1.0f + ((x[0] + 1.0f) * 50.0f);
}
};
// set the grain size to the LFO
gsp.setGrainInterval(grainIntervalLFO);
// tell gsp to behave somewhat randomly
gsp.setRandomness(new Static(ac, 10.0f));
// set up a gain
Gain gain = new Gain(ac, 1, 0.5f);
gain.in(gsp);
// connect the Gain to ac
ac.out.in(gain);
// begin audio processing
ac.start();
Util.sleep((100 * 1000));
}
use of net.beadsproject.beads.data.Sample in project narchy by automenta.
the class AudioContext method record.
/**
* Tells the AudioContext to record all output for the given millisecond
* duration, kill the AudioContext, and save the recording to the given file
* path. This is a convenient way to make quick recordings, but may not suit
* every circumstance.
*
* @param timeMS the time in milliseconds to record for.
* @param filename the filename to save the recording to.
* @throws IOException Signals that an I/O exception has occurred.
* @see RecordToSample recorder
* @see Sample sample
*/
public void record(double timeMS, String filename) throws Exception {
Sample s = new Sample(timeMS, audioFormat.outputs, audioFormat.sampleRate);
RecordToSample r;
try {
r = new RecordToSample(this, s);
r.in(out);
out.dependsOn(r);
r.start();
r.after(new AudioContextStopTrigger(this));
} catch (Exception e) {
/* won't happen */
}
while (isRunning()) {
}
s.write(filename);
}
Aggregations