Error on connect AudioEngin with AudioPlayerNoded with AVAudioPCMFormatInt16

Hi community,

I'm trying to setup an AVAudioFormat with AVAudioPCMFormatInt16. But, i've an error :

AVAEInternal.h:125 [AUInterface.mm:539:SetFormat: ([[busArray objectAtIndexedSubscript:(NSUInteger)element] setFormat:format error:&nsErr])] returned false, error Error Domain=NSOSStatusErrorDomain Code=-10868 "(null)"

If i understand the error code 10868, the format is not correct. But, how i can use PCM Int16 format ? Here is my method :

- (void)setupAudioDecoder:(double)sampleRate audioChannels:(double)audioChannels {
    if (self.isRunning) {
        return;
    }

    self.audioEngine = [[AVAudioEngine alloc] init];
    self.audioPlayerNode = [[AVAudioPlayerNode alloc] init];

    [self.audioEngine attachNode:self.audioPlayerNode];

    AVAudioChannelCount channelCount = (AVAudioChannelCount)audioChannels;

    self.audioFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatInt16
                                              sampleRate:sampleRate
                                              channels:channelCount
                                              interleaved:YES];

    NSLog(@"Audio Format: %@", self.audioFormat);
    NSLog(@"Audio Player Node: %@", self.audioPlayerNode);
    NSLog(@"Audio Engine: %@", self.audioEngine);

    // Error on this line
    [self.audioEngine connect:self.audioPlayerNode to:self.audioEngine.mainMixerNode format:self.audioFormat];

    
    /**NSError *error = nil;

    if (![self.audioEngine startAndReturnError:&error]) {
        NSLog(@"Erreur lors de l'initialisation du moteur audio: %@", error);
        return;
    }

    [self.audioPlayerNode play];
    self.isRunning = YES;*/
}

Also, i see the audioEngine seem not running ?

Audio Engine: 
________ GraphDescription ________
AVAudioEngineGraph 0x600003d55fe0: initialized = 0, running = 0, number of nodes = 1

Anyone have already use this format with AVAudioFormat ?

Thank you !

Hello @stephane-r, error code -10868 corresponds to kAudioUnitErr_FormatNotSupported. If you are getting this error, you might need to convert your audio data using AVAudioConverter, for example. Please see TN3136 for more information. If you are not performing sample rate conversions, you can use convert(to:from:) instead of convert(to:error:withInputFrom:), which offers much simpler, one-shot conversion functionality.

Error on connect AudioEngin with AudioPlayerNoded with AVAudioPCMFormatInt16
 
 
Q