-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioProcessing.cpp
More file actions
68 lines (58 loc) · 1.52 KB
/
AudioProcessing.cpp
File metadata and controls
68 lines (58 loc) · 1.52 KB
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
#include "RtAudio.h"
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "AudioProcessing.h"
MY_TYPE *Buffer;
double *newBuffer;
int record( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *userData )
{
if ( status )
std::cout << "Stream overflow detected!" << std::endl;
// Do something with the data in the "inputBuffer" buffer.
// std::cout << "WTF" << std::endl;
Buffer = (signed short *)inputBuffer;
for(unsigned int i = 0; i < FRAMES; i++) {
newBuffer[i] = abs(Buffer[i]);
newBuffer[i]/=MAX_VAL;
// std::cout << "newbuf: " << newBuffer[i] << std::endl;
}
return 0;
}
int audioFn() {
if ( adc.getDeviceCount() < 1 ) {
std::cout << "\nNo audio devices found!\n";
exit( 0 );
}
RtAudio::StreamParameters parameters;
parameters.deviceId = adc.getDefaultInputDevice();
parameters.nChannels = 1;
parameters.firstChannel = 0;
unsigned int sampleRate = SAMPLE_RATE;
unsigned int bufferFrames = FRAMES;
newBuffer = (double *)malloc(sizeof(double) * FRAMES);
try {
adc.openStream( NULL, ¶meters, RTAUDIO_SINT16,
sampleRate, &bufferFrames, &record);
adc.startStream();
}
catch ( RtError& e ) {
e.printMessage();
exit( 0 );
}
std::cout << "\nAnalyzing...\n";
return 0;
}
int exitFn()
{
try {
// Stop the stream
adc.stopStream();
}
catch (RtError& e) {
e.printMessage();
}
if ( adc.isStreamOpen() ) adc.closeStream();
return 0;
}