Commit 7a633ceb authored by Your Name's avatar Your Name
Browse files

more zmqaudio debugging

parent 74aece1e
No preview for this file type
// //
// zmqaudio.cc -- play audio samples received over zeromq sockets // zmqaudio.cc -- play audio samples received over zeromq sockets
// Copyright (c) 2020 Günter Winau // Copyright (c) 2020 Günter Windau
// based on the example in paex_sine.c // based on the example in paex_sine.c
// //
...@@ -65,6 +65,15 @@ int verbose = 1; ...@@ -65,6 +65,15 @@ int verbose = 1;
const int nrbuffers = 5; const int nrbuffers = 5;
zmq_audiobuffer *buffer[nrbuffers]; zmq_audiobuffer *buffer[nrbuffers];
PaError print_error(PaError e) {
if (e != paNoError)
Pa_Terminate();
fprintf(stderr, "An error occured while using the portaudio stream\n");
fprintf(stderr, "Error number: %d\n", e);
fprintf(stderr, "Error message: %s\n", Pa_GetErrorText(e));
return e;
}
zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp, zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp,
std::uint32_t _nchan) std::uint32_t _nchan)
: fsamp{_fsamp}, nsamp{_nsamp}, nchan{_nchan}, : fsamp{_fsamp}, nsamp{_nsamp}, nchan{_nchan},
...@@ -91,8 +100,9 @@ zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp, ...@@ -91,8 +100,9 @@ zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp,
paClipOff, /* we won't output out of range samples so paClipOff, /* we won't output out of range samples so
don't bother clipping them */ don't bother clipping them */
zmq_audiobuffer::stream_callback, this); zmq_audiobuffer::stream_callback, this);
if (err != paNoError) if (err != paNoError) {
return; print_error(err);
}
} }
zmq_audiobuffer::~zmq_audiobuffer() { zmq_audiobuffer::~zmq_audiobuffer() {
...@@ -128,6 +138,7 @@ int zmq_audiobuffer::stream_callback( ...@@ -128,6 +138,7 @@ int zmq_audiobuffer::stream_callback(
ret = paComplete; ret = paComplete;
} }
} }
//std::cerr << "idata=" << data->idata << std::endl;
return ret; return ret;
} }
...@@ -146,12 +157,17 @@ int zmq_audiobuffer::play() { ...@@ -146,12 +157,17 @@ int zmq_audiobuffer::play() {
sprintf(message, "No Message"); sprintf(message, "No Message");
int err = int err =
Pa_SetStreamFinishedCallback(stream, &zmq_audiobuffer::stream_finished); Pa_SetStreamFinishedCallback(stream, &zmq_audiobuffer::stream_finished);
if (err != paNoError) if (err != paNoError) {
print_error(err);
return err; return err;
}
err = Pa_StartStream(stream); err = Pa_StartStream(stream);
if (err != paNoError) if (err != paNoError) {
print_error(err);
return err; return err;
}
playing = true; playing = true;
// printf("Play for %d seconds.\n", NUM_SECONDS); // printf("Play for %d seconds.\n", NUM_SECONDS);
...@@ -190,15 +206,20 @@ int zmq_audiobuffer::fill(zmq::message_t &msg) { ...@@ -190,15 +206,20 @@ int zmq_audiobuffer::fill(zmq::message_t &msg) {
return 0; return 0;
} }
PaError print_error(PaError e) { void zmq_audiobuffer::dump(int nsamples)
if (e != paNoError) {
Pa_Terminate(); std::cerr << "in void zmq_audiobuffer::dump(int nsamples):" << std::endl;
fprintf(stderr, "An error occured while using the portaudio stream\n"); std::cerr << "fsamp=" << fsamp << std::endl;
fprintf(stderr, "Error number: %d\n", e); std::cerr << "nsamp=" << nsamp << std::endl;
fprintf(stderr, "Error message: %s\n", Pa_GetErrorText(e)); std::cerr << "nchan=" << nchan << std::endl;
return e; std::cerr << "frames_per_buffer=" << frames_per_buffer << std::endl;
std::cerr << "idata=" << idata << std::endl;
for (int i=0; i<nsamples; i++) {
std::cerr << "data[" << i << "]=" << data[i] << std::endl;
}
} }
int zmq_recv_multi(zmq::socket_t &socket, zmq::message_t parts[], int nmax) { int zmq_recv_multi(zmq::socket_t &socket, zmq::message_t parts[], int nmax) {
int64_t more; int64_t more;
size_t more_size = sizeof more; size_t more_size = sizeof more;
...@@ -295,17 +316,27 @@ int main(void) { ...@@ -295,17 +316,27 @@ int main(void) {
std::uint32_t nsamp = audio_header[2]; std::uint32_t nsamp = audio_header[2];
buffer[ibuf] = new zmq_audiobuffer(Fs, nsamp, nchan); buffer[ibuf] = new zmq_audiobuffer(Fs, nsamp, nchan);
buffer[ibuf]->fill(msg[2]); buffer[ibuf]->fill(msg[2]);
if (verbose)
buffer[ibuf]->dump(50);
} }
else else
buffer[ibuf]=nullptr; buffer[ibuf]=nullptr;
} }
else if (cmd == "AP") { // Play else if (cmd == "AP") { // Play
if (buffer[ibuf]) if (buffer[ibuf]) {
buffer[ibuf]->play(); err=buffer[ibuf]->play();
if (err != paNoError) {
print_error(err);
return err;
}
}
} }
else if (cmd == "AS") { // Stop else if (cmd == "AS") { // Stop
if (buffer[ibuf]) if (buffer[ibuf]) {
buffer[ibuf]->stop(); buffer[ibuf]->stop();
if (verbose)
buffer[ibuf]->dump(4);
}
} }
delete[] audio_header; delete[] audio_header;
......
...@@ -27,6 +27,8 @@ class zmq_audiobuffer { ...@@ -27,6 +27,8 @@ class zmq_audiobuffer {
return double(nsamp)/fsamp; return double(nsamp)/fsamp;
} }
void dump(int nsamples);
protected: protected:
bool playing; bool playing;
PaStream *stream; PaStream *stream;
......
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