2

I'm creating a sort of drum pad app, and it seems like AKPlayer is the best of many classes available in AudioKit for playing my samples.

Trouble is, when I start playing a low-frequency (bass note) sample, there's always a clicking sound (or "pop") when playing the sample!

This can be easily heard by running an unmodified "Mixing Nodes" demo from the AudioKit Playgrounds. Turn down the volume on everything but the Bass, and you'll notice the clicking every time the Bass sample loops.

I also tested the issue with AVFoundation and it is the case too. This only happens with low frequency sounds like bass. Lead and other sounds dont produce this. I also tested with my own bass sample and same issue was here.

Here is the code for both:

import AudioKitPlaygrounds
import AudioKit

import AVFoundation


//: This section prepares the players
let drumFile = try AKAudioFile(readFileName: "drum.wav")
let bassFile = try AKAudioFile(readFileName: "bass.wav")
let guitarFile = try AKAudioFile(readFileName: "guitar.wav")
let leadFile = try AKAudioFile(readFileName: "lead.wav")

var drums = AKPlayer(audioFile: drumFile)
var bass = AKPlayer(audioFile: bassFile)
var guitar = AKPlayer(audioFile: guitarFile)
var lead = AKPlayer(audioFile: leadFile)

bass.play() // will produce click/pop
guitar.play() // will not produce click/pop, only low frequency samples produce click


let path = Bundle.main.path(forResource: "3", ofType:"aac")!
let url = URL(fileURLWithPath: "path")

var bombSoundEffect = try AVAudioPlayer(contentsOf: bassFile.url)
bombSoundEffect.prepareToPlay()

// uncomment below for AVFoundation
// bombSoundEffect.numberOfLoops = -1
// bombSoundEffect.play()

How may I get rid of this click/pop?

cs guy
  • 926
  • 2
  • 13
  • 33

1 Answers1

2

Rework your bass sample so that it starts and ends with some silence.

To avoid clicks and pops when looping, the values at the seam must be continuous, that is they must not differ too much. Their velocities need to match too, not sure about acceleration. You could achieve this easily by loading the sample into memory and multiplying it by a curve that has the above properties. Something that eases in from 0 to 1 at the beginning then back out at the end.

Also load up your sample in sound editor and inspect the beginning and end. Maybe the end has been cut off too sharply.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • What is the best way to handle these click/pops. It seems like this is one of the biggest problems in audio field. Do you have any experience on how to handle these clicks without modifying the source sample? – cs guy Mar 25 '21 at 15:01
  • To avoid clicks and pops when looping, the values at the seam must be continuous, that is they must not differ too much. Their velocities need to match too, not sure about acceleration. You could achieve this easily by loading the sample into memory and multiplying it by a curve that has the above properties. Something that eases in from 0 to 1 at the beginning then back out. Also load up your sample in sound editor and inspect the beginning and end. Maybe the end has been cut off too sharply. – Rhythmic Fistman Mar 25 '21 at 15:06
  • Wow very well explained, thank you. I am very stuck on this, I could really use help if you don't mind. Your experience on ios audio seems just the right fit. Here is the link https://stackoverflow.com/questions/66801870/audio-alternative-to-ffmpeg-core-audio-ios – cs guy Mar 25 '21 at 15:44
  • also I accepted this as answer because of the detailed description in the comment, could you paste it your answer – cs guy Mar 25 '21 at 22:23
  • Thanks and you're welcome! It looks like your other question has been answered. – Rhythmic Fistman Mar 25 '21 at 22:46
  • Yes it has been but I have another important one. If you are confident about Audiokit, I would love to see an answer for this. https://stackoverflow.com/questions/66806338/audiokit-akplayer-can-not-loopback-to-beginning-with-setposition – cs guy Mar 25 '21 at 22:51