Skip to content

Commit

Permalink
Working on NeuronSignal, it now adapts a signal held by a float buffe…
Browse files Browse the repository at this point in the history
…r to an output buffer of any length, it basically keeps track of where in the signal the last chunk was taken out, and starts there for the next chunk.
  • Loading branch information
zk committed Jan 14, 2009
1 parent 9455ef0 commit 5f6f6b4
Show file tree
Hide file tree
Showing 30 changed files with 267 additions and 37 deletions.
7 changes: 6 additions & 1 deletion .classpath
Expand Up @@ -3,7 +3,12 @@
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/minim.jar"/>
<classpathentry kind="lib" path="lib/core.jar"/>
<classpathentry kind="lib" path="lib/minim-spi.jar"/>
<classpathentry kind="lib" path="lib/jsminim.jar"/>
<classpathentry kind="lib" path="lib/tritonus_aos.jar"/>
<classpathentry kind="lib" path="lib/tritonus_share.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
6 changes: 0 additions & 6 deletions .project
Expand Up @@ -10,14 +10,8 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>
15 changes: 11 additions & 4 deletions .settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,12 @@
#Tue Jan 13 23:25:56 MST 2009
#Wed Jan 14 13:54:56 MST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.source=1.3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
6 changes: 3 additions & 3 deletions .settings/org.maven.ide.eclipse.prefs
@@ -1,8 +1,8 @@
#Tue Jan 13 23:25:56 MST 2009
#Wed Jan 14 00:14:16 MST 2009
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
includeModules=true
resolveWorkspaceProjects=false
resourceFilterGoals=process-resources resources\:testResources
version=1
Binary file added lib/core.jar
Binary file not shown.
Binary file added lib/jsminim.jar
Binary file not shown.
Binary file added lib/minim-spi.jar
Binary file not shown.
Binary file added lib/tritonus_aos.jar
Binary file not shown.
Binary file added lib/tritonus_share.jar
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/java/napplelabs/dbssim/AudioCapture01.java

This file was deleted.

49 changes: 28 additions & 21 deletions src/main/java/napplelabs/dbssim/NeuronPlayer.java
@@ -1,44 +1,51 @@
package napplelabs.dbssim;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.DataLine.Info;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import ddf.minim.AudioOutput;
import ddf.minim.Minim;
import ddf.minim.signals.PinkNoise;
import ddf.minim.signals.SineWave;

public class NeuronPlayer {

public NeuronPlayer() throws LineUnavailableException {
Info info = new Info(SourceDataLine.class, new AudioFormat(22050f, 8, 1, true, false));
SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);

System.out.println("Supported: " + AudioSystem.isLineSupported(info));

int buff_size = 22100;

PinkNoise noise = new PinkNoise(1, 5);
private PinkNoise pink;
private SineWave sin;
private AudioOutput out;

public NeuronPlayer() throws LineUnavailableException, InterruptedException {

line.open();
line.start();

byte[] buffer = new byte[buff_size];
for(int i=0; i < buff_size; i++) {
buffer[i] = (byte) ((noise.nextValue() * 255) - 127);
}
JFrame frame = new JFrame("");
frame.setSize(500, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

line.write(buffer, 0, buff_size);
Minim minim = new Minim(null);
out = minim.getLineOut(Minim.MONO);
pink = new PinkNoise(0.2f);

out.addSignal(pink);

TracePanel panel = new TracePanel(out);
frame.setContentPane(panel);

line.drain();
frame.setVisible(true);

line.stop();
line.close();
new Thread(panel).start();
}

public static void main(String[] args) throws LineUnavailableException {
public static void main(String[] args) throws LineUnavailableException, InterruptedException {
new NeuronPlayer();
}
}
54 changes: 54 additions & 0 deletions src/main/java/napplelabs/dbssim/NeuronSignal.java
@@ -0,0 +1,54 @@
package napplelabs.dbssim;

import ddf.minim.AudioOutput;
import ddf.minim.AudioSignal;


/**
* Neuron signal provides a mechanism for pushing chunks of a neural
* signal out to a float buffer. It abstracts away the need to
* think about the specifics of the target buffer (length), and
* concentrate on the neuronal signal.
*
* Usage:
* float[] signal = new float[signal_length]
* for(int i=0; i<signal_length; i++) {
* // Fill signal
* }
*
* NeuronSignal ns = new NeuronSignal(signal);
*
* float[] first_chunk = new float[100]; //notice different array sizes
* float[] second_chunk = new float[39];
*
* ns.generate(first_chunk); // gets first chunk
* ns.generate(second_chunk); // gets second chunk
*
* //Send first and second chunk to output
* @author zkim
*
*/
public class NeuronSignal implements AudioSignal {


private float[] spike;
private int counter = 0;

public NeuronSignal(float[] spike) {
this.spike = spike;
}

public void generate(float[] signal) {
for(int i=0; i < signal.length; i++) {
signal[i] = spike[counter];

counter++;
if(counter >= spike.length) counter = 0;
}
}

public void generate(float[] left, float[] right) {

}

}

0 comments on commit 5f6f6b4

Please sign in to comment.