manipulating audio and drawing waveform using java sound in real-time

11,355

Solution 1

John says:

First, forget Java ... Secondly, you will be interfacing with the hardware ... Java does not support this kind of thing.

Jeez, that's kinda harsh - you should have told Sun that this wasn't possible before they published the API for this: http://java.sun.com/products/java-media/sound/. There's lots done with sound in Java, and I've never had an issue with latency or buffers, even on somewhat decrepit hardware.

Good examples @ http://www.jsresources.org/examples/index.html

Good help @ http://java.sun.com/products/java-media/sound/list.html

... having said that, John's comments on learning DSP & waveform analysis are on the $$$.

Have fun - Dave

Solution 2

This open source project maybe a good reference for you. There's a function that construct the waveform http://code.google.com/p/musicg/

Share:
11,355
starblue
Author by

starblue

I'm a free-lance embedded software developer who likes computer science, mathematics, electronics and foreign languages. eiπ + 1 = 0 eπ√163 ≅ 6403203 + 744 rot13("fr") = "se"

Updated on June 08, 2022

Comments

  • starblue
    starblue about 2 years

    I am currently developing an application that helps the user to tune his guitar and generate guitar effects. This is in real-time. I've been looking through java applications that could give an idea to generate guitar effects such as overdrive and delay but I couldn't find any. Also a source on creating a waveform in real time is needed. Your comments would be so much help, thanks in advance.

  • John Leidegren
    John Leidegren about 14 years
    I believe the impact of garbage collection will reveal itself when you use small buffers which are necessary to minimize latency (the ~2ms range). Though I never meant that Java wasn't capable of playing back sound. You use something like JNI to bridge a native engine for performance reasons with a managed UI framework for productivity. That's typically what I go for whenever the performance is critical.
  • Jonathan Spooner
    Jonathan Spooner over 12 years
    By the way, the above library is written in Java
  • John Leidegren
    John Leidegren almost 11 years
    I recently came across this little tid bit, thought I'd share it. stackoverflow.com/a/1602139/58961
  • supercat
    supercat over 10 years
    @JohnLeidegren: I've often thought that what would be helpful would be if streams kept track of an absolute amount of time since they were opened, and one could specify that a stream of audio data should replace anything that's already buffered, starting at a particular absolute time, with the semantics that if that time was in the past, the appropriate amount of new data would be skipped, so that each sample which had been enqueued to play at a particular time would get replaced with data that was intended to play at the same time. That would allow code to enqueue speculative data...
  • supercat
    supercat over 10 years
    ...but replace it instantly if controls were changed so that it became obsolete. Any idea if systems do anything like that?
  • John Leidegren
    John Leidegren over 10 years
    Well sure, but it's gonna depend on how the data stream is encoded, PCM is straightforward since seek time relates linearly with sample rate, bit depth and channel count. For other encoded streams I wouldn't know but typically you have the concept of a bit rate which probably is a good approximation but not exact, for exact seek times you'd probably rely on more knowledge of how the stream is encoded. Maybe there are markers in the data stream that you can jump to and then seek from them, that's probably a good tradeoff between efficiency and what's practical.
  • John Leidegren
    John Leidegren over 10 years
    You could do away with the encoding problem entirely if it's enough to just jump around PCM data streams, most providers that I know of tend to emit PCM data stream in the end. It's probably a combination of both but I'm not that sure I understand your use case, exactly right.