Representing sound graphically as a wave

I created an application that records and plays sound, and I'm looking for a way to show a simple wave representation of the recorded sound, no animation is required, just a simple graph.

It would also be nice if you could pick up a subset of the waves and freshness by playing in this section.

To summarize, I am looking for:

  • A way to graphically represent recorded sound in the form of a wave (for example, as seen from boldness)
  • A way to graphically select a subset of a wave representation.

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

  • If there is lib for this, I would be insanely happy :)
  • A hint about which components are best used for processing a graphic drawing.
  • Advice on how to handle selections in a graphics component.
+5
source share
1 answer

I already did this in another application and struggled with it for a while ...

You would divide the number of samples that the audio file has by the number of pixels that you should display on the graph. This gives you a piece. For all buckets, you calculate the minimum and maximum values ​​and display them depending on the resolution used.

May provide additional examples if necessary.


Regarding graphics: (I'm not an iOS developer, but programming on a Mac isn't that much different.) Just create a subclass of NSView (must be UIView on iOS) and override the drawRect method. Then just create a function in which you pass an array of values ​​for your file and draw a bunch of lines on the screen. There is no black magic here!

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

+3
source

Source: https://habr.com/ru/post/952367/


All Articles