Browse files

Added peak() in SoundcardConsumer

  • Loading branch information...
1 parent e232fbd commit b369ddb6ac256ff0a2730065ad27b0ab14cc33fe @sivantoledo committed Mar 16, 2012
View
26 build.xml
@@ -1,21 +1,35 @@
<?xml version="1.0"?>
<project name="javAX25" basedir="." default="build-jars" >
-<target name="build-jars" >
+<target name="compile" >
<mkdir dir="bin" />
<javac destdir="bin"
deprecation="false"
optimize="true"
-debug="true" >
+debug="true"
+fork="yes"
+ executable="c:\Program Files\Java\jdk1.6.0_24\bin\javac"
+ >
-<classpath path="/usr/share/java/RXTXcomm.jar" />
-<src path="src/sivantoledo" />
+<classpath path="RXTXcomm.jar;javAPRSSrvr.jar" />
+<src path="src" />
<include name="**/*.java" />
</javac>
-<jar jarfile="bin/javAX25lib.jar" basedir="bin" includes="sivantoledo/ax25/**"/>
-<jar jarfile="bin/javAX25all.jar" basedir="bin" includes="sivantoledo/**"/>
</target>
+
+<target name="build-jars" depends="compile">
+ <jar jarfile="bin/javAX25lib.zip">
+ <fileset dir="bin" includes="sivantoledo/ax25/**"/>
+ <fileset dir="bin" includes="sivantoledo/soundcard/**"/>
+ </jar>
+
+ <jar jarfile="bin/javAX25all.zip">
+ <fileset dir="bin" includes="**/*.class" excludes="obsolete/**" />
+ </jar>
+</target>
+
+
<target name="clean">
<delete dir="bin" failonerror="false" />
</target>
View
BIN manual.doc
Binary file not shown.
View
5 src/sivantoledo/ax25/Afsk1200Demodulator.java
@@ -22,7 +22,7 @@
import java.util.Arrays;
public class Afsk1200Demodulator
- implements PacketDemodulator
+ extends PacketDemodulator
//implements HalfduplexSoundcardClient
{
private float[] td_filter;
@@ -98,6 +98,7 @@ public Afsk1200Demodulator(int sample_rate, int filter_length) throws Exception
}
public Afsk1200Demodulator(int sample_rate, int filter_length, int emphasis, PacketHandler h) throws Exception {
+ super(sample_rate==8000 ? 16000 : sample_rate);
if (sample_rate==8000) {
interpolate = true;
@@ -243,7 +244,7 @@ private float sum(float[] x, int j) {
private boolean vox_state = false;
- public void addSamples(float[] s, int n) {
+ protected void addSamplesPrivate(float[] s, int n) {
//for (int i=0; i<n; i++) {
int i = 0;
while (i<n) {
View
5 src/sivantoledo/ax25/Afsk1200MultiDemodulator.java
@@ -23,7 +23,7 @@
//import java.util.Arrays;
-public class Afsk1200MultiDemodulator implements PacketDemodulator {
+public class Afsk1200MultiDemodulator extends PacketDemodulator {
private class InnerHandler implements PacketHandler {
int d;
@@ -92,13 +92,14 @@ public void handlePacket(byte[] bytes, int d) {
//private int max_sample_delay;
public Afsk1200MultiDemodulator(int sample_rate, PacketHandler h) throws Exception {
+ super(sample_rate);
//this.sample_rate = sample_rate;
this.h = h;
//max_sample_delay = (10 * 8 * sample_rate) / 1200; // a 10 byte delay
d0 = new Afsk1200Demodulator(sample_rate,1,0,new InnerHandler(0));
d6 = new Afsk1200Demodulator(sample_rate,1,6,new InnerHandler(6));
}
- public void addSamples(float[] s, int n) {
+ protected void addSamplesPrivate(float[] s, int n) {
sample_count += n;
d0.addSamples(s, n);
d6.addSamples(s, n);
View
10 src/sivantoledo/ax25/PacketDemodulator.java
@@ -21,7 +21,11 @@
import sivantoledo.soundcard.SoundcardConsumer;
-public interface PacketDemodulator extends SoundcardConsumer {
- public void addSamples(float[] s, int n);
- public boolean dcd();
+public abstract class PacketDemodulator extends SoundcardConsumer {
+ public PacketDemodulator(int sample_rate) {
+ super(sample_rate);
+ }
+
+ //public void addSamples(float[] s, int n);
+ public abstract boolean dcd();
}
View
19 src/sivantoledo/ax25test/Test.java
@@ -269,7 +269,7 @@ public static void main(String[] args) {
else {
System.err.printf("Sample rates must match or lead to decimation by an integer!\n");
System.exit(1);
- }
+ }
byte[] raw = new byte[fmt.getFrameSize()];
float[] f = new float[1];
@@ -279,6 +279,14 @@ public static void main(String[] args) {
else
bb = ByteBuffer.wrap(raw).order(ByteOrder.LITTLE_ENDIAN);
int j = 0;
+ int k = 0;
+ float scale = 0.0f;
+ switch (fmt.getSampleSizeInBits()){
+ case 32: scale = 1.0f / ((float) fmt.getChannels() * 2147483648.0f ); break;
+ case 16: scale = 1.0f / ((float) fmt.getChannels() * 32768.0f ); break;
+ case 8: scale = 1.0f / ((float) fmt.getChannels() * 256.0f ); break;
+ }
+ //System.out.printf("Format bits per sample = %d\n",fmt.getSampleSizeInBits());
while (true) {
try {
int n = ios.read(raw);
@@ -288,6 +296,7 @@ public static void main(String[] args) {
}
bb.rewind();
f[0] = 0.0f;
+ // we average over channels (stereo)
for (int i=0; i<fmt.getChannels(); i++) {
switch (fmt.getSampleSizeInBits()){
case 32: f[0] += (float) bb.getInt(); break;
@@ -298,12 +307,20 @@ public static void main(String[] args) {
System.exit(1);
}
}
+ f[0] = scale*f[0];
if (j==0) {
t.incSampleCount();
//afsk.addSamples(f, 1);
//afsk0.addSamples(f, 1);
//afsk6.addSamples(f, 1);
+ //if (f[0] > 32768.0f || f[0] < -32768.0f) System.out.printf("Weird short sample value %f\n", f[0]);
multi.addSamples(f, 1);
+
+ k++;
+ if (k==rate) {
+ System.out.printf("peak level %d\n",multi.peak());
+ k=0;
+ }
}
j++;
if (j==decimation) j=0;
View
22 src/sivantoledo/sampledsound/Soundcard.java
@@ -113,8 +113,12 @@ public static void enumerate() {
}
lis = AudioSystem.getMixer(mi).getTargetLineInfo();
for (Line.Info li: lis) {
- if (TargetDataLine.class.equals(li.getLineClass()))
+ if (TargetDataLine.class.equals(li.getLineClass())) {
System.out.println(" input : "+name);
+
+ }
+
+
//System.out.println(" input device = "+li.getLineClass());
//System.out.println(" isInstance = "+li.getLineClass().isInstance(TargetDataLine.class));
//System.out.println(" isInstance = "+));
@@ -150,13 +154,14 @@ public void receive() {
if (!display_audio_level) continue;
j ++;
//System.out.printf("j=%d\n",j);
- if (f[i] > max) max = f[i];
- if (f[i] < min) min = f[i];
+ //if (f[i] > max) max = f[i];
+ //if (f[i] < min) min = f[i];
if (j == rate) {
- System.err.printf("Audio in range [%f, %f]\n",min,max);
+ //System.err.printf("Audio in range [%f, %f]\n",min,max);
+ System.err.printf("Audio level %d\n",consumer.peak());
j = 0;
- min = 1.0f;
- max = -1.0f;
+ //min = 1.0f;
+ //max = -1.0f;
}
}
consumer.addSamples(f,rv/2);
@@ -195,6 +200,11 @@ private void openSoundInput(String mixer) {
return;
}
+ //Control[] controls = tdl.getControls();
+ //for (Control c: controls) {
+ // System.out.println(" Control: +"+c.getType().getClass());
+ //}
+
int buffer_size_in_samples = (int) Math.round(latency_ms * ((double) rate / 1000.0));
try {
tdl.open(fmt,2*buffer_size_in_samples);
View
30 src/sivantoledo/soundcard/SoundcardConsumer.java
@@ -20,11 +20,37 @@
package sivantoledo.soundcard;
-public interface SoundcardConsumer {
+public abstract class SoundcardConsumer {
+ int sample_rate;
+ float peak = 0.0f;
+ float decay;
+ //private final float oneovermax = 1.0f/32768.0f;
+ public SoundcardConsumer(int sample_rate) {
+ this.sample_rate = sample_rate;
+ decay = (float) ( 1.0 - Math.exp(Math.log(0.5)/(double)sample_rate) );
+ System.out.printf("decay = %e\n", (double)decay);
+
+ }
//public void addSamples(float[] s) {
// addSamples(s,s.length);
//}
- public abstract void addSamples(float[] s, int n);
+ protected abstract void addSamplesPrivate(float[] s, int n);
+
+ public int peak() {
+ return (int) Math.ceil(peak*100.0f);
+ }
+
+ public void addSamples(float[] s, int n) {
+ for (int i=0; i<n; i++) {
+ float abs = s[i] >= 0 ? s[i] : -s[i];
+ if (abs > peak) peak = abs;
+ else peak = peak - (peak * decay);
+
+ //if (peak > 1.0f)
+ // System.out.printf("sample=%f peak=%f decay=%f\n", abs,peak,decay);
+ }
+ addSamplesPrivate(s,n);
+ }
}

0 comments on commit b369ddb

Please sign in to comment.