annotate examples/sound/sampled/Spectro.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 import samer.core.*;
samer@0 2 import samer.tools.*;
samer@0 3 import samer.maths.*;
samer@0 4 import samer.audio.*;
samer@0 5 import samer.units.*;
samer@0 6 import samer.functions.*;
samer@0 7 import samer.models.*;
samer@0 8
samer@0 9
samer@0 10 public class Spectro {
samer@0 11 public static void main(String [] args) throws Exception {
samer@0 12 new samer.core.shells.SwingShell();
samer@0 13
samer@0 14 CompoundTask tasks=new CompoundTask();
samer@0 15 RThread thread=new RThread(tasks);
samer@0 16 AudioSource source=new FileSource();
samer@0 17 LineIn linein=new LineIn(source,1024,512);
samer@0 18 Scaler scaler=new Scaler(linein.output());
samer@0 19 IIDPrior prior=new IIDPrior(scaler.output(),new Abs());
samer@0 20 FFTVector fft=new FFTVector(scaler.output());
samer@0 21 VVector y=new VVector("ft-magnitude",fft.size()/2);
samer@0 22
samer@0 23 scaler.setOutputModel(prior);
samer@0 24 tasks.addTask(linein);
samer@0 25 tasks.addTask(scaler);
samer@0 26 tasks.addTask(prior);
samer@0 27 tasks.addTask(new BatchedTrainer(scaler.getTrainer(),4));
samer@0 28 tasks.addTask(fft.calcTask());
samer@0 29 tasks.addTask(fft.getFnPower(new Sqrt(),y));
samer@0 30
samer@0 31 /* this shows how to put some defaults in the environment
samer@0 32 they will affect any trace viewers for the ft-magnitude vector */
samer@0 33 Shell.push(y.getNode());
samer@0 34 Shell.put("trace.map.log","true");
samer@0 35 Shell.put("trace.map.maxmimum",new Double(10));
samer@0 36 Shell.put("trace.map.minimum",new Double(0.01));
samer@0 37 Shell.pop();
samer@0 38
samer@0 39 y.getAgent().execute("trace",Shell.env());
samer@0 40
samer@0 41 {
samer@0 42 Object [] commands = { "expose", "exit" };
samer@0 43
samer@0 44 Shell.interpret("expose");
samer@0 45 Shell.exposeCommands(commands);
samer@0 46 Shell.exposeCommands(thread);
samer@0 47 }
samer@0 48 }
samer@0 49
samer@0 50 public static void lineout() {
samer@0 51 Shell.put("audio.scale",new Integer(1));
samer@0 52 Shell.put("audio.rate",new Integer(22050));
samer@0 53 // could create LineOut object to play stuff coming from linein
samer@0 54 }
samer@0 55 }