⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audiodev.cpp

📁 G.723在ARM上的实现。实现平台为Linux2.4.8+ Intel Xscal。包括源代码
💻 CPP
字号:
#include "audiodev.h"#include "mutexbuff.h"#include "goabl.h"#include "jrtplib/rtptimeutilities.h"#include <pthread.h>#include <iostream>using namespace std;extern int fd_wr;extern MutexBuff speechbuf;int  AudioDev::open_audiodev(int mode){		int mod;	int dev;		mod=mode;	switch(mod)	{		case MOD_RDONLY:			dev=open("/dev/dsp",O_RDONLY);					break;		case MOD_WRONLY:			dev=open("/dev/dsp",O_WRONLY);		break;		case MOD_RDWR:		dev=open("/dev/dsp",O_RDWR);		break;		fault:break;	}		if(dev==-1)	{		cout<<"open audiodev error!"<<endl;			exit(0);	}		return dev;	}void AudioDev::init_audiodev(int fd){	int arg;		arg=SIZE;	cout<<"init dev!"<<endl;	if(ioctl(fd,SOUND_PCM_WRITE_BITS,&arg)==-1)	{		cout<<"BITS ioctl error!"<<endl;	}	cout<<"size :"<<arg<<endl;		arg=CHANNELS;        if(ioctl(fd,SOUND_PCM_WRITE_CHANNELS,&arg)==-1)	{		cout<<"CHANNELS ioctl error!"<<endl;	}	cout<<"channels :"<<arg<<endl;		arg=RATE;	 if(ioctl(fd,SOUND_PCM_WRITE_RATE,&arg)==-1)	 {		 cout<<"RATE ioctl error!"<<endl;	 }	 cout<<"rate :"<<arg<<endl;	 }	void *AudioDev::voiceplay(void *){	int i=0;		unsigned char *tmp;	tmp=(unsigned char*)malloc(sizeof(unsigned char)*SPEECH);		while(1)	{		i=i%speechbuf.getframenum();		if(speechbuf.hasdata(i)==0)		{				cout<<"wait!"<<endl;			RTPTime::Wait(RTPTime(0,10)); //fixed delay play						}		if(speechbuf.hasdata(i)==0)		{				cout<<"wait,has no data"<<endl;										speechbuf.readbuff(i-1,tmp);								memset(tmp,0,SPEECH);		}				speechbuf.readbuff(i,tmp);		cout<<"write dsp"<<endl;		write(fd_wr,tmp,SPEECH);		i++;	}}void AudioDev::voiceplaythread_start(void){	pthread_t voiceplaythread;	pthread_create(&voiceplaythread,NULL,voiceplay,NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -