1

We are trying to display the input audio signals already recorded form an electric guitar, using a variety of amplifiers. We are looking for an algorithm to display with Java.

We are currently looking at AWT and Swing libraries and are wondering: which would be better suited to graphic or visually displaying this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Mitchb
  • 159
  • 3
  • 13

4 Answers4

2

Would you be allowed to use JavaFx? Reason I ask is JavaFx 2.0 has some excellent api's designed specifically for this sort of multimedia task. This is doable with swing or awt for sure but why not be kind to yourself? I don't have time or space to go deeply into it here but I'd recommend either 'Introduction to Javafx 2.0 by Example' or 'Pro JavaFx 2.0' both by Apress. I'd say the second is better, more comprehensive. I believe both have sample code that does pretty much what you just described.

Good luck!!

Marc H
  • 1,228
  • 3
  • 18
  • 29
  • yeah, look at the MediaPlayer class, specifically the AudioEqualizer instance it creates. You can use these to view the live spectrum of audio as it's played. Actionscript 3 has some similar abilities built in and I've seen some very cool applications of it in that language (as3). – Marc H Sep 03 '12 at 04:12
2

Use Swing rather than AWT for this. Either is capable of doing it, but Swing is more modern and supports components (JTree, JTable..) and functionality (double-buffering built-in, key bindings, PLAFs, support for rich text) that is missing from the AWT APIs.

Another advantage of using Swing is that it seems you are at a stage where you need to ask further questions. Most people who program GUIs using Java SE have never used AWT components, and the rest of us have mostly forgotten how! (There are also many more people who can help with Swing than JavaFX, at this point.)

In AWT you might use a Canvas for drawing the waveform, but in Swing you would use either of the following:

  • A JPanel (or sometimes a JComponent) where to paint we override paintComponent(Graphics)
  • A BufferedImage display in a JLabel.

You can see examples of the first technique at DrewTubeish - here is Leftover Wine.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1

JFreeChart includes a variety of suitable charts; there's a time domain example here. This KineticModel extends JLabel and implements Icon to display a frequency domain Histogram. Neither requires Swing, but either works better in a Swing context.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

I've used AWT, Swing and JavaFX for major projects in Audio, including waveform drawing and editing. Here are my thoughts:

  • AWT is not being developed or taught. I don't know of any developers who still work with it. I would not use it.
  • JavaFX is a disaster. Back in 2010 I was working on the largest JavaFX codebase around, and we dropped it for swing. I'm sure it's gotten better, but I haven't yet heard anyone say it can handle major projects. If your project is small, JavaFX may be a good choice, or if you feel strongly, you may want to do further research. You can read more about my experience here: http://blog.bjornroche.com/2010/03/java-nofx-why-one-project-dropped.html
  • Swing has problems, and deserves much of the criticism it receives, but if you know what you are doing it can be awesome. I have developed some kick-ass UI's with it (they looked EXACTLY like the designs). Swing is written on top of AWT, which you would think would make it slower, but there are a lot of optimizations that actually make it very fast on most platforms. If I understand correctly, CodenameOne uses a swing-like interface, so in my book, that's another vote for swing: http://www.codenameone.com/
  • SWT is another option. http://www.eclipse.org/swt/ I have never used it, but I understand you have to do your own memory management with that, which, IMO, takes away a lot of the advantages of using Java. Like I said, though, I've never used it so I could be wrong. It is the native toolkit of Eclipse.
Bjorn Roche
  • 11,279
  • 6
  • 36
  • 58