Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioKit File Normalization

I'm trying to normalize audio file after record to make it louder or vice versa, but i'm getting error WARNING AKAudioFile: cannot normalize a silent file

I have checked recordered audioFile.maxLevel and it was 1.17549e-38, minimum float.

I'm using official Recorder example, and to normalize after record i added this code:

let norm = try player.audioFile.normalized(newMaxLevel: -4.0);

What I'm doing wrong? Why maxLevel invalid? Record is loud enough.

like image 700
Roman Simenok Avatar asked Mar 27 '26 07:03

Roman Simenok


1 Answers

Rather than use the internal audio file of the player, make a new instance like so:

if let file = try? AKAudioFile(forReading: url) {
    if let normalizedFile = try? file.normalized(newMaxLevel: -4) {
        Swift.print("Normalized file sucess: \(normalizedFile.maxLevel)")
    }
}

I can add a normalize func to the AKAudioPlayer so that it's available for playback. Essentially, the player just uses the AKAudioFile for initialization, and all subsequent operations happen in a buffer.

like image 105
Ryan Francesconi Avatar answered Mar 29 '26 22:03

Ryan Francesconi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!