Mercurial > hg > jslab
diff examples/sound/sampled/Spectro.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/sound/sampled/Spectro.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,55 @@ +import samer.core.*; +import samer.tools.*; +import samer.maths.*; +import samer.audio.*; +import samer.units.*; +import samer.functions.*; +import samer.models.*; + + +public class Spectro { + public static void main(String [] args) throws Exception { + new samer.core.shells.SwingShell(); + + CompoundTask tasks=new CompoundTask(); + RThread thread=new RThread(tasks); + AudioSource source=new FileSource(); + LineIn linein=new LineIn(source,1024,512); + Scaler scaler=new Scaler(linein.output()); + IIDPrior prior=new IIDPrior(scaler.output(),new Abs()); + FFTVector fft=new FFTVector(scaler.output()); + VVector y=new VVector("ft-magnitude",fft.size()/2); + + scaler.setOutputModel(prior); + tasks.addTask(linein); + tasks.addTask(scaler); + tasks.addTask(prior); + tasks.addTask(new BatchedTrainer(scaler.getTrainer(),4)); + tasks.addTask(fft.calcTask()); + tasks.addTask(fft.getFnPower(new Sqrt(),y)); + + /* this shows how to put some defaults in the environment + they will affect any trace viewers for the ft-magnitude vector */ + Shell.push(y.getNode()); + Shell.put("trace.map.log","true"); + Shell.put("trace.map.maxmimum",new Double(10)); + Shell.put("trace.map.minimum",new Double(0.01)); + Shell.pop(); + + y.getAgent().execute("trace",Shell.env()); + + { + Object [] commands = { "expose", "exit" }; + + Shell.interpret("expose"); + Shell.exposeCommands(commands); + Shell.exposeCommands(thread); + } + } + + public static void lineout() { + Shell.put("audio.scale",new Integer(1)); + Shell.put("audio.rate",new Integer(22050)); + // could create LineOut object to play stuff coming from linein + } +}