#include <online-audio-source.h>
|
int | PaCallback (const void *input, void *output, long unsigned frame_count, const PaStreamCallbackTimeInfo *time_info, PaStreamCallbackFlags status_flags, void *user_data) |
|
Definition at line 66 of file online-audio-source.h.
◆ rbs_t
typedef ring_buffer_size_t rbs_t |
◆ SampleType
◆ OnlinePaSource()
OnlinePaSource |
( |
const uint32 |
timeout, |
|
|
const uint32 |
sample_rate, |
|
|
const uint32 |
rb_size, |
|
|
const uint32 |
report_interval |
|
) |
| |
Definition at line 49 of file online-audio-source.cc.
References KALDI_ASSERT, KALDI_ERR, kaldi::Log(), OnlinePaSource::pa_ringbuf_, OnlinePaSource::pa_stream_, OnlinePaSource::PaCallback, OnlinePaSource::rb_size_, OnlinePaSource::ring_buffer_, and OnlinePaSource::sample_rate_.
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";
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_
#define KALDI_ASSERT(cond)
◆ ~OnlinePaSource()
◆ Callback()
int Callback |
( |
const void * |
input, |
|
|
void * |
output, |
|
|
ring_buffer_size_t |
frame_count, |
|
|
const PaStreamCallbackTimeInfo * |
time_info, |
|
|
PaStreamCallbackFlags |
status_flags |
|
) |
| |
|
private |
◆ KALDI_DISALLOW_COPY_AND_ASSIGN()
◆ Read()
Implements OnlineAudioSourceItf.
Definition at line 102 of file online-audio-source.cc.
References VectorBase< Real >::Dim(), Timer::Elapsed(), rnnlm::i, KALDI_ERR, KALDI_VLOG, KALDI_WARN, OnlinePaSource::noverflows_, OnlinePaSource::nread_calls_, OnlinePaSource::pa_ringbuf_, OnlinePaSource::pa_started_, OnlinePaSource::pa_stream_, OnlinePaSource::report_interval_, Vector< Real >::Resize(), OnlinePaSource::samples_lost_, OnlinePaSource::timed_out_, and OnlinePaSource::timeout_.
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)
126 int32 elapsed =
static_cast<int32>(timer.Elapsed() * 1000);
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);
PaUtilRingBuffer pa_ringbuf_
◆ TimedOut()
◆ PaCallback
int PaCallback |
( |
const void * |
input, |
|
|
void * |
output, |
|
|
long unsigned |
frame_count, |
|
|
const PaStreamCallbackTimeInfo * |
time_info, |
|
|
PaStreamCallbackFlags |
status_flags, |
|
|
void * |
user_data |
|
) |
| |
|
friend |
Definition at line 39 of file online-audio-source.cc.
Referenced by OnlinePaSource::OnlinePaSource().
45 return pa_src->Callback(input, output, frame_count, time_info, status_flags);
OnlinePaSource(const uint32 timeout, const uint32 sample_rate, const uint32 rb_size, const uint32 report_interval)
◆ noverflows_
◆ nread_calls_
◆ pa_ringbuf_
PaUtilRingBuffer pa_ringbuf_ |
|
private |
◆ pa_started_
◆ pa_stream_
◆ rb_size_
◆ report_interval_
◆ ring_buffer_
◆ sample_rate_
◆ samples_lost_
◆ timed_out_
◆ timeout_
The documentation for this class was generated from the following files: