28 #ifndef KALDI_NO_PORTAUDIO 30 #endif // KALDI_NO_PORTAUDIO 36 #ifndef KALDI_NO_PORTAUDIO 40 long unsigned frame_count,
41 const PaStreamCallbackTimeInfo *time_info,
42 PaStreamCallbackFlags status_flags,
45 return pa_src->
Callback(input, output, frame_count, time_info, status_flags);
50 const uint32 sample_rate,
52 const uint32 report_interval)
53 : timeout_(timeout), timed_out_(false),
54 sample_rate_(sample_rate), pa_started_(false),
55 report_interval_(report_interval), nread_calls_(0),
56 noverflows_(0), samples_lost_(0) {
65 float f =
Log(static_cast<float>(rb_size)) /
Log(static_cast<float>(2));
68 throw invalid_argument(
"PortAudio ring buffer too large!");
71 ring_buffer_size_t rbs = PaUtil_InitializeRingBuffer(
75 KALDI_ERR <<
"PortAudio ring buffer init error";
77 PaError paerr = Pa_Initialize();
78 if (paerr != paNoError)
79 KALDI_ERR <<
"PortAudio initialization error";
82 "The current OnlinePaSource code assumes 16-bit input");
85 if (paerr != paNoError)
86 KALDI_ERR <<
"PortAudio failed to open the default stream";
105 if (paerr != paNoError)
106 KALDI_ERR <<
"Error while trying to open PortAudio stream";
114 <<
" PortAudio ring buffer overflows detected " 118 uint32 nsamples_req = data->
Dim();
121 ring_buffer_size_t nsamples;
122 nsamples = PaUtil_GetRingBufferReadAvailable(&
pa_ringbuf_);
123 if (nsamples >= nsamples_req)
128 nsamples_req = nsamples;
130 KALDI_VLOG(2) <<
"OnlinePaSource::Read() timeout";
136 std::vector<int16> buf(nsamples_req);
138 nsamples_rcv = PaUtil_ReadRingBuffer(&
pa_ringbuf_, buf.data(), nsamples_req);
139 if (nsamples_rcv != nsamples_req) {
141 <<
"; Received: " << nsamples_rcv <<
" samples";
144 data->
Resize(nsamples_rcv);
145 for (
int i = 0;
i < nsamples_rcv; ++
i)
146 (*data)(
i) = static_cast<BaseFloat>(buf[
i]);
148 return (nsamples_rcv != 0);
157 ring_buffer_size_t frame_count,
158 const PaStreamCallbackTimeInfo *time_info,
159 PaStreamCallbackFlags status_flags) {
161 if (frame_count > PaUtil_GetRingBufferWriteAvailable(&
pa_ringbuf_))
169 #endif // KALDI_NO_PORTAUDIO 173 int32 n_elem = std::min(src_.Dim() - pos_,
174 static_cast<uint32
>(data->
Dim()));
177 if (data->
Dim() == subsrc.
Dim()) {
181 (*data)(
i) = subsrc(
i);
185 return (pos_ < src_.Dim());
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
friend int PaCallback(const void *input, void *output, long unsigned frame_count, const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags status_flags, void *user_data)
PaUtilRingBuffer pa_ringbuf_
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
bool Read(Vector< BaseFloat > *data)
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
MatrixIndexT Dim() const
Returns the dimension of the vector.
int PaCallback(const void *input, void *output, long unsigned frame_count, const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags status_flags, void *user_data)
A class representing a vector.
#define KALDI_ASSERT(cond)
OnlinePaSource(const uint32 timeout, const uint32 sample_rate, const uint32 rb_size, const uint32 report_interval)
bool Read(Vector< BaseFloat > *data)
double Elapsed() const
Returns time in seconds.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
int Callback(const void *input, void *output, ring_buffer_size_t frame_count, const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags status_flags)