Skip to content

Commit

Permalink
added a gui to decode ax25 audio
Browse files Browse the repository at this point in the history
  • Loading branch information
damico committed Dec 4, 2023
1 parent a847765 commit bef9758
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 114 deletions.
Binary file added dist/icon.ico
Binary file not shown.
Binary file added dist/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<archive>
<manifest>
<mainClass>
org.jdamico.javax25.App
org.jdamico.javax25.GuiApp
</mainClass>
</manifest>

Expand Down
12 changes: 3 additions & 9 deletions src/main/java/org/jdamico/javax25/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
import org.jdamico.javax25.ax25.Afsk1200Modulator;
import org.jdamico.javax25.ax25.Afsk1200MultiDemodulator;
import org.jdamico.javax25.ax25.PacketDemodulator;
import org.jdamico.javax25.radiocontrol.SerialTransmitController;
import org.jdamico.javax25.soundcard.Soundcard;

/**
* Hello world!
*
*/
public class App
{
public class App {
public static void main( String[] args) {
Soundcard.enumerate();

Expand Down Expand Up @@ -48,9 +42,9 @@ public static void main( String[] args) {

Soundcard sc = new Soundcard(rate,input,output,buffer_size,multi,mod);

if (p.containsKey("audio-level")) {

sc.displayAudioLevel();
}



/*** listen for incoming packets ***/
Expand Down
130 changes: 130 additions & 0 deletions src/main/java/org/jdamico/javax25/GuiApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package org.jdamico.javax25;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.DefaultCaret;

import org.jdamico.javax25.soundcard.Soundcard;

public class GuiApp extends JPanel implements ActionListener {

private JTextArea textArea = new JTextArea(40, 80);
private JComboBox devicesComboBox = null;
private JButton decodeBtn = null;
private JButton resetBtn = null;
private JLabel audioLevelLabel = null;
private JLabel audioLevelValue = null;
private Thread guiDecoderThread;

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}

public GuiApp() {
super(new BorderLayout());

JPanel northPanel = new JPanel(); // **** to hold buttons

List<String> lst = Soundcard.getInputDevicesLst();
String[] deviceArray = new String[lst.size()];
for (int i = 0; i < deviceArray.length; i++) {
deviceArray[i] = lst.get(i);
}
devicesComboBox = new JComboBox(deviceArray);
northPanel.add(devicesComboBox);

decodeBtn = new JButton("Decode Audio");
decodeBtn.addActionListener(this);
northPanel.add(decodeBtn);

resetBtn = new JButton("Reset");


resetBtn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
Soundcard.running = false;
guiDecoderThread.interrupt();
devicesComboBox.setEnabled(true);
decodeBtn.setEnabled(true);
resetBtn.setEnabled(false);
}
});

resetBtn.setEnabled(false);

northPanel.add(resetBtn);

audioLevelLabel = new JLabel("Audio Level: ");
northPanel.add(audioLevelLabel);

audioLevelValue = new JLabel("000");
audioLevelValue.setForeground(Color.red);
northPanel.add(audioLevelValue);

add(northPanel, BorderLayout.PAGE_START);

DefaultCaret caret = (DefaultCaret) textArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

JScrollPane scrollPane = new JScrollPane(textArea);

add(scrollPane, BorderLayout.CENTER);

setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}

private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("JavaX25 Decoder v.0.0.1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon img = new ImageIcon("dist/icon.png");
frame.setIconImage(img.getImage());

//Create and set up the content pane.
JComponent newContentPane = new GuiApp();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent arg0) {
decode();

}

private void decode() {
decodeBtn.setEnabled(false);
devicesComboBox.setEnabled(false);
resetBtn.setEnabled(true);
String input = (String) devicesComboBox.getSelectedItem();
Soundcard.jTextArea = textArea;
Soundcard.audioLevelValue = audioLevelValue;
guiDecoderThread = new GuiDecoderThread(input);
guiDecoderThread.start();
}

}
63 changes: 63 additions & 0 deletions src/main/java/org/jdamico/javax25/GuiDecoderThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.jdamico.javax25;

import java.util.Properties;

import org.jdamico.javax25.ax25.Afsk1200Modulator;
import org.jdamico.javax25.ax25.Afsk1200MultiDemodulator;
import org.jdamico.javax25.ax25.PacketDemodulator;
import org.jdamico.javax25.soundcard.Soundcard;

public class GuiDecoderThread extends Thread {
private String input;
public GuiDecoderThread(String input) {
this.input = input;
}

public void run() {
Properties p = System.getProperties();

int rate = 48000;

PacketHandlerImpl t = new PacketHandlerImpl();
Afsk1200Modulator mod = null;
PacketDemodulator multi = null;
try {
multi = new Afsk1200MultiDemodulator(rate,t);
mod = new Afsk1200Modulator(rate);
} catch (Exception e) {
System.out.println("Exception trying to create an Afsk1200 object: "+e.getMessage());
}


/*** preparing to generate or capture audio packets ***/

//String input = p.getProperty("input", null);
String output = null;

int buffer_size = -1;
try {
// our default is 100ms
buffer_size = Integer.parseInt(p.getProperty("latency", "100").trim());
} catch (Exception e){
System.err.println("Exception parsing buffersize "+e.toString());
}

Soundcard sc = new Soundcard(rate,input,output,buffer_size,multi,mod);



sc.displayAudioLevel();


/*** listen for incoming packets ***/

if (input != null) {
System.out.printf("Listening for packets\n");
//sc.openSoundInput(input);
sc.receive();
}else {
System.err.println("Input is null!");
}
}

}
14 changes: 13 additions & 1 deletion src/main/java/org/jdamico/javax25/PacketHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@

import org.jdamico.javax25.ax25.Packet;
import org.jdamico.javax25.ax25.PacketHandler;
import org.jdamico.javax25.soundcard.Soundcard;

public class PacketHandlerImpl implements PacketHandler {

public void handlePacket(byte[] bytes) {
System.out.println(Packet.format(bytes));


if(Soundcard.jTextArea == null) {
System.out.println("Packet ====>>>>" +Packet.format(bytes));

}else {

String lines = Soundcard.jTextArea.getText();
if(lines.length() > 80000) lines = "Cleaning log...\n";
Soundcard.jTextArea.setText(lines+Packet.format(bytes)+"\n");
}

return;
/*
if (last!=null && Arrays.equals(last, bytes) && sample_count <= last_sample_count + 100) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

import java.util.Arrays;

import javax.swing.JTextArea;

import org.jdamico.javax25.soundcard.Soundcard;

public class Afsk1200Demodulator
extends PacketDemodulator
//implements HalfduplexSoundcardClient
Expand Down Expand Up @@ -379,8 +383,9 @@ protected void addSamplesPrivate(float[] s, int n) {
// emphasis,f0_max/-f1_min,max_period_error));
if (handler!=null)
handler.handlePacket(packet.bytesWithoutCRC());
else
System.out.println(""+(++decode_count)+": "+packet);
else {
System.out.println((++decode_count)+": "+packet);
}
}
packet = null;
state=State.JUST_SEEN_FLAG;
Expand Down
Loading

0 comments on commit bef9758

Please sign in to comment.