Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Biophysics Labs
Firmware
Commits
ce605efb
Commit
ce605efb
authored
Sep 02, 2020
by
Your Name
Browse files
fix zmqaudio data loading (finally....)
parent
9d50a779
Changes
2
Hide whitespace changes
Inline
Side-by-side
lsldert/zmqaudio
View file @
ce605efb
No preview for this file type
lsldert/zmqaudio.cc
View file @
ce605efb
...
...
@@ -80,29 +80,6 @@ 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
PaStreamParameters
outputParameters
;
outputParameters
.
device
=
Pa_GetDefaultOutputDevice
();
/* default output device */
if
(
outputParameters
.
device
==
paNoDevice
)
{
fprintf
(
stderr
,
"Error: No default output device.
\n
"
);
return
;
}
outputParameters
.
channelCount
=
nchan
;
/* stereo output */
outputParameters
.
sampleFormat
=
paFloat32
;
/* 32 bit floating point output */
outputParameters
.
suggestedLatency
=
Pa_GetDeviceInfo
(
outputParameters
.
device
)
->
defaultLowOutputLatency
;
outputParameters
.
hostApiSpecificStreamInfo
=
NULL
;
PaError
err
;
err
=
Pa_OpenStream
(
&
stream
,
NULL
,
/* no input */
&
outputParameters
,
fsamp
,
frames_per_buffer
,
paClipOff
,
/* we won't output out of range samples so
don't bother clipping them */
zmq_audiobuffer
::
stream_callback
,
this
);
if
(
err
!=
paNoError
)
{
print_error
(
err
);
}
}
zmq_audiobuffer
::~
zmq_audiobuffer
()
{
...
...
@@ -127,18 +104,17 @@ int zmq_audiobuffer::stream_callback(
int
ret
=
paContinue
;
for
(
i
=
0
;
i
<
framesPerBuffer
;
i
++
)
{
if
(
pbuf
->
idata
<
pbuf
->
nsamp
)
{
*
out
++
=
pbuf
->
data
[
2
*
(
pbuf
->
idata
)];
// left
*
out
++
=
pbuf
->
data
[
2
*
(
pbuf
->
idata
)
+
1
];
// right
pbuf
->
idata
++
;
if
(
pbuf
->
idata
<
(
pbuf
->
nsamp
*
pbuf
->
nchan
))
{
for
(
int
j
=
0
;
j
<
pbuf
->
nchan
;
j
++
)
*
out
++
=
pbuf
->
data
[
pbuf
->
idata
++
];
}
else
{
*
out
++
=
0
;
*
out
++
=
0
;
for
(
int
j
=
0
;
j
<
pbuf
->
nchan
;
j
++
)
*
out
++
=
0
;
ret
=
paComplete
;
}
}
std
::
cerr
<<
"idata="
<<
pbuf
->
idata
<<
" fpb="
<<
framesPerBuffer
<<
std
::
endl
;
std
::
cerr
<<
"idata="
<<
pbuf
->
idata
<<
" fpb="
<<
framesPerBuffer
<<
" nsamp="
<<
pbuf
->
nsamp
<<
std
::
endl
;
return
ret
;
}
...
...
@@ -154,8 +130,29 @@ void zmq_audiobuffer::stream_finished(void *userData) {
int
zmq_audiobuffer
::
play
()
{
idata
=
0
;
PaStreamParameters
outputParameters
;
outputParameters
.
device
=
Pa_GetDefaultOutputDevice
();
/* default output device */
if
(
outputParameters
.
device
==
paNoDevice
)
{
fprintf
(
stderr
,
"Error: No default output device.
\n
"
);
return
paNoDevice
;
}
outputParameters
.
channelCount
=
nchan
;
/* stereo output */
outputParameters
.
sampleFormat
=
paFloat32
;
/* 32 bit floating point output */
outputParameters
.
suggestedLatency
=
Pa_GetDeviceInfo
(
outputParameters
.
device
)
->
defaultLowOutputLatency
;
outputParameters
.
hostApiSpecificStreamInfo
=
NULL
;
PaError
err
;
err
=
Pa_OpenStream
(
&
stream
,
NULL
,
/* no input */
&
outputParameters
,
fsamp
,
frames_per_buffer
,
paClipOff
,
/* we won't output out of range samples so
don't bother clipping them */
zmq_audiobuffer
::
stream_callback
,
this
);
sprintf
(
message
,
"No Message"
);
int
err
=
err
=
Pa_SetStreamFinishedCallback
(
stream
,
&
zmq_audiobuffer
::
stream_finished
);
if
(
err
!=
paNoError
)
{
print_error
(
err
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment