Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

representing sound graphically as wave

Tags:

ios

audio

I Have created an app that records and plays sound and I am looking for a way of showing a simple wave representation of the recorded sound, no animation is necessary, just a simple graph.

It would also be nice it is was possible to select a subset of the wave and ofcourrse even more nice playing that section aswell.

To sum up, what I'm looking for:

  1. A way of graphically represent a recorded sound as a wave (e.g as seen in audacity)
  2. A way of graphically selecting a subset of the wave representation.

And to clarify a bit further of what I'm looking for:

  1. If there is a lib for this I'd be insanely happy :)
  2. A hint on what components to best use for handling the graph drawing.
  3. A tip on how to handle the selection within the graphical component.
like image 463
tommys Avatar asked Oct 09 '22 16:10

tommys


1 Answers

I already did this in another application and have been struggling with it for a while ...

You would divide the number of samples the audio file has by the number of pixels you have to display the graph. This gives you a chunksize. For all the "buckets" you calculate the min and max value and display them in relation to the sample resolution used.

Can provide further examples if needed.


Regarding the graphics stuff: (I am not an iOS developer but Mac programming isn't that much different I think.) Just create a subclass of NSView ( should be UIView in iOS ) and override the drawRect method. Then just create a function which you pass an array of values for your file and draw a bunch of lines to the screen. It's no black magic here!!

This is really nothing you would need a library for! And, as another positive aspect : if you keep it generic enough you can always reuse it.

like image 120
guitarflow Avatar answered Oct 12 '22 11:10

guitarflow