30 bool is_input =
false;
31 bool is_output =
true;
54 result.is_input =
true;
55 result.is_output =
false;
58 result.is_input =
false;
59 result.is_output =
true;
62 result.is_input =
true;
63 result.is_output =
true;
66 LOGE(
"Unsupported Mode")
90 bool begin()
override {
91 return begin(defaultConfig());
95 bool begin(PortAudioConfig info) {
99 if (info.channels>0 && info.sample_rate && info.bits_per_sample>0){
100 LOGD(
"Pa_Initialize");
101 err = Pa_Initialize();
102 LOGD(
"Pa_Initialize - done");
103 if( err != paNoError ) {
104 LOGE(
"PortAudio error: %s\n", Pa_GetErrorText( err ) );
109 int buffer_frames = paFramesPerBufferUnspecified;
112 LOGD(
"Pa_OpenDefaultStream");
113 err = Pa_OpenDefaultStream( &stream,
114 info.is_input ? info.channels : 0,
115 info.is_output ? info.channels : 0,
121 LOGD(
"Pa_OpenDefaultStream - done");
122 if( err != paNoError && err!= paOutputUnderflow ) {
123 LOGE(
"PortAudio error: %s\n", Pa_GetErrorText( err ) );
127 LOGI(
"basic audio information is missing...");
133 void end()
override {
135 err = Pa_StopStream( stream );
136 if( err != paNoError ) {
137 LOGE(
"PortAudio error: %s\n", Pa_GetErrorText( err ) );
140 err = Pa_CloseStream( stream );
141 if( err != paNoError ) {
142 LOGE(
"PortAudio error: %s\n", Pa_GetErrorText( err ) );
144 stream_started =
false;
148 return err == paNoError;
151 size_t write(
const uint8_t* data,
size_t len)
override {
152 LOGD(
"write: %zu", len);
157 if (stream!=
nullptr){
158 int frames = len / bytesPerSample() / info.channels;
159 err = Pa_WriteStream( stream, data, frames);
160 if( err == paNoError ) {
161 LOGD(
"Pa_WriteStream: %zu", len);
164 LOGE(
"PortAudio error: %s", Pa_GetErrorText( err ) );
167 LOGW(
"stream is null")
172 size_t readBytes( uint8_t *data,
size_t len)
override {
173 LOGD(
"readBytes: %zu", len);
175 if (stream!=
nullptr){
176 int frames = len / bytesPerSample() / info.channels;
177 err = Pa_ReadStream( stream, data, frames );
178 if( err == paNoError ) {
181 LOGE(
"PortAudio error: %s\n", Pa_GetErrorText( err ) );
184 LOGW(
"stream is null")
191 PaStream *stream =
nullptr;
192 PaError err = paNoError;
193 PortAudioConfig info;
194 bool stream_started =
false;
195 int buffer_size = 10*1024;
197 int bytesPerSample(){
199 return info.bits_per_sample==24 ?
sizeof(int24_t): info.bits_per_sample / 8;
203 PaSampleFormat getFormat(){
204 switch(bytesPerSample()){
220 if (!stream_started && stream !=
nullptr) {
222 err = Pa_StartStream( stream );
223 if( err == paNoError ) {
224 stream_started =
true;
226 stream_started =
false;
227 LOGE(
"PortAudio error: %s\n", Pa_GetErrorText( err ) );
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:28