Commit 9d50a779 authored by Your Name's avatar Your Name
Browse files

more zmqaudio debugging

parent 7a633ceb
No preview for this file type
......@@ -78,7 +78,7 @@ zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp,
std::uint32_t _nchan)
: fsamp{_fsamp}, nsamp{_nsamp}, nchan{_nchan},
data{new float[_nsamp * _nchan]}, idata{0},
frames_per_buffer{64}, playing{false}, stream{nullptr} {
frames_per_buffer{paFramesPerBufferUnspecified}, playing{false}, stream{nullptr} {
assert(sizeof(float) == 4); // need 32 bit IEEE 754 floats
PaStreamParameters outputParameters;
outputParameters.device =
......@@ -116,21 +116,21 @@ zmq_audiobuffer::~zmq_audiobuffer() {
** that could mess up the system like calling malloc() or free().
*/
int zmq_audiobuffer::stream_callback(
const void * /*inputBuffer*/, void *outputBuffer,
const void *, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo * /*timeInfo*/,
PaStreamCallbackFlags /*statusFlags*/, void *userData) {
const PaStreamCallbackTimeInfo *,
PaStreamCallbackFlags, void *userData) {
zmq_audiobuffer *data = (zmq_audiobuffer *)userData;
zmq_audiobuffer *pbuf = (zmq_audiobuffer *)userData;
float *out = (float *)outputBuffer;
unsigned long i;
int ret = paContinue;
for (i = 0; i < framesPerBuffer; i++) {
if (data->idata < data->nsamp) {
*out++ = data->data[2 * (data->idata)]; // left
*out++ = data->data[2 * (data->idata) + 1]; // right
data->idata++;
if (pbuf->idata < pbuf->nsamp) {
*out++ = pbuf->data[2 * (pbuf->idata)]; // left
*out++ = pbuf->data[2 * (pbuf->idata) + 1]; // right
pbuf->idata++;
}
else {
*out++ = 0;
......@@ -138,7 +138,7 @@ int zmq_audiobuffer::stream_callback(
ret = paComplete;
}
}
//std::cerr << "idata=" << data->idata << std::endl;
std::cerr << "idata=" << pbuf->idata << " fpb=" << framesPerBuffer << std::endl;
return ret;
}
......@@ -146,9 +146,9 @@ int zmq_audiobuffer::stream_callback(
* This routine is called by portaudio when playback is done.
*/
void zmq_audiobuffer::stream_finished(void *userData) {
zmq_audiobuffer *data = (zmq_audiobuffer *)userData;
data->playing = false;
printf("Stream Completed: %s\n", data->message);
zmq_audiobuffer *pbuf = (zmq_audiobuffer *)userData;
pbuf->playing = false;
printf("Stream Completed: %s\n", pbuf->message);
}
int zmq_audiobuffer::play() {
......@@ -170,8 +170,8 @@ int zmq_audiobuffer::play() {
playing = true;
// printf("Play for %d seconds.\n", NUM_SECONDS);
// Pa_Sleep((unsigned int)(duration() * 1000));
//printf("Play for %d seconds.\n", NUM_SECONDS);
//Pa_Sleep((unsigned int)(duration() * 1000));
return paNoError;
}
......@@ -264,6 +264,9 @@ int main(void) {
// ssub.connect("tcp://lsldert00.local:5557");
ssub.setsockopt(ZMQ_SUBSCRIBE, "A", 1);
buffer[0] = new zmq_audiobuffer(44100, 5 * 48000, 2);
buffer[0]->fill();
int run = 1;
while (run) {
const int maxmsg = 3;
......@@ -275,12 +278,9 @@ int main(void) {
std::string str((char *)request.data());
std::uint32_t *audio_header = nullptr;
//float *audio_data = nullptr;
if (nmsg > 2) {
audio_header = new std::uint32_t[msg[1].size()/sizeof(std::uint32_t)];
//audio_data = new float[msg[2].size()/sizeof(float)];
std::memcpy(audio_header, msg[1].data(), msg[1].size());
//std::memcpy(audio_data, msg[2].data(), msg[2].size());
}
if (verbose) {
......
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