-
Notifications
You must be signed in to change notification settings - Fork 1
/
audiocap.cpp
executable file
·89 lines (72 loc) · 2.61 KB
/
audiocap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "audiocap.h"
#include "app.h"
#include <stdio.h>
#define SAMPLE_RATE (44100)
#define FRAMES_PER_BUFFER (1024)
#define NUM_CHANNELS (2)
#define PA_SAMPLE_TYPE paInt16
typedef short SAMPLE;
#define SAMPLE_SILENCE (0)
#define PRINTF_S_FORMAT "%d"
static int recordCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
AudioCap *pCap = (AudioCap *)userData;
pCap->waveCaptureProcess(inputBuffer,outputBuffer,framesPerBuffer,timeInfo,statusFlags);
return 0;
}
int AudioCap::waveCaptureProcess(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags)
{
/* Write recorded data to a file. */
//fwrite( inputBuffer, NUM_CHANNELS * sizeof(SAMPLE), framesPerBuffer, fid );
m_pApp->encodeAAC(inputBuffer, NUM_CHANNELS*sizeof(SAMPLE)*framesPerBuffer, (int64_t)timeInfo->currentTime);
}
AudioCap::AudioCap(int index, app *pApp)
{
m_index = index;
m_pApp = pApp;
PaError err = Pa_Initialize();
}
AudioCap::~AudioCap()
{
StopCap();
Pa_Terminate();
}
int AudioCap::StartCap()
{
PaStreamParameters inputParameters;
inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */
if (inputParameters.device == paNoDevice) {
fprintf(stderr,"Error: No default input device.\n");
return -1;
}
inputParameters.channelCount = 2; /* stereo input */
inputParameters.sampleFormat = PA_SAMPLE_TYPE;
inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency;
inputParameters.hostApiSpecificStreamInfo = NULL;
/* Record some audio. -------------------------------------------- */
PaError err = Pa_OpenStream(
&stream,
&inputParameters,
NULL, /* &outputParameters, */
SAMPLE_RATE,
FRAMES_PER_BUFFER,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
recordCallback,
this );
if( err != paNoError )
return -1;
err = Pa_StartStream( stream );
return err;
}
int AudioCap::StopCap()
{
PaError err = Pa_CloseStream( stream );
return err;
}