Commit cc1b0dbc authored by Your Name's avatar Your Name
Browse files

zmqaudio_pa on raspi5

parent 3cbfb25f
#!/bin/bash
echo "running rc.raspi5"
run zmq_trigger_subscriber --zmq-proxy tcp://raspi6.local:5557
# these are for local testing
#run lsldert_proxy
#run zmq_trigger_subscriber --zmq-proxy tcp://raspi5.local:5557
#run zmqaudio_pa --zmq-proxy tcp://raspi5.local:5557
run zmqaudio_pa --zmq-proxy tcp://lsldert00.local:5557
#run zmq_trigger_subscriber --zmq-proxy tcp://lsldert00.local:5557
......@@ -27,7 +27,7 @@ msgqueue_pubsub: msgqueue_pubsub.cc
lsldert_proxy: lsldert_proxy.cc
lsldert_proxy: LDLIBS+=-lpthread
zmq_trigger_subscriber: zmq_trigger_subscriber.cc
zmqaudio_pa: LDLIBS=-lzmq
zmqaudio_pa: LDLIBS=-lzmq -lboost_program_options
zmqaudio_pa: zmqaudio_pa.cc zmqaudio_pa.h
zmqaudio: LDLIBS=-lzmq -lm -lasound -lportaudio
zmqaudio: zmqaudio.cc zmqaudio.h pcm_async.cc
......
No preview for this file type
No preview for this file type
......@@ -46,6 +46,11 @@
#include <math.h>
#include <stdio.h>
#include <sched.h>
#include <boost/program_options.hpp>
using namespace std;
using namespace boost;
#define NUM_SECONDS (5)
#define SAMPLE_RATE (44100)
......@@ -62,9 +67,11 @@ typedef struct {
char message[20];
} paTestData;
string proxy;
zmq_audiobuffer *zmq_audiobuffer::_playing_now = nullptr;
int verbose = 1;
int verbose = 0;
const int nrbuffers = 22;
zmq_audiobuffer *buffer[nrbuffers];
......@@ -83,7 +90,7 @@ zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp,
data{new float[_nsamp * _nchan]}, idata{0},
frames_per_buffer{paFramesPerBufferUnspecified}, playing{false}, stream{nullptr} {
assert(sizeof(float) == 4); // need 32 bit IEEE 754 floats
frames_per_buffer=64;
//frames_per_buffer=64;
}
zmq_audiobuffer::~zmq_audiobuffer() {
......@@ -101,7 +108,8 @@ int zmq_audiobuffer::stream_callback(
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo *,
PaStreamCallbackFlags, void *userData) {
std::cerr << "<callback>" << std::flush;
if (verbose)
std::cerr << "<callback>" << std::flush;
zmq_audiobuffer *pbuf = (zmq_audiobuffer *)userData;
float *out = (float *)outputBuffer;
unsigned long i;
......@@ -120,8 +128,10 @@ int zmq_audiobuffer::stream_callback(
//return ret;
}
}
std::cerr << "idata=" << pbuf->idata << " fpb=" << framesPerBuffer << " nsamp=" << pbuf->nsamp << std::flush;
std::cerr << "</callback>" << std::endl;
if (verbose) {
std::cerr << "idata=" << pbuf->idata << " fpb=" << framesPerBuffer << " nsamp=" << pbuf->nsamp << std::flush;
std::cerr << "</callback>" << std::endl;
}
return ret;
}
......@@ -143,7 +153,8 @@ int zmq_audiobuffer::play() {
<< std::endl;
p->stop();
}
std::cerr << "Start!" << std::endl;
if (verbose)
std::cerr << "Start!" << std::endl;
zmq_audiobuffer::_playing_now = this;
idata = 0;
......@@ -194,13 +205,15 @@ int zmq_audiobuffer::play() {
}
void zmq_audiobuffer::abort() {
std::cerr << "Abort!" << std::endl;
if (verbose)
std::cerr << "Abort!" << std::endl;
Pa_AbortStream(stream);
Pa_CloseStream(stream);
}
void zmq_audiobuffer::stop() {
std::cerr << "Stop!" << std::endl;
if (verbose)
std::cerr << "Stop!" << std::endl;
Pa_StopStream(stream);
Pa_CloseStream(stream);
Pa_Terminate();
......@@ -291,11 +304,45 @@ return 0;
return sched_setscheduler(0, sched_policy, &sched);
}
int main(void) {
void parse_options(int argc, const char *argv[]) {
namespace po = boost::program_options;
// Declare the supported options.
po::options_description desc("Usage:");
desc.add_options()("help,h", "show this message")(
"zmq-proxy,p", po::value<string>(), "select zmq pub-sub proxy host and port number, e.g. tcp://lsldert00.local:5557")(
"verbose,v","enable verbose output");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
exit(0);
}
if (vm.count("verbose")) {
verbose = 1;
}
if (vm.count("zmq-proxy"))
proxy = vm["zmq-proxy"].as<string>();
else
proxy = "";
if (verbose)
cout << "ZMQ proxy is: " << proxy << endl;
}
int main(int argc, const char *argv[]) {
int prio1 = 40;
int prio2 = 50;
parse_options(argc, argv);
rtpriority(prio2);
//PaError err = Pa_Initialize();
//if (err != paNoError)
......@@ -306,7 +353,7 @@ int main(void) {
zmq::context_t context(1);
zmq::socket_t ssub(context, ZMQ_SUB);
ssub.connect("tcp://raspi6.local:5557");
ssub.connect(proxy.c_str());
//ssub.connect("tcp://lsldert00.local:5557");
ssub.setsockopt(ZMQ_SUBSCRIBE, "A", 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment