Playing several audio files at precise same time

What is the best way yo play several AEAudioFilePlayer players simultaneously - at precise same time? Something like AVAudioPlayer playAtTime method.

Thank you very much.

Regards, Grega

Comments

  • Atomic updates like that is still a work in progress, I'm afraid, Grega. If you're not doing anything else with the engine at the time of playback, you could stop the engine, add each of the players, then start it to have everything come in at the same time.

  • Hi,

    sorry for late reply. Wow that is great, thanks!

    Regards,
    Grega

  • I have just tested this and it does not work as expected. For example i am playing 10 audio files at the same time. Sometimes it works, sometimes it does not and you can here a little delay (like a chorus effect). Maybe i am doing something wrong: i am using Apple's AVAudioPlayer deviceCurrentTime property to get the audio system time,then i add 0.2 seconds to that time and use it with AEAudioPlayer playAtTime method.

    Regards,
    Grega

  • The delay you mention, is that a delay between files all played with AEAudioFilePlayer, or between AEAudioFilePlayer and AVAudioPlayer/etc?

  • Between files all played with AEAudioFilePlayer. Once you move to TAAE you don't need AVAudioPlayer anymore. :)))

  • edited October 2015

    Hmm, I see! Would you share some code? I'm trying to reproduce this on my end with the following:

    <

    pre lang="objc">
    uint64_t startTime = AECurrentTimeInHostTicks() + AEHostTicksFromSeconds(2.0);
    for ( int i=0; i<10; i++ ) {
    AEAudioFilePlayer * loop = [AEAudioFilePlayer audioFilePlayerWithURL:[[NSBundle mainBundle] URLForResource:@Southern Rock Drums withExtension:@m4a] error:NULL];
    loop.loop = YES;
    [loop playAtTime:startTime];
    [_audioController addChannels:@[loop]];
    }

    It seems to sound fine to me (just like one really loud loop)

  • edited October 2015

    I do it like this:

    AEAudioFilePlayer * loop1 = [AEAudioFilePlayer audioFilePlayerWithURL:url1 error:NULL];
    AEAudioFilePlayer * loop2 = [AEAudioFilePlayer audioFilePlayerWithURL:url2 error:NULL];
    AEAudioFilePlayer * loop3 = [AEAudioFilePlayer audioFilePlayerWithURL:url3 error:NULL];
    AEAudioFilePlayer * loop4 = [AEAudioFilePlayer audioFilePlayerWithURL:url4 error:NULL];
    
    [_audioController addChannels:@[loop1]];
    [_audioController addChannels:@[loop2]];
    [_audioController addChannels:@[loop3]];
    [_audioController addChannels:@[loop4]];
    
    uint64_t startTime = AECurrentTimeInHostTicks() + AEHostTicksFromSeconds(0.2);
    
    [loop1 playAtTime:startTime];
    [loop2 playAtTime:startTime];
    [loop3 playAtTime:startTime];
    [loop4 playAtTime:startTime];
    

    Is it wrong to add channels to audio controller before play or playAtTime?

    Regards,
    Grega

  • Ah, yes, that might be it: once you add the channels, unless you set channelIsPlaying to NO first, they'll begin playing. You want to change the order there.

  • Tried that and got the same result. Still not precise enough. Any other ideas? Thanks.

  • Having trouble reproducing this on my end; can you modify the TAAE sample app to reproduce and send me a diff?

  • OK, thank you. Will send you when ready.

  • edited October 2015

    Hi again,

    i have managed to make it work. I have changed sync time from AVAudioPlayer deviceCurrentTime to match your example: uint64_t startTime = AECurrentTimeInHostTicks() + AEHostTicksFromSeconds(2.0); and after that channels are synced ok. Thank you for your time.

    Regards,
    Grega

  • Okay, cool =)

Sign In or Register to comment.