This is an Maven project. Apache NetBeans 32 -> JDK settings -> java plattform: JDK 27, target release: 8. To compile an maven project to an executable *.jar file must this include in pom.xml:
4.0.0
com.mycompany
stereoplotsync
1.0-SNAPSHOT
jar
StereoPlotSync
org.apache.maven.plugins
maven-assembly-plugin
3.6.0
com.mycompany.stereoplotsync.StereoPlotSync
jar-with-dependencies
make-assembly
package
single
this is the result:
stereoplotsync-1.0-SNAPSHOT-jar-with-dependencies.jar
Thank! you for all help: https://www.bing.com/copilotsearch
and
https://netbeans.apache.org/tutorial/main/kb/docs/java/javase-deploy/
https://stackoverflow.com/questions/22332745/maven-and-netbeans-how-do-i-build-project-and-get-executable-jar
https://stackoverflow.com/questions/15282098/netbeans-maven-project-not-adding-main-class-to-manifest
https://maven.apache.org/pom.html
XML validation started Checking file:/C:/Users/Peter%20Adolfsson/Documents/NetBeansProjects/StereoPlotSync/pom.xml...Referenced entity at https://maven.apache.org/xsd/maven-4.0.0.xsd.
XML validation finished.
Error with pom.xml: Premature end of file. [1]
No error after Notepad++ -> convert to UTF-8.
Delete all help information before compile.
package com.mycompany.stereoplotsync;
/**
* @author Peter Adolfsson and
* Microsoft AI mode (www.bing.com/copilotsearch and www.bing.com/search).
*/
import javax.sound.sampled.*;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class StereoPlotSync extends JFrame {
private final PlotPanel plotPanel;
private volatile boolean syncEnabled = false;
private volatile long syncStartTime = 0;
private final List samples = new ArrayList<>();
public StereoPlotSync() {
setTitle("Stereo Plot with Sync");
setSize(800, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
plotPanel = new PlotPanel(samples);
JButton syncButton = new JButton("Synchronize");
syncButton.addActionListener(e -> {
syncEnabled = true;
syncStartTime = System.nanoTime();
});
add(plotPanel, BorderLayout.CENTER);
add(syncButton, BorderLayout.SOUTH);
startAudioCapture();
startPlotTimer();
}
private void startAudioCapture() {
new Thread(() -> {
try {
AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
TargetDataLine line = AudioSystem.getTargetDataLine(format);
line.open(format);
line.start();
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = line.read(buffer, 0, buffer.length)) > 0) {
for (int i = 0; i < bytesRead; i += 4) {
int leftSample = (buffer[i + 1] << 8) | (buffer[i] & 0xFF);
int rightSample = (buffer[i + 3] << 8) | (buffer[i + 2] & 0xFF);
samples.add(new int[]{leftSample, rightSample});
}
}
} catch (LineUnavailableException ex) {
}
}).start();
}
private void startPlotTimer() {
new Timer(30, e -> {
if (syncEnabled) {
long elapsedMs = (System.nanoTime() - syncStartTime) / 1_000_000;
if (elapsedMs >= 30) {
syncStartTime = System.nanoTime();
plotPanel.resetHorizontal();
}
}
plotPanel.repaint();
}).start();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new StereoPlotSync().setVisible(true));
}
static class PlotPanel extends JPanel {
private final List samples;
private int horizontalOffset = 0;
PlotPanel(List samples) {
this.samples = samples;
setBackground(Color.BLACK);
}
void resetHorizontal() {
horizontalOffset = 0;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.GREEN);
int width = getWidth();
int height = getHeight();
int xCenter = width / 2;
int yCenter = height / 2;
int maxPoints = Math.min(samples.size(), width);
for (int i = 0; i < maxPoints; i++) {
int[] sample = samples.get(samples.size() - maxPoints + i);
int x = xCenter + (sample[0] / 256) + horizontalOffset;
int y = yCenter - (sample[1] / 256);
g.drawLine(x, y, x, y);
}
horizontalOffset++;
if (horizontalOffset > width) horizontalOffset = 0;
}
}
}