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
// Copyright (c) 2020 Günter Winau
// Copyright (c) 2020 Günter Windau
// based on the example in paex_sine.c
//
......@@ -65,6 +65,15 @@ int verbose = 1;
const int nrbuffers = 5;
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,
std::uint32_t _nchan)
: fsamp{_fsamp}, nsamp{_nsamp}, nchan{_nchan},
......@@ -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
don't bother clipping them */
zmq_audiobuffer::stream_callback, this);
if (err != paNoError)
return;
if (err != paNoError) {
print_error(err);
}
}
zmq_audiobuffer::~zmq_audiobuffer() {
......@@ -128,6 +138,7 @@ int zmq_audiobuffer::stream_callback(
ret = paComplete;
}
}
//std::cerr << "idata=" << data->idata << std::endl;
return ret;
}
......@@ -146,12 +157,17 @@ int zmq_audiobuffer::play() {
sprintf(message, "No Message");
int err =
Pa_SetStreamFinishedCallback(stream, &zmq_audiobuffer::stream_finished);
if (err != paNoError)
if (err != paNoError) {
print_error(err);
return err;
}
err = Pa_StartStream(stream);
if (err != paNoError)
if (err != paNoError) {
print_error(err);
return err;
}
playing = true;
// printf("Play for %d seconds.\n", NUM_SECONDS);
......@@ -190,15 +206,20 @@ int zmq_audiobuffer::fill(zmq::message_t &msg) {
return 0;
}
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;
void zmq_audiobuffer::dump(int nsamples)
{
std::cerr << "in void zmq_audiobuffer::dump(int nsamples):" << std::endl;
std::cerr << "fsamp=" << fsamp << std::endl;
std::cerr << "nsamp=" << nsamp << std::endl;
std::cerr << "nchan=" << nchan << std::endl;
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) {
int64_t more;
size_t more_size = sizeof more;
......@@ -295,17 +316,27 @@ int main(void) {
std::uint32_t nsamp = audio_header[2];
buffer[ibuf] = new zmq_audiobuffer(Fs, nsamp, nchan);
buffer[ibuf]->fill(msg[2]);
if (verbose)
buffer[ibuf]->dump(50);
}
else
buffer[ibuf]=nullptr;
}
else if (cmd == "AP") { // Play
if (buffer[ibuf])
buffer[ibuf]->play();
if (buffer[ibuf]) {
err=buffer[ibuf]->play();
if (err != paNoError) {
print_error(err);
return err;
}
}
}
else if (cmd == "AS") { // Stop
if (buffer[ibuf])
if (buffer[ibuf]) {
buffer[ibuf]->stop();
if (verbose)
buffer[ibuf]->dump(4);
}
}
delete[] audio_header;
......
......@@ -27,6 +27,8 @@ class zmq_audiobuffer {
return double(nsamp)/fsamp;
}
void dump(int nsamples);
protected:
bool playing;
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