click sound on the first time when read audio file

edited October 2015

Hi, I am going to build a app that deal with many wav files (like 500 files in total).

I need very fast sound response so I set [frames = 128]

Here is my test code for that app

I used interface and implement the callback function. This wait until the flag=YES then start read data from the file

static OSStatus renderCallback(__unsafe_unretained SupportedChannel *THIS,
                               __unsafe_unretained AEAudioController *audioController,
                               const AudioTimeStamp *time,
                               UInt32 frames,
                               AudioBufferList *audio) {
    if (THIS->flag){
        [THIS readFrames:frames audioBufferList:audio];
    return noErr;

- (void)readFrames:(UInt32)frames audioBufferList:(AudioBufferList *)audioBufferList{
    if (audioFile) {
        // seek to the current frame index
        ExtAudioFileSeek(audioFile, _frameIndex);
        // do the read
        ExtAudioFileRead(audioFile, &frames, audioBufferList);
        _frameIndex += frames;

The problem is on the first time, or at the very first of the read, I heard the click sound . sometime during the play, it happens too, (but rarely).

I got this message: "TAAE: Warning: render took too long (0.002140s, should be less than 0.001451s). Expect glitches."

Can anyone help me solve this problem ?


  • Hi @sirenseavn,

    Oh, that's a big no-no: you're both calling Objective-C stuff and doing IO from the core audio thread. If you just need to play audio, use AEAudioFilePlayer, which handles it all for you.

  • Hi @Michael

    My app is kind of flute instrument app which handle notes(C D E G A B) as user press.
    Well, I need to handle like 30 notes at the same time.

    I also need audio transformation using my own method (that's why I need to access the callback for the audio transformation)

    I am thinking about using like 30 AEAudioFilePlayer, each player handle one note

    Is that design ok with the requirement ?

  • edited October 2015

    Hmm, no, I think you probably want the AUSampler for that sort of thing. Take a look at this.

    Generally speaking, for tasks this common, you don't need to reinvent the wheel - there are lots of facilities already built in to iOS which do this for you, and will almost always do it better than you (or I!) can. Before going to build something, always do a quick search around to see if it already exists, as it will save you enormous amounts of time and pain.

Sign In or Register to comment.