发表于:2006-05-16 10:47:00
楼主
大家好,有个问题卡住了!急!
背景:使用9812采集卡作为AD连续采集数据(目前采集的是AM信号),基于PC做为信号处理机,处理后回放音频。使用vc编程实现实时软件无线电接收机。
问题:要连续采集数据并输出,每次采集一秒的数据,要保证每秒数据之间无信息丢失。以下是我做的程序,采集后用matlab解调观察,每秒数据之间有数据丢失,语音不连续。(解调方法肯定没问题!)
#define FRAMES 40
I16 *bk_buf1;
I16 *bk_buf2;
I16 *ai_buf;
long sample_rate=5000000;
I16 card = -1;
U32 access_cnt;
DWORD mem_size = 0;
static HANDLE hMem=NULL;
BOOL CShiyanDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
card=Register_Card(PCI_9812, 0);
if(card<0)
AfxMessageBox("Error Initialing Card!");
mem_size=data_size*2;
hMem = GlobalAlloc(GMEM_ZEROINIT,mem_size);
ai_buf = (short *)GlobalLock(hMem);
if (ai_buf == NULL )
AfxMessageBox("Not enough memory!");
GlobalFix(hMem);
bSampled=FALSE;
for(int i=0; i<FRAMES; i++)
{
bk_buf[i] = new I16[data_size/2];
if(bk_buf[i]==NULL)
AfxMessageBox("Error Alloc Memory for
StorageBuffer!");
}
bk_buf1=new I16[FRAMES*data_size/2];
bk_buf2=new I16[FRAMES*data_size/2];
return TRUE; // return TRUE unless you set the focus to a control
}
void lpRecvProc(LPVOID lpParam)
{
int err, i, j;
CString strTemp;
CString memcounter;
CString m_filepath;
LPCTSTR P;
CFileException Error;
CFile fs;
unsigned char bReady, bStop;
U32 count;
bSampled=FALSE;
err=AI_9812_Config(card,P9812_TRGMOD_SOFT, P9812_TRGSRC_CH0,
P9812_TRGSLP_POS,P9812_AD2_LT_PCI|P9812_CLKSRC_INT,0x80,0);
if(err<0)
{
strTemp.Format("AI_9812_Config Error! Code = %d.", err);
AfxMessageBox(strTemp);
}
bReady=0;
bStop=0;
i=0;
j=0;
AI_AsyncDblBufferMode(card, 1);
U16 channel=0;
AI_ContScanChannels (card, channel, AD_B_1_V,
(unsigned short *)ai_buf,data_size, (F64)sample_rate, ASYNCH_OP);
bool des=true;
while(1)
{
AI_ContStatus(card, &iFIFOSts[i]);
bReady=0;
while (!bReady && !bStop)
AI_AsyncDblBufferHalfReady(card, &bReady,
&bStop);
AI_AsyncDblBufferTransfer(card, (unsigned short *)