current version.. forgot to commit
This commit is contained in:
62
pa/main.cpp
Executable file
62
pa/main.cpp
Executable file
@@ -0,0 +1,62 @@
|
||||
#include "pulseaudio.h"
|
||||
|
||||
#include "../lib/BeatDetection2.h"
|
||||
|
||||
#include "../lib/Socket.h"
|
||||
SocketUDP sck;
|
||||
|
||||
void sendUDP(const std::string& msg) {
|
||||
NetworkAddress destination("127.0.0.1", 5050);
|
||||
sck.sendDatagram(msg, destination);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
sck.bind(5051);
|
||||
sendUDP("starting");
|
||||
|
||||
// sanity check
|
||||
if (argc != 2) {
|
||||
std::cout << "usage: paBeatRecorder [pa_deviceName]" << std::endl;
|
||||
std::cout << "e.g. paBeatRecorder alsa_output.pci-0000_00_1b.0.analog-stereo.monitor" << std::endl;
|
||||
std::cout << "list devices with: pactl list | grep '\\.monitor'" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get the to-be-used device name
|
||||
std::string devName = argv[1];
|
||||
|
||||
PulseAudio pa(devName);
|
||||
//pa.join();
|
||||
|
||||
int16_t buf[1024];
|
||||
|
||||
BeatDetection2<float> bestBass(Mode::BASS);
|
||||
BeatDetection2<float> beatSnare(Mode::SNARE);
|
||||
|
||||
while(true) {
|
||||
|
||||
pa.read(buf, 1024);
|
||||
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
const float left = buf[i];
|
||||
const float right = buf[i];
|
||||
|
||||
const bool bBass = bestBass.add(left, right);
|
||||
if (bBass) {
|
||||
std::cout << "bass\n" << std::flush;
|
||||
sendUDP("bass");
|
||||
}
|
||||
|
||||
const bool bSnare = beatSnare.add(left, right);
|
||||
if (bSnare) {
|
||||
std::cout << "snare...\n" << std::flush;
|
||||
sendUDP("snare");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user