Audio编程中的一些

adts 头部中 audioObjectType 5bits  0001 0
samplingFrequencyIndex 4bits 
0x3 48000
0x4 44100 
0x5 32000 
0x6 24000 
0x7 22050 
0x8 16000 
0x9 12000 
0xa 11025 
0xb 8000 

channelConfiguration 4bits


测试时候可以 用一下方法填充AudioBufferData

[audio buffer make]
long length = 4*1024;
audioData_ = malloc(length);
void *pDst = AudioBufferData;
memset(pDst, 0, 0); // 1kHz tone
double Radian1kHzAcc = 0.0;
const double Radian1kHzInc = 2.0 * 3.1415926535 * 1000.0 / 44100;
int FrameRate = 25;
unsigned SampleCount = 0;
int nChannels = 2;
switch (FrameRate)
{
case 23: 
SampleCount = 2002;break;
	
case 24:
 SampleCount = 2000; break;
	
case 25: 
SampleCount = 1920; break;
	
case 29: 
SampleCount = 1602; break;
	
case 30:
 SampleCount = 1600; break;
	
case 50:
 SampleCount = 960; break;
	
case 59: 
SampleCount = 800; break;
	
case 60: 
SampleCount = 800; break;
}
SampleCount = (length)/4;// 1kHz burst for one frame
short* pData = (short*)pDst;
short Data;
for (unsigned Sample=0; Sample<SampleCount; ++Sample, Radian1kHzAcc+=Radian1kHzInc)
{
Data = (short)(sin(Radian1kHzAcc) * (double)0x6FFF);
for (unsigned channel=0; channel<nChannels; ++channel)
{	
*pData++ = Data;
	
}


}






static void fill_audio_buffer(unsigned char* buf, size_t len)
{
	memset(buf, 0, len); // 1kHz tone
	double Radian1kHzAcc = 0.0;
	static const double Radian1kHzInc = 1.0 * 3.1415926535 * 1000.0 / 8000;
	
	int FrameRate = 25;
	unsigned SampleCount = 0;
	int nChannels = 1;
	switch (FrameRate)
	{		
	case 23: 
		SampleCount = 2002;break;		
	case 24: 
		SampleCount = 2000; break;
		
	case 25: 
		SampleCount = 1920; break;
		
	case 29: 
		SampleCount = 1602; break;
		
	case 30: 
		SampleCount = 1600; break;
		
	case 50: 
		SampleCount = 960; break;
		
	case 59: 
		SampleCount = 800; break;
		
	case 60: 
		SampleCount = 800; break;
		
	}
	
	SampleCount = len/4;// 1kHz burst for one frame
	
	short* pData = (short*)buf;
	short Data;
	for (unsigned Sample=0; Sample<SampleCount; ++Sample, Radian1kHzAcc+=Radian1kHzInc)
	{
		
		Data = (short)(sin(Radian1kHzAcc) * (double)0x6FFF);
		for (int channel = 0; channel<nChannels; ++channel)		
		{		
			*pData++ = Data;		
		}	
	}
}


你可能感兴趣的:(Audio编程中的一些)