Audio not working on 3.1.2?

Member
Posts: 93
Joined: 2008.11
Post: #1
Hi guys,

I have my own sound engine with code base from GBMusicTrack by AnotherJake. All the code worked wonderful under 2.x and 3.0/3.1. However, under 3.1.2 it just wont work. Anyone experienced any problems with sound recently?
I already tried everything possible.. The audio session is setup correctly and if I change between Ambient and MediaPlayback it really looks like it works (silences the iPod or mixing through in Ambient mode).. But my music and even most of the effects (AVPlayer for effects) just wont work. I only get one .caf file to play using AVPlayer and that .caf file is nothing different from the others.

Any ideas?
Thanks in advance!
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #2
Weird. I'd say I'm surprised, but they keep changing all the audio stuff around for iPhone, it seems, like every little update.

I tried GBMusicTrack on 3.1.2 a couple months ago and it seemed to work just fine. I have been using AVAudioPlayer for iPhone releases. I use OpenAL for effects. One little detail I found which you will have to do is use kAudioSessionCategory_SoloAmbientSound (note the "solo" in there) instead of kAudioSessionCategory_AmbientSound, to get rid of an annoying performance problem related to whether it decodes in software or hardware... but that sounds unrelated to your issue. Other than that, everything seems to work fine on 3.1.2.

I wonder if there is some conflict with using AVAudioPlayer and GBMusicTrack at the same time on 3.1.2? Otherwise I'm kinda stumped at the moment.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #3
Hi Jake,

Well, I'm stumped too. I tried everything already but the sound just wont work on the device. It works just fine on the simulator though.

I'm not really using OpenAL unless I'm playing OGG which can happen if the user uploads a song in that format.. However, I tried to remove the code which initializes OpenAL and it didn't help anything.. neither did the music in the simulator stop working correctly.

For music, I'm using your GBMusicTrack code (well, slightly modified) to play .mp3 files with fade in/out, positioning and looping possibilities.. all the UI effects (buttons, togglers etc.) are played using AVAudioPlayer as that is just simpler.. isn't it?

Also, tried the SoloAmbientSound, didn't help, as expected. Thanks for the input though!

While writing this I tried one thing. I removed the code that adds the background music for the menu and I hoped that it will allow effect sounds to work correctly as that would not mix with GBMusicTrack at same time.. but what happened is much more weird. Instead of what I expected I've got sound in the song selection screen. The one with looping, fading and positioning! It just seems to work on some files and fail on some others.. plus if it already failed ones it wont work again.. what could it be? I can't think of a reason for the files to be under DRM or something.. I manually converted them to .caf and they shouldn't differ from the file that I reported to work in the original post...
Ideas?

Regards,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #4
Some more info became available: AVAudioPlayer gives me OSStatus 1685348671. This means "invalid file, malformed etc.". But hey, it works on the simulator and it used to work on the older iPhone OS versions... how can this be invalid? Ideas?

Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #5
That is definitely weird that you're getting errors from AVAudioPlayer about the files. Just out of curiosity, have you rebooted your device lately?

I'm still totally clueless about why it isn't working for you on 3.1.2.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #6
Jake, the problem appears on all 3.1.2 devices around the world which are using my game.. every 100th user which upgrades to 3.1.2 reports this problem.. and the others just downgrade or forget about my game.

I'm about to create a simple empty project with the sound engine included just to test whether it still fails or not. Also, my sound engine lives in a separate thread and manages a queue.. however, it works on the simulator and it used to work asis on older iPhone firmware.

Regards,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #7
I can't imagine why using a separate thread for any audio stuff would cause an issue, although I suppose anything's possible.

Keep us updated!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #8
Some more useless info regarding this issue:

This AIFF file isn't working. Compiled from a .caf file which didn't work either:

File: Data/themes/default/Sounds/SongsLoader/Music_(loop).aiff
File type ID: AIFF
Data format: 1 ch, 44100 Hz, 'lpcm' (0x0000000E) 16-bit big-endian signed integer
no channel layout.
estimated duration: 13.241 sec
audio bytes: 1167856
audio packets: 583928
bit rate: 705600 bits per second
packet size upper bound: 2
audio data file offset: 54
optimized


But this one works! Compiled from a .caf which didn't work:

File: Data/themes/default/Sounds/Common/MenuMusic_(loop).aiff
File type ID: AIFF
Data format: 1 ch, 44100 Hz, 'lpcm' (0x0000000E) 16-bit big-endian signed integer
no channel layout.
estimated duration: 13.714 sec
audio bytes: 1209574
audio packets: 604787
bit rate: 705600 bits per second
packet size upper bound: 2
audio data file offset: 54
optimized

Now tell me, what is the freaking difference between them? And why .caf didn't work but .aiff works? It's the same LPCM data.. just another header. What the hell is going on? :-)

Regards,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #9
Update: Works with exactly the same issues on iPhone 3G with iPhoneOS 3.0. Game compiled with 3.1.2 SDK for 2.2 device/release.
What could this mean? That the problem is in the SDK or that it's in my code (which didn't change since it worked last time)? This becomes even more weird...

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #10
Way back we logged a bug with Apple where loading audio was randomly failing on some filenames when testing again a beta of an SDK. It was a while back but IIRC the file info/loading functions the Sound Library code (and AL code in general) was using such as LoadFileDataInfo were failing for certain file names that had previously (and subsequently) worked fine.

Changing the filename slightly fixed it as a workaround. It was fixed by the time the release version came out and haven't seen it since, but if you find changing the filenames is all you need to fix it, it may be worth using that as a workaround and logging a bug.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #11
Hi,

This doesn't seems to be the problem.
Hereby some test code for AVAudioPlayer..

Code:
- (void) playSound:(NSString*)sound {
    NSLog(@"Going to play sound: %@", sound);
    
    NSError* err;
    AVAudioPlayer *avSound = [[AVAudioPlayer alloc] initWithContentsOfURL:
                              [NSURL fileURLWithPath:sound] error:&err];
    
    if(!avSound) {
        NSLog(@"PlayEffect err: %@", [err localizedDescription]);
        return;
    }
    
    [avSound play];
    NSLog(@"Should play now...");
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    
    // Enable audio
     OSStatus result = AudioSessionInitialize(NULL, NULL, NULL, NULL);
     if(result) {
         NSLog(@"Problems initializing audio session.");
     }
    
     UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
     result = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);
     if(result) {
         NSLog(@"Problems setting category for audio session.");
     }
    
     result = AudioSessionSetActive (true);
     if(result) {
         NSLog(@"Problems activating audio session.");
     }    
    
    // Now play the sound
    NSString* path = [[NSBundle mainBundle] pathForResource:@"test3" ofType:@"caf"];
    [self playSound:path];
}

This code does work on simulator 2.2 but fails on simulator/device 3.1.2.
Here is the test project: http://tapmania.org/testsound.tar.gz
Can anyone please test this code on their machine just to make sure it's not mine SDK which could get broken or something?
Also, what do you think about the code? It should work right? How do you init/play sound on 3.1.2?

EDIT: Forgot to say that test3.caf will work on 3.1.2 but test.caf and test2.caf will not! This is the most crazy thing here...

Thanks in advance!
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #12
Ok, Seems like I finally got the clue. 3.1.2 requires .caf to be 11025hz. That's why some of the files were playing fine... they are 11025hz.

afconvert -d "BEI16@11025" test2.caf test2_cool.caf
fixes the problem for the test2.caf file included in the test project in the previous post.

Hope this helps anyone..
Regards,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #13
So is that it then? The files have to be 11025 Hz? That doesn't seem right either. I'd file a bug on that one.

I don't see anything in the code you posted which shouldn't work.
Quote this message in a reply
Member
Posts: 440
Joined: 2002.09
Post: #14
I've had no problems with 22050 or 44100 Hz but you seem to be using big endian sounds, and that can certainly be a problem. Use LEI16 when converting to raw PCM.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #15
Frank C. Wrote:I've had no problems with 22050 or 44100 Hz but you seem to be using big endian sounds, and that can certainly be a problem. Use LEI16 when converting to raw PCM.


That's interesting. Will give it a try, thanks. I just can't find a good reason for something what worked to just stop working... Kinda breaks backward compatibility.
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Post Reply