bastienFalcou / SoundWave

Illustrate your sound waves on the fly πŸš€
MIT License
611 stars 94 forks source link

Build metering levels array from audio file? #11

Open borisyurkevich opened 7 years ago

borisyurkevich commented 7 years ago

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.

beekeweerts commented 6 years ago

Need that feature, too! Found any solution?

bastienFalcou commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Need that feature, too!

hiral128 commented 5 years ago

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 commented 4 years ago

Same here. Would love to have this feature.

ljs19923 commented 3 years ago

Same here