Hi,
I am using ShazamKit to detect songs from a live stream. I am using matchStreamingBuffer with a PCMBuffer. It looks like it works for the most part, but sometimes it throws an NSException.
Here's the code calling the match:
engine.mainMixerNode.installTap(onBus: 0, bufferSize: 4096, format: options.audioFormat) { buffer, time in
do {
self.session.matchStreamingBuffer(buffer, at: time)
}
catch {
}
}
The exception:
Supplied audio format is not supported <CMAudioFormatDescription 0x2828a29e0 [0x20f7863a0]> { mediaType:'soun' mediaSubType:'lpcm' mediaSpecific: { ASBD: { mSampleRate: 44100.000000 mFormatID: 'lpcm' mFormatFlags: 0x29 mBytesPerPacket: 4 mFramesPerPacket: 1 mBytesPerFrame: 4 mChannelsPerFrame: 2 mBitsPerChannel: 32 } cookie: {(null)} ACL: {Stereo (L R)} FormatList Array: { Index: 0 ChannelLayoutTag: 0x650002 ASBD: { mSampleRate: 44100.000000 mFormatID: 'lpcm' mFormatFlags: 0x29 mBytesPerPacket: 4 mFramesPerPacket: 1 mBytesPerFrame: 4 mChannelsPerFrame: 2 mBitsPerChannel: 32 }} } extensions: {(null)} }
This is the stack stack:
0 CoreFoundation 0xa248 __exceptionPreprocess
1 libobjc.A.dylib 0x17a68 objc_exception_throw
2 ShazamKit 0x159d0 -[SHMutableSignature appendBuffer:atTime:error:]
3 ShazamKit 0x6d7c -[SHSignatureGenerator appendBuffer:atTime:error:]
4 ShazamKit 0x3968 -[SHSessionDriverSignatureSlot appendBuffer:atTime:error:]
5 ShazamKit 0x10430 -[SHSignatureBuffer flow:time:]
6 ShazamKit 0x2490 -[SHStreamingSessionDriver flow:time:]
7 ShazamKit 0xf784 -[SHSession matchStreamingBuffer:atTime:]
8 MyApp 0x17f69c thunk for @escaping @callee_guaranteed (@guaranteed AVAudioPCMBuffer, @guaranteed AVAudioTime) -> () (<compiler-generated>)
9 AVFAudio 0x482ac AVAudioNodeTap::TapMessage::RealtimeMessenger_Perform()
10 AVFAudio 0x71c4 CADeprecated::RealtimeMessenger::_PerformPendingMessages()
11 AVFAudio 0x471e4 invocation function for block in CADeprecated::RealtimeMessenger::RealtimeMessenger(applesauce::dispatch::v1::queue)
I don't mind failing if the format is not good, but how can I avoid crashing?