55#ifdef SHERPA_ONNX_ENABLE_ALSA
66
77#include " sherpa-onnx/csrc/alsa.h"
8+ #include " sherpa-onnx/csrc/macros.h"
89
910#include < algorithm>
1011#include < cstdio>
@@ -49,7 +50,7 @@ and if you want to select card 3 and device 0 on that card, please use:
4950 if (err) {
5051 fprintf (stderr, " Unable to open: %s. %s\n " , device_name, snd_strerror (err));
5152 fprintf (stderr, " %s\n " , kDeviceHelp );
52- exit (-1 );
53+ SHERPA_ONNX_EXIT (-1 );
5354 }
5455
5556 snd_pcm_hw_params_t *hw_params;
@@ -58,21 +59,21 @@ and if you want to select card 3 and device 0 on that card, please use:
5859 err = snd_pcm_hw_params_any (capture_handle_, hw_params);
5960 if (err) {
6061 fprintf (stderr, " Failed to initialize hw_params: %s\n " , snd_strerror (err));
61- exit (-1 );
62+ SHERPA_ONNX_EXIT (-1 );
6263 }
6364
6465 err = snd_pcm_hw_params_set_access (capture_handle_, hw_params,
6566 SND_PCM_ACCESS_RW_INTERLEAVED);
6667 if (err) {
6768 fprintf (stderr, " Failed to set access type: %s\n " , snd_strerror (err));
68- exit (-1 );
69+ SHERPA_ONNX_EXIT (-1 );
6970 }
7071
7172 err = snd_pcm_hw_params_set_format (capture_handle_, hw_params,
7273 SND_PCM_FORMAT_S16_LE);
7374 if (err) {
7475 fprintf (stderr, " Failed to set format: %s\n " , snd_strerror (err));
75- exit (-1 );
76+ SHERPA_ONNX_EXIT (-1 );
7677 }
7778
7879 // mono
@@ -86,7 +87,7 @@ and if you want to select card 3 and device 0 on that card, please use:
8687 fprintf (stderr, " Failed to set number of channels to 2. %s\n " ,
8788 snd_strerror (err));
8889
89- exit (-1 );
90+ SHERPA_ONNX_EXIT (-1 );
9091 }
9192 actual_channel_count_ = 2 ;
9293 fprintf (stderr,
@@ -101,7 +102,7 @@ and if you want to select card 3 and device 0 on that card, please use:
101102 if (err) {
102103 fprintf (stderr, " Failed to set sample rate to, %d: %s\n " ,
103104 expected_sample_rate_, snd_strerror (err));
104- exit (-1 );
105+ SHERPA_ONNX_EXIT (-1 );
105106 }
106107 actual_sample_rate_ = actual_sample_rate;
107108
@@ -128,13 +129,13 @@ and if you want to select card 3 and device 0 on that card, please use:
128129 err = snd_pcm_hw_params (capture_handle_, hw_params);
129130 if (err) {
130131 fprintf (stderr, " Failed to set hw params: %s\n " , snd_strerror (err));
131- exit (-1 );
132+ SHERPA_ONNX_EXIT (-1 );
132133 }
133134
134135 err = snd_pcm_prepare (capture_handle_);
135136 if (err) {
136137 fprintf (stderr, " Failed to prepare for recording: %s\n " , snd_strerror (err));
137- exit (-1 );
138+ SHERPA_ONNX_EXIT (-1 );
138139 }
139140
140141 fprintf (stderr, " Recording started!\n " );
@@ -154,7 +155,7 @@ const std::vector<float> &Alsa::Read(int32_t num_samples) {
154155 stderr,
155156 " Too many overruns. It is very likely that the RTF on your board is "
156157 " larger than 1. Please use ./bin/sherpa-onnx to compute the RTF.\n " );
157- exit (-1 );
158+ SHERPA_ONNX_EXIT (-1 );
158159 }
159160 fprintf (stderr, " XRUN.\n " );
160161 snd_pcm_prepare (capture_handle_);
@@ -163,7 +164,7 @@ const std::vector<float> &Alsa::Read(int32_t num_samples) {
163164 return tmp;
164165 } else if (count < 0 ) {
165166 fprintf (stderr, " Can't read PCM device: %s\n " , snd_strerror (count));
166- exit (-1 );
167+ SHERPA_ONNX_EXIT (-1 );
167168 }
168169
169170 samples_.resize (count * actual_channel_count_);
0 commit comments