Skip to content

Commit 91652b9

Browse files
committed
Portaudio start stream
1 parent 75e00d1 commit 91652b9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/AudioTools/PortAudioStream.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class PortAudioStream : public BufferedStream {
8989
if( err != paNoError ) {
9090
LOGE( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
9191
}
92+
stream_started = false;
9293
}
9394

9495
operator boolean() {
@@ -99,9 +100,13 @@ class PortAudioStream : public BufferedStream {
99100
PaStream *stream = nullptr;
100101
PaError err = paNoError;
101102
PortAudioConfig info;
103+
bool stream_started = false;
102104

103105
virtual size_t writeExt(const uint8_t* data, size_t len) {
104106
LOGD("writeExt: %zu", len);
107+
108+
startStream();
109+
105110
size_t result = 0;
106111
if (stream!=nullptr){
107112
int bytes = info.bits_per_sample / 8;
@@ -150,6 +155,20 @@ class PortAudioStream : public BufferedStream {
150155
// make sure that we return a valid value
151156
return paInt16;
152157
}
158+
159+
/// automatically start the stream when we start to get data
160+
void startStream() {
161+
if (!stream_started) {
162+
LOGD(__FUNCTION__);
163+
err = Pa_StartStream( stream );
164+
if( err == paNoError ) {
165+
stream_started = true;
166+
} else {
167+
stream_started = false;
168+
LOGE( "PortAudio error: %s\n", Pa_GetErrorText( err ) );
169+
}
170+
}
171+
}
153172
};
154173

155174
} // namespace

0 commit comments

Comments
 (0)