IPB

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topic
> AVFoundation / initialisation AVAudioConverter, en objective-c
Options
audionuma
posté 22 Sep 2018, 16:27
Message #1


Macbidouilleur d'Or !
*****

Groupe : Membres
Messages : 2 031
Inscrit : 27 Apr 2004
Membre no 18 176



Bonjour,
j'essaye d'implémenter une conversion de fréquence d'échantillonnage audio avec AVFoundation, avec la classe AVAudioConverter.

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.


--------------------
Membre du club des AIPBP (Anciens Inscrits Pas Beaucoup de Posts) Voir la liste
Futur ex-macbidouilleur, sous Dell / Ubuntu depuis 2021 !
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



Nous sommes le : 28th March 2024 - 13:05