Examples : Record audio files with FFmpeg
Play an audio file with CIOS Audio Core is extremely easy, you need only one line of code.bool MediaRecord (char * filename ,
int milliseconds = 60000 ,
int samplerate = 44100 ,
int channels = 1 ,
int inputDevice = -1 ,
int encodeDevice = -1 ,
int latency = 500 ,
Debugger * debugger = NULL ) ;
#include "CiosAudio.hpp"
int main(int argc,char * argv[])
{
if (argc<2) return 0 ;
CiosAudio::MediaRecord(argv[1]) ;
return 1 ;
}
MediaRecord parameters
Parameter |
Explain |
filename |
Audio file name |
milliseconds |
Recording time (ms). If it is less or equal to 0, the recording will go on indefinitely, until user's program interrupt it from outside. |
samplerate |
Sampling rate |
channels |
Audio channels |
inputDevice |
Audio Device ID. It must be a real MIC or network audio input device. |
encodeDevice |
Encoder Device ID. It must be a encoder device 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 Recorder(int argc,char ** argv)
{
int ms = 60000 ;
int id = -1 ;
int od = -1 ;
int i = 2 ;
int samplerate = 8000 ;
int channels = 1 ;
int latency = 500 ;
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++ ;
} else {
char * filename = argv [ i ] ;
i++ ;
MediaRecord(filename,ms,samplerate,channels,id,od,latency,debugger) ;
} ;
} ;
////////////////////////////////////////////////////////////////////////////
if ( NULL != debugger ) delete debugger ;
////////////////////////////////////////////////////////////////////////////
return 1 ;
}