views:

698

answers:

2

Hello,

I am playing MP3 audio form a network stream and sometimes gaps are present when using WIFI connection.

I decrease the buffer size, but I am wondering what is the best method for calculating buffer size.

My MP3 stream is 64 Kbits.

I am using 3 buffers, for 64 *1024 each. PacketDescriptions is 512

Thanks a lot

Thierry

A: 

I found the answer!

Best values for me are :

Number of buffers 3 Buffer size 32 * 768 Max packets description 4096

thierryb
A: 

Hi, I'm doing the AAC stream playing internet.I want to know how should i do it.Now,I can get the data from the net.Then I parse it,but wrong! There is a wrong message to me. kAudioFileStreamError_NotOptimized. What can I do?The same code can play the MP3 stream.But the AAC stream couldn't play.Why?

void IRPacketCallback(void *in, UInt32 inNumberBytes, UInt32 inNumberPackets, const void *inInputData, AudioStreamPacketDescription *inPacketDescriptions) { NSLog(@"packet 解析"); //NSLog(@"%@",[NSString stringWithFormat:@"%@",inInputData]); CInteractiveRadio *radio = stcast_(in); AudioQueueBufferRef buf;

OSStatus error = AudioQueueAllocateBufferWithPacketDescriptions(radio.queue, inNumberBytes, 
                                                                inNumberPackets, &buf);
if(error) 
{
    NSLog(@"Unable to allocate buffer, discarding packet");
} 
else
{
    buf->mAudioDataByteSize = inNumberBytes;
    memcpy(buf->mAudioData, inInputData, inNumberBytes);
    AudioQueueEnqueueBuffer(radio.queue, buf, inNumberPackets, inPacketDescriptions);
    radio.audioBufferDataSize = radio.audioBufferDataSize + inNumberBytes;
    [radio BufferEnqueued];
}

}

void IRPropertyCallback(void *in,AudioFileStreamID inAudioFileStream,AudioFileStreamPropertyID inPropertyID, UInt32 *ioFlags) { NSLog(@"property 解析"); NSLog(@"inPropertyID %x",inPropertyID); CInteractiveRadio *radio = stcast_(in); AudioStreamBasicDescription dataFormat; AudioQueueRef queue;

if (inPropertyID == kAudioFileStreamProperty_FileFormat)
{
    NSLog(@"kAudioFileStreamProperty_FileFormat");
    UInt32 fileFormatSize;
    UInt32 fileFormatValue;
    AudioFileStreamGetProperty(inAudioFileStream, inPropertyID, &fileFormatSize, &fileFormatValue);
    //fileFormatValue = 0;
    //AudioFileStreamSetProperty(inAudioFileStream, inPropertyID, fileFormatSize, &fileFormatValue);
    NSLog(@"FileFormat %x = %x",inPropertyID,fileFormatValue);
}

switch(inPropertyID) 
{
    case kAudioFileStreamProperty_DataFormat:
    {
        NSLog(@"Got data format\n");
        UInt32 len = sizeof(dataFormat);
        AudioFileStreamGetProperty(inAudioFileStream, inPropertyID, &len, &dataFormat);
        radio.dataFormat = dataFormat;
    }
        break;

    case kAudioFileStreamProperty_ReadyToProducePackets:
    {
        NSLog(@"Ready to produce packets");
        dataFormat = radio.dataFormat;
        OSStatus error = AudioQueueNewOutput(&dataFormat, OutputCallback, radio, NULL, 
                                             kCFRunLoopCommonModes, 0, &queue);

        if(error) 
        {
            NSLog(@"Unable to create audio queue!\n");
        } 
        else 
        {
            radio.queue = queue;
        }

        [radio Play];
    }
        break;
}

}