fulldecent / FDWaveformView

Reads an audio file and displays the waveform
MIT License
1.25k stars 170 forks source link

M4A format compatibility #12

Closed jpm closed 10 years ago

jpm commented 10 years ago

I'm no audio expert by any means, so this might be a silly question: is FDWaveformView supposed to be compatible with M4A files?

When I try to set the audioURL to my M4A file (local file, not streamed) the code crashes as the "tracks" property is an empty array.

--Joao

fulldecent commented 10 years ago

Hmm, which hardware and software version? This may be related to hardware/software acceleration. And how big is the file? Are you able to share the file or is this for all M4A files?

Is there encryption in the file?

jpm commented 10 years ago

Hey, thanks for the quick response.

I'm on my initial prototype tests for this waveform feature, so I'm still just trying to run it on the iPhone Simulator (iOS 7.0 - iPhone Retina 4-inch 64-bit).

The file itself is ~110KB in size, and it's just a dummy audio file for me to test this feature. You are welcome to try it -- http://ipanemalabs.com/audio_test.m4a

--Joao

jpm commented 10 years ago

Hey, not trying to pressure you or anything, but I'm curious to understand the problem with the M4A compatibility. Is it something about this particular file that is causing the issue?

Cheers, --Joao

fulldecent commented 10 years ago

Joao, I used the file

Morrison Trio Sample 2012 - Bittersweet Symphony by The Verve.m4a
http://www.morrisontrio.com/audio-samples.php

And updated

NSString *filePath = [thisBundle pathForResource:@"Submarine" ofType:@"aiff"];

To

NSString *filePath = [thisBundle pathForResource:@"bittersweet" ofType:@"m4a"];

And got this:

screen shot 2014-01-17 at 5 05 53 pm

The files look similar:

$ file *m4a
audio_test.m4a:  ISO Media, MPEG v4 system, iTunes AAC-LC
bittersweet.m4a: ISO Media, MPEG v4 system, iTunes AAC-LC

Do you have any other ideas on how this file could be different?

fulldecent commented 10 years ago

Is anyone else able to confirm this issue is not working for them?

jpm commented 10 years ago

No idea on how the file could be different. I created it through the iPhone Simulator on my computer, with code that uses AVAudioRecorder:

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0f] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];

// Initiate and prepare the recorder
NSError *error = nil;
self.recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:&error];

Perhaps I'm doing something here as far as the recording settings go?

--Joao

lulucom commented 10 years ago

Joao, you have to include your m4a into your target bundle resources so that NSBundle can get the path. Make sure it is listed in "Copy Bundle Resources" of "Build Phases" of your target.

If your m4a is in your app's Documents or Chaches directory, you need to use NSFileManager instead of NSBundle.

jpm commented 10 years ago

Takaya (lulucom), Thanks for trying to help, but that is not the issue. I have a proper handle to the file path to where the M4A file is stored.

--Joao

fulldecent commented 10 years ago

Wait a minute... I'm having no trouble rendering your file provided above.

screen shot 2014-02-13 at 9 40 58 am

diff --git a/FDWaveformView.xcodeproj/project.pbxproj b/FDWaveformView.xcodeproj/project.pbxproj
index 30ff923..dff6be8 100644
--- a/FDWaveformView.xcodeproj/project.pbxproj
+++ b/FDWaveformView.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
    objects = {

 /* Begin PBXBuildFile section */
+       D9A1D9B118AD0EA500E023C7 /* audio_test.m4a in Resources */ = {isa = PBXBuildFile; fileRef = D9A1D9B018AD0EA500E023C7 /* audio_test.m4a */; };
        D9FE116F180256830000F135 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9FE116E180256830000F135 /* Foundation.framework */; };
        D9FE1171180256830000F135 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9FE1170180256830000F135 /* CoreGraphics.framework */; };
        D9FE1173180256830000F135 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9FE1172180256830000F135 /* UIKit.framework */; };
@@ -23,6 +24,7 @@
 /* End PBXBuildFile section */

 /* Begin PBXFileReference section */
+       D9A1D9B018AD0EA500E023C7 /* audio_test.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = audio_test.m4a; sourceTree = "<group>"; };
        D9FE116B180256830000F135 /* FDWaveformView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FDWaveformView.app; sourceTree = BUILT_PRODUCTS_DIR; };
        D9FE116E180256830000F135 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
        D9FE1170180256830000F135 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
@@ -102,6 +104,7 @@
                D9FE1186180256830000F135 /* ViewController.h */,
                D9FE1187180256830000F135 /* ViewController.m */,
                D9FE11AD18025B1B0000F135 /* Submarine.aiff */,
+               D9A1D9B018AD0EA500E023C7 /* audio_test.m4a */,
                D9FE1189180256830000F135 /* Images.xcassets */,
                D9FE1175180256830000F135 /* Supporting Files */,
            );
@@ -172,6 +175,7 @@
            buildActionMask = 2147483647;
            files = (
                D9FE11AE18025B1B0000F135 /* Submarine.aiff in Resources */,
+               D9A1D9B118AD0EA500E023C7 /* audio_test.m4a in Resources */,
                D9FE118A180256830000F135 /* Images.xcassets in Resources */,
                D9FE1182180256830000F135 /* Main.storyboard in Resources */,
                D9FE1179180256830000F135 /* InfoPlist.strings in Resources */,
diff --git a/FDWaveformView/ViewController.m b/FDWaveformView/ViewController.m
index 95f9a29..bc82d62 100644
--- a/FDWaveformView/ViewController.m
+++ b/FDWaveformView/ViewController.m
@@ -19,7 +19,7 @@
 {
     [super viewDidLoad];
     NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
-    NSString *filePath = [thisBundle pathForResource:@"Submarine" ofType:@"aiff"];
+    NSString *filePath = [thisBundle pathForResource:@"audio_test" ofType:@"m4a"];
     NSURL *url = [NSURL fileURLWithPath:filePath];

     // We wish to animate the waveformv iew in when it is rendered
Williams-MacBook-Air:FDWaveformView williamentriken$ 
fulldecent commented 10 years ago

@jpm Please reopen if there is another issue, but we are not seeming to have a problem rendering the supplied sample M4A file