I recently released my first ShazamKit app, but there is one thing that still bothers me.
When I started I followed the steps as documented by Apple right here : https://developer.apple.com/documentation/shazamkit/shsession/matching_audio_using_the_built-in_microphone
however when I was running this on iPad I receive a lot of high pitched feedback noise when I ran my app with this configuration. I got it to work by commenting out the output node and format and only use the input.
But now I want to be able to recognise the song that’s playing from the device that has my app open and was wondering if I need the output nodes for that or if I can do something else to prevent the Mic. Feedback from happening.
In short:
- What can I do to prevent feedback from happening
- Can I use the output of a device to recognise songs or do I just need to make sure that the microphone can run at the same time as playing music?
Other than that I really love the ShazamKit API and can highly recommend to have a go with it!
This is the code as documented in the above link (I just added the comments of what broke it for me)
func configureAudioEngine() {
// Get the native audio format of the engine's input bus.
let inputFormat = audioEngine.inputNode.inputFormat(forBus: 0)
// THIS CREATES FEEDBACK ON IPAD PRO
let outputFormat = AVAudioFormat(standardFormatWithSampleRate: 48000, channels: 1)
// Create a mixer node to convert the input.
audioEngine.attach(mixerNode)
// Attach the mixer to the microphone input and the output of the audio engine.
audioEngine.connect(audioEngine.inputNode, to: mixerNode, format: inputFormat)
// THIS CREATES FEEDBACK ON IPAD PRO
audioEngine.connect(mixerNode, to: audioEngine.outputNode, format: outputFormat)
// Install a tap on the mixer node to capture the microphone audio.
mixerNode.installTap(onBus: 0,
bufferSize: 8192,
format: outputFormat) { buffer, audioTime in
// Add captured audio to the buffer used for making a match.
self.addAudio(buffer: buffer, audioTime: audioTime)
}
}