0

I have been trying to generate Audacity-like waveforms. I used java sound api and got up to a decent point of representing the actual mp3 to a waveform. Do you have in mind any mathematic function that I can apply to the dataset to be painted so the it looks more dense and smoother?

Thanks!

EDIT 1:

The proposal for moving average(I used the exponential) works great but do to the restrictions I have(single threaded) was performing really heavy. Apart from that the output was excellent!

I ended up into a small implementation of my own. I take the local maxima of an area of values and connect it with a straight line to the local maxima of the next area. It is fast and gives nice output.

EDIT 2: Linking code/solution by @Nicholas DiPiazza

Community
  • 1
  • 1
Potney Switters
  • 2,902
  • 4
  • 33
  • 51
  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/). But to make an SSCCE, you'll need to either hot-link to a sound file supported by J2SE ([e.g.](http://pscode.org/media/#sound)), or generate it at run-time using Java Sound. – Andrew Thompson May 11 '12 at 01:59
  • Thanks for pointing this out Andrew :) – Potney Switters May 14 '12 at 07:18
  • 1
    I created a program and posted its code here: http://stackoverflow.com/questions/11017283/java-program-that-create-a-png-waveform-for-an-audio-file – Nicholas DiPiazza Jun 13 '12 at 15:01

1 Answers1

1

If I understand you correctly, you have figured out how to get to the PCM datapoints, but are now wanting to fit a curve to them. Yes?

Linear interpolation is the simplest way to do this. I'm surprised if it isn't smooth enough. What is your sample rate?

I know there are higher-order curves that can also be used to fit datapoints and that would make the graphical representation smoother. I'm not sure exactly what would be the best for representing an audio wave. I seem to recall the term "cubic interpolation" bandied about for use with audio. Can't say for sure though, and the math is a bit rough.

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41
  • Thanks for replying Phil. I am representing MP3 files. The track that creates the problematic representation has a sampling rate of 48000 Hz. The interpolation will give me more "in between" values. I do not have this problem, I have enough samples. My problem is that the pure representation of the tracks is not fancy enough, like soundcloud. So you can have peaks, muted intervals etc. The ideal situation would be to even up all this and make it appear smoother. – Potney Switters May 14 '12 at 07:25
  • 1
    SoundCloud graphs are just PCM data, aren't they? The ones I've seen can get pretty spikey. SoundCloud might "normalize" data so that the visual spans the display vertically, but I don't think anything else is done. (You know what that means, right? Example, with 16-bit signed PCM encoding: divide the PCM value by 32767, and call the top of the display 1 and the bottom -1.) Data smoothing is typically done with a filter function or a rolling average, but either will make the visual data an inaccurate representation of the sound. I guess I don't understand what you are asking for. Sorry! – Phil Freihofner May 14 '12 at 12:27
  • I dont think I formalized it correctly, my bad :) My problem is on filtering or the rolling average thing, my goal is to decrease the spikes. Do you have any idea for possible filters?(or a library) Thanks Phil! – Potney Switters May 14 '12 at 12:39
  • 1
    You might try this article on "Moving Averages" from wikipedia. http://en.wikipedia.org/wiki/Moving_average Simply put, for each data point, you would make a new data point that is the average of N of its neighbors. The more neighbors used, the smoother the resulting line. It is also possible to weight the neighbors so that the nearer ones impact the average the most. There is also a wiki article on "Low Pass Filters" that might be helpful, but the math can get hairy. There IS an algorithm near the end of the article, though, that I programmed once as a test and it does work. Good Luck! – Phil Freihofner May 14 '12 at 13:04