Version imprimable du sujet

Cliquez ici pour voir ce sujet dans son format original

Forums MacBidouille _ Technologies Apple _ AVFoundation / initialisation AVAudioConverter

Écrit par : audionuma 22 Sep 2018, 16:27

Bonjour,
j'essaye d'implémenter une conversion de fréquence d'échantillonnage audio avec AVFoundation, avec la classe https://developer.apple.com/documentation/avfoundation/avaudioconverter?language=objc.

Il y a très peu de documentation, et les rares exemples que je trouve sont en swift, alors que je souhaite utiliser objective-c.

Contexte : projet Xcode 7.2.1, projet ligne de commande objective-c, tous réglages par défaut, sous macOS 10.10.5, OS X deployment target 10.10.

Voici un exemple minimal :

Code
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <assert.h>

int main(int argc, const char * argv[]) {
  @autoreleasepool {
    NSURL *fileURL = [NSURL fileURLWithPath:@"/Users/audionuma/un_fichier.wav"];
    
    NSError *error = nil;
    
    AVAudioFile *file = [[AVAudioFile alloc] initForReading:fileURL commonFormat:AVAudioPCMFormatFloat32 interleaved:NO error:&error];
    assert(file != nil);
    Float64 sampleRate = file.processingFormat.sampleRate;
    assert(sampleRate <= 48000.0);
    AVAudioChannelCount channels = file.processingFormat.channelCount;
    assert(channels > 0 && channels <= 2);
    
    const int factor = 4;
    AVAudioFormat *outFmt = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32 sampleRate:factor * sampleRate channels:channels interleaved:NO];
    assert(outFmt != nil);
    AVAudioConverter *converter = [[AVAudioConverter alloc] initFromFormat:file.processingFormat toFormat:outFmt];
    assert(converter != nil);
  }
    return 0;
}


Le fichier compile sans warnings ni erreurs.
Le problème que je rencontre c'est que l'assertion ligne 22 échoue :
Code
Assertion failed: (converter != nil), function main, file /Users/audionuma/resample/resample/main.m, line 22.

Avez vous une suggestion ? Je ne trouve pas de doc suggérant ce qui pourrait provoquer cette absence d'initialisation.

Propulsé par Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)