@@ -27,8 +27,9 @@ class PortAudioConfig : public AudioBaseInfo {
27
27
*/
28
28
class PortAudioStream : public BufferedStream {
29
29
public:
30
- PortAudioStream ():BufferedStream(DEFAULT_BUFFER_SIZE ) {
30
+ PortAudioStream (int buffer_size=DEFAULT_BUFFER_SIZE ):BufferedStream(buffer_size ) {
31
31
LOGD (__FUNCTION__);
32
+ this ->buffer_size = buffer_size;
32
33
}
33
34
34
35
~PortAudioStream (){
@@ -57,20 +58,20 @@ class PortAudioStream : public BufferedStream {
57
58
return ;
58
59
}
59
60
60
- /* Open an audio I/O stream. */
61
+ // calculate frames
62
+ int bytes = info.bits_per_sample / 8 ;
63
+ int buffer_frames = buffer_size / bytes / info.channels ;
64
+
65
+ // Open an audio I/O stream.
61
66
LOGD (" Pa_OpenDefaultStream" );
62
67
err = Pa_OpenDefaultStream ( &stream,
63
- info.is_input ? info.channels : 0 , /* no input channels */
64
- info.is_output ? info.channels : 0 , /* stereo output */
65
- getFormat (info.bits_per_sample ),
66
- info.sample_rate ,
67
- paFramesPerBufferUnspecified, /* frames per buffer, i.e. the number
68
- of sample frames that PortAudio will
69
- request from the callback. Many apps
70
- may want to use*/
71
- nullptr , /* this is your callback function */
72
- nullptr ); /* This is a pointer that will be passed to
73
- your callback*/
68
+ info.is_input ? info.channels : 0 , // no input channels
69
+ info.is_output ? info.channels : 0 , // stereo output
70
+ getFormat (info.bits_per_sample ), // format
71
+ info.sample_rate , // sample rate
72
+ buffer_frames, // frames per buffer
73
+ nullptr ,
74
+ nullptr );
74
75
LOGD (" Pa_OpenDefaultStream - done" );
75
76
if ( err != paNoError ) {
76
77
LOGE ( " PortAudio error: %s\n " , Pa_GetErrorText ( err ) );
@@ -101,6 +102,7 @@ class PortAudioStream : public BufferedStream {
101
102
PaError err = paNoError;
102
103
PortAudioConfig info;
103
104
bool stream_started = false ;
105
+ int buffer_size;
104
106
105
107
virtual size_t writeExt (const uint8_t * data, size_t len) {
106
108
LOGD (" writeExt: %zu" , len);
0 commit comments