iPhone/iPad開發札記2012/03/12 Audio Unit


1. MixerHost 


* AudioBufferList 

Declaration: struct AudioBufferList {

   UInt32      mNumberBuffers;

   AudioBuffer mBuffers[1];

};

Q:WHY AudioBuffer[1]? WHY NOT AudioBuffer *? seems the same ?

注:參見此文對指針與數據區別的分析:http://wenku.baidu.com/view/93fc57202f60ddccda38a0b5.html

mBuffers只是標明一個buffer array的起始地址,具體空間大小由mNumberBuffers決定。


另外,在本程序裏,mNumberBuffers爲1/2,分別表示mono/stereo,而每個buffer本身只有一個channel


* AudioBuffer 

struct AudioBuffer {
   UInt32 mNumberChannels;
   UInt32 mDataByteSize;
   void   *mData;
};
typedef struct AudioBuffer AudioBuffer;

Q:  跟蹤發現,mNumberChannels總是1,什麼原因?是否因爲right channel的data在另一個buffer中?和interleaved及non-interleaved之間有什麼關係?

   A: 此struct用於多種場景,某些情況下在一個buffer中會有多個channel的數據,有些情況下只有一個channel的數據。與AudioBufferList配合使用。


* InputRenderCallback()

//    Audio unit input render callbacks are invoked on a realtime priority thread (the highest 

//    priority on the system). To work well, to not make the system unresponsive, and to avoid 

//    audio artifacts, a render callback must not:

//

//        * allocate memory

//        * access the file system or a network connection

//        * take locks

//        * waste time

//

//    In addition, it's usually best to avoid sending Objective-C messages in a render callback.

//


2. My own Audio Unit code in conference project 

* inside InputRenderCallback()


// get audio data from audio engine 

readAudioData(buffer, length)           // length should be 1280=320*4 bytes 

// fill the buffer handed to me 

    // Fill the buffer or buffers pointed at by *ioData with the requested number of samples 

   //    of audio from the sound stored in memory.

    for (UInt32 frameNumber = 0; frameNumber < inNumberFrames; ++frameNumber) {

        outSamplesChannelLeft[frameNumber]                 = dataInLeft[sampleNumber];

    }



3. 調試Conference程序使用G711

* playback 

errors as follows: 


(gdb) continue

2012-03-12 18:03:26.217 test555[1369:207] AQBufferCallback...

2012-03-12 18:03:27.395 test555[1369:207] audio data ready

2012-03-12 18:03:27.395 test555[1369:207] AQBufferCallback...

[Switching to process 1369]

Program received signal:  “EXC_BAD_ACCESS”.


other erros: 


2012-03-12 18:16:03.056 test555[1475:207] AQBufferCallback...

mi_cmd_exec_interrupt: Inferior not executing.

mi_cmd_exec_interrupt: Inferior not executing.

(gdb) continue

(gdb) continue

2012-03-12 18:16:03.976 test555[1475:207] audio data ready

test555(1475,0xb024f000) malloc: *** error for object 0x551bde4: incorrect checksum for freed object - object was probably modified after being freed.

*** set a breakpoint in malloc_error_break to debug

Program received signal:  “SIGABRT”.

(gdb) continue

Program received signal:  “SIGABRT”.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章