Commit 628ce6c7 authored by Your Name's avatar Your Name
Browse files

more zmqaudio

parent 613fd9c0
...@@ -10,8 +10,7 @@ LDLIBS+=-lzmq -lboost_program_options -lpigpio -llsl32 ...@@ -10,8 +10,7 @@ LDLIBS+=-lzmq -lboost_program_options -lpigpio -llsl32
#INCLUDE+=RS-232 #INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11 CXXFLAGS+=-Wall -std=c++11
all: zmq_trigger playtone msgqueue_pubsub lsldert_proxy zmq_trigger_subscriber playsound lsldertc hwserver hwserver2 hwserver3 all: zmq_trigger playtone msgqueue_pubsub lsldert_proxy zmq_trigger_subscriber playsound lsldertc hwserver hwserver2 hwserver3 zmqaudio
develop: zmqaudio
lsldertc: lsldertc.c lsldertc: lsldertc.c
hwserver: hwserver.c hwserver: hwserver.c
......
No preview for this file type
...@@ -96,7 +96,7 @@ zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp, ...@@ -96,7 +96,7 @@ zmq_audiobuffer::zmq_audiobuffer(std::uint32_t _fsamp, std::uint32_t _nsamp,
} }
zmq_audiobuffer::~zmq_audiobuffer() { zmq_audiobuffer::~zmq_audiobuffer() {
delete data; delete[] data;
Pa_StopStream(stream); Pa_StopStream(stream);
Pa_CloseStream(stream); Pa_CloseStream(stream);
} }
...@@ -163,7 +163,7 @@ void zmq_audiobuffer::abort() { Pa_AbortStream(stream); } ...@@ -163,7 +163,7 @@ void zmq_audiobuffer::abort() { Pa_AbortStream(stream); }
void zmq_audiobuffer::stop() { Pa_StopStream(stream); } void zmq_audiobuffer::stop() { Pa_StopStream(stream); }
void zmq_audiobuffer::fill() { int zmq_audiobuffer::fill() {
// initialise sinusoidal wavetable // initialise sinusoidal wavetable
const float fl{440}; const float fl{440};
const float fr{880}; const float fr{880};
...@@ -172,6 +172,19 @@ void zmq_audiobuffer::fill() { ...@@ -172,6 +172,19 @@ void zmq_audiobuffer::fill() {
data[2 * i] = vol * sin((2 * M_PI * fl * i) / fsamp); data[2 * i] = vol * sin((2 * M_PI * fl * i) / fsamp);
data[2 * i + 1] = vol * sin((2 * M_PI * fr * i) / fsamp); data[2 * i + 1] = vol * sin((2 * M_PI * fr * i) / fsamp);
} }
return 0;
}
int zmq_audiobuffer::fill(zmq::message_t &msg) {
uint32_t ndata = msg.size()/sizeof(float);
if (ndata != (nsamp*nchan)) {
std::cerr <<
"in int zmq_audiobuffer::fill(zmq::message_t &msg): audio data size mismatch" <<
std::endl;
return 1;
}
std::memcpy(data, msg.data(), msg.size());
return 0;
} }
PaError print_error(PaError e) { PaError print_error(PaError e) {
...@@ -237,6 +250,15 @@ int main(void) { ...@@ -237,6 +250,15 @@ int main(void) {
zmq::message_t &request = msg[0]; zmq::message_t &request = msg[0];
std::string str((char *)request.data()); 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) { if (verbose) {
std::cout << "Received: '" << str << "' (" << request.size() std::cout << "Received: '" << str << "' (" << request.size()
<< " bytes)" << std::endl; << " bytes)" << std::endl;
...@@ -262,12 +284,30 @@ int main(void) { ...@@ -262,12 +284,30 @@ int main(void) {
} }
if (cmd == "AF") { // Fill if (cmd == "AF") { // Fill
delete buffer[ibuf];
if (audio_header) {
std::uint32_t Fs = audio_header[0];
std::uint32_t nchan = audio_header[1];
std::uint32_t nsamp = audio_header[2];
buffer[ibuf] = new zmq_audiobuffer(Fs, nsamp, nchan);
buffer[ibuf]->fill(msg[2]);
}
else
buffer[ibuf]=nullptr;
} }
else if (cmd == "AP") { // Play else if (cmd == "AP") { // Play
if (buffer[ibuf])
buffer[ibuf]->play();
} }
else if (cmd == "AS") { // Stop else if (cmd == "AS") { // Stop
if (buffer[ibuf])
buffer[ibuf]->stop();
} }
delete[] audio_header;
//delete[] audio_data;
buffer[0] = new zmq_audiobuffer(44100, 5 * 48000, 2); buffer[0] = new zmq_audiobuffer(44100, 5 * 48000, 2);
zmq_audiobuffer *data = buffer[0]; zmq_audiobuffer *data = buffer[0];
data->fill(); data->fill();
......
...@@ -18,8 +18,8 @@ class zmq_audiobuffer { ...@@ -18,8 +18,8 @@ class zmq_audiobuffer {
std::uint32_t _nchan); std::uint32_t _nchan);
~zmq_audiobuffer(); ~zmq_audiobuffer();
void fill(); int fill();
void fill(zmq::message_t&); int fill(zmq::message_t&);
int play(); int play();
void stop(); void stop();
void abort(); void abort();
......
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