Examples : Audio streaming redirect
Audio streaming redirection is two different audio devices, redirect audio input device into audio output device. It is suggested that the distance of MIC and speaker keep a certain distance. Otherwise, a strong echo gain will occur.If you want to use redirect function, you will have to add DEFINEs in your C++ CXXFLAGS compiler flags:
CAUTILITIES
- C++ compiler : -DCAUTILITIES
- Qt:DEFINES += CAUTILITIES
Function
bool Redirect (int milliseconds = -1 ,
int samplerate = 44100 ,
int channels = 1 ,
int inputDevice = -1 ,
int outputDevice = -1 ,
int latency = 10 ,
Debugger * debugger = NULL ) ;
Parameters
Parameter |
Explain |
milliseconds | Redirection time (ms), stop after milliseconds. If it is less or equal to 0, the redirection will go on indefinitely, until user's program interrupt it from outside. |
samplerate |
Sampling rate |
channels |
Audio channels. Not all channel numbers are supported. |
inputDevice |
Audio Device ID. It must be a real MIC or network audio input device. |
outputDevice |
Audio Device ID. It must be a real speaker or network audio output device. |
latency |
The latency from input to output. Basically audio input streaming first comes into buffer, and then from buffer into audio output device, then play it. This parameter set up interval of the audio input device starting point and the audio output device starting point. |
debugger |
Debugger classs. If a normal user does not want to debug, just give NULL as parameter. |
Example in CaPlay.cpp
int Diversion(int argc,char ** argv)
{
int ms = -1 ;
int id = -1 ;
int od = -1 ;
int i = 2 ;
int samplerate = 8000 ;
int channels = 1 ;
int latency = 10 ;
Debugger * debugger = NULL ;
////////////////////////////////////////////////////////////////////////////
while ( i < argc ) {
if ( 0 == strcmp(argv[i],"--time") ) {
i++ ;
ms = atoi(argv[i]) ;
i++ ;
} else
if ( 0 == strcmp(argv[i],"--samplerate") ) {
i++ ;
samplerate = atoi(argv[i]) ;
i++ ;
} else
if ( 0 == strcmp(argv[i],"--channels") ) {
i++ ;
channels = atoi(argv[i]) ;
i++ ;
} else
if ( 0 == strcmp(argv[i],"--latency") ) {
i++ ;
latency = atoi(argv[i]) ;
i++ ;
} else
if ( 0 == strcmp(argv[i],"--output") ) {
i++ ;
od = atoi(argv[i]) ;
i++ ;
} else
if ( 0 == strcmp(argv[i],"--input") ) {
i++ ;
id = atoi(argv[i]) ;
i++ ;
} else
if ( 0 == strcmp(argv[i],"--debug" ) ) {
if ( NULL == debugger ) {
debugger = new Debugger ( ) ;
} ;
i++ ;
} ;
i++ ;
} ;
////////////////////////////////////////////////////////////////////////////
if (Redirect(ms,samplerate,channels,id,od,latency,debugger)) {
if ( NULL != debugger ) delete debugger ;
return 1 ;
} ;
if ( NULL != debugger ) delete debugger ;
////////////////////////////////////////////////////////////////////////////
return 0 ;
}