-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRtAudioCallbackFunction.h
35 lines (31 loc) · 1 KB
/
RtAudioCallbackFunction.h
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
#pragma once
#include <RtAudio.h>
#include "buffer.h"
#include "FIFO_Array.h"
ThreadSafeQ<buffer> fifo(441);
int readSpeakerLoopback(void* outputBuffer, void* inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void* data)
{
int numOfChannels = 2;
std::vector<float> copy;
for (int frame = 0; frame < nBufferFrames * numOfChannels; frame++) {
float sample = ((float*)inputBuffer)[frame];
copy.push_back(sample);
}
buffer input = buffer(copy);
fifo.push(input);
return false;
}
int playSpeakerSound(void* outputBuffer, void* inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void* data)
{
int numOfChannels = 2;
buffer output = buffer();
fifo.pop(output);
std::vector<float> temp = output.dataBuffer;
float* playback = (float*)outputBuffer;
for (int frame = 0; frame < nBufferFrames * numOfChannels; frame++) {
*playback++ = temp.at(frame);
}
return 0;
}