Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build metering levels array from audio file? #11

Open
borisyurkevich opened this issue Feb 7, 2017 · 8 comments
Open

Build metering levels array from audio file? #11

borisyurkevich opened this issue Feb 7, 2017 · 8 comments

Comments

@borisyurkevich
Copy link
Contributor

Hi, thanks for your library. I assumed that's it is possible to read sound file in this library and produce graphic representation from it. However it looks like I need to get level numbers (from 0 to 1.0) by some other mean. Just wanted to confirm, does this library supports this feature?

If it doesn't maybe I can try to build it and make a pull request. Can't guarantee anything. In this case please mark this as Enhancement request.

@borisyurkevich borisyurkevich changed the title Is it possible to build metering levels array from audio file? Build metering levels array from audio file? Feb 7, 2017
@beekeweerts
Copy link

Need that feature, too! Found any solution?

@bastienFalcou
Copy link
Owner

Hi @borisyurkevich and @beekeweerts, thank you for your interest 👍

1/ So I am assuming that the following is not what you want?

play

Generated by:

self.audioVisualizationView.audioVisualizationMode = .read
self.audioVisualizationView.meteringLevels = [0.1, 0.67, 0.13, 0.78, 0.31]
self.audioVisualizationView.play(for: 5.0)

2/ The type of animation you wish to produce might be the "recording mode" one. That is, the metering level bars are appearing as the song is played, instead of being all displayed from the start and animating gradient only:

on-the-fly

In this case indeed there is nothing in the Framework allowing you to do that out of the box. However and if you don't wish to modify it, you could think of a solution as such:

let existingDataSource = [0.1, 0.8, 0.5, ..., 0.4]
let duration: TimeInterval = 10.0
let timeBetweenFrames: TimeInterval = self.existingDataSource / self.duration
var meteringLevelsLeft = existingDataSource.count

self.audioVisualizationView.audioVisualizationMode = .write

self.timer = Timer.scheduledTimer(timeInterval: self.timeBetweenFrames, target: self, selector: #selector(addMeteringLevel), userInfo: nil, repeats: true)

With:

private func addMeteringLevel() {
    if self.meteringLevelsLeft == 0 {
        timer.invalidate()
    }
    let meteringLevelValue = self.existingDataSource[self.meteringLevelsLeft]
    self.audioVisualizationView.addMeteringLevel(meteringLevelValue)
    self.meteringLevelsLeft -= 1
}

That type of solution could definitely be implemented in the Framework directly 👌Let me know if you get a chance!

@borisyurkevich may have come up with another solution as well.

@StuartMorris0
Copy link

I think what the person is asking for here is how to create the meteringLevels array from an asset. For example, I looked to use this project with songs from the users iTunes library so I have a MPMediaItem. I need to know how to read that file and generate the meteringLevels.

@bastienFalcou
Copy link
Owner

Ha I see yes, makes sense. This is not covered by the library at the moment indeed. The library is not able to generate the meteringLevels yet, this part is left to the discretion of the consumer.

@tularovbeslan
Copy link

Need that feature, too!

@hiral128
Copy link

hiral128 commented Nov 21, 2018

hey
please anyone tell me how can i create meteringLevels / averagePower before playing song
and also i want tap on wave for want to know meteringLevels of this wave and want scrolling on wave and show all wave with scrolling
if anyone know please tell me how can i do..

@Stefanhym
Copy link

Same here. Would love to have this feature.

@ljs19923
Copy link

ljs19923 commented Mar 5, 2021

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants