本文整理汇总了C++中pa_usec_to_bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ pa_usec_to_bytes函数的具体用法?C++ pa_usec_to_bytes怎么用?C++ pa_usec_to_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pa_usec_to_bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pulse_start_recording
/**
* Start recording
*
* We request the default format used by pulse here because the data will be
* converted and possibly re-sampled by obs anyway.
*
* For now we request a buffer length of 25ms although pulse seems to ignore
* this setting for monitor streams. For "real" input streams this should work
* fine though.
*/
static int_fast32_t pulse_start_recording(struct pulse_data *data)
{
if (pulse_get_server_info(pulse_server_info, (void *) data) < 0) {
blog(LOG_ERROR, "Unable to get server info !");
return -1;
}
if (pulse_get_source_info(pulse_source_info, data->device,
(void *) data) < 0) {
blog(LOG_ERROR, "Unable to get source info !");
return -1;
}
pa_sample_spec spec;
spec.format = data->format;
spec.rate = data->samples_per_sec;
spec.channels = data->channels;
if (!pa_sample_spec_valid(&spec)) {
blog(LOG_ERROR, "Sample spec is not valid");
return -1;
}
data->speakers = pulse_channels_to_obs_speakers(spec.channels);
data->bytes_per_frame = pa_frame_size(&spec);
data->stream = pulse_stream_new(obs_source_get_name(data->source),
&spec, NULL);
if (!data->stream) {
blog(LOG_ERROR, "Unable to create stream");
return -1;
}
pulse_lock();
pa_stream_set_read_callback(data->stream, pulse_stream_read,
(void *) data);
pulse_unlock();
pa_buffer_attr attr;
attr.fragsize = pa_usec_to_bytes(25000, &spec);
attr.maxlength = (uint32_t) -1;
attr.minreq = (uint32_t) -1;
attr.prebuf = (uint32_t) -1;
attr.tlength = (uint32_t) -1;
pa_stream_flags_t flags = PA_STREAM_ADJUST_LATENCY;
pulse_lock();
int_fast32_t ret = pa_stream_connect_record(data->stream, data->device,
&attr, flags);
pulse_unlock();
if (ret < 0) {
pulse_stop_recording(data);
blog(LOG_ERROR, "Unable to connect to stream");
return -1;
}
blog(LOG_INFO, "Started recording from '%s'", data->device);
return 0;
}
示例2: process_rewind
static void process_rewind(struct userdata *u, pa_usec_t now) {
size_t rewind_nbytes, in_buffer;
pa_usec_t delay;
pa_assert(u);
rewind_nbytes = u->sink->thread_info.rewind_nbytes;
if (!PA_SINK_IS_OPENED(u->sink->thread_info.state) || rewind_nbytes <= 0)
goto do_nothing;
pa_log_debug("Requested to rewind %lu bytes.", (unsigned long) rewind_nbytes);
if (u->timestamp <= now)
goto do_nothing;
delay = u->timestamp - now;
in_buffer = pa_usec_to_bytes(delay, &u->sink->sample_spec);
if (in_buffer <= 0)
goto do_nothing;
if (rewind_nbytes > in_buffer)
rewind_nbytes = in_buffer;
pa_sink_process_rewind(u->sink, rewind_nbytes);
u->timestamp -= pa_bytes_to_usec(rewind_nbytes, &u->sink->sample_spec);
pa_log_debug("Rewound %lu bytes.", (unsigned long) rewind_nbytes);
return;
do_nothing:
pa_sink_process_rewind(u->sink, 0);
}
示例3: kradpulse_stream_underflow_cb
static void kradpulse_stream_underflow_cb(pa_stream *s, void *userdata) {
krad_pulse_t *kradpulse = (krad_pulse_t *)userdata;
// We increase the latency by 50% if we get 6 underflows and latency is under 2s
// This is very useful for over the network playback that can't handle low latencies
printf("underflow\n");
kradpulse->underflows++;
if (kradpulse->underflows >= 6 && kradpulse->latency < 2000000) {
kradpulse->latency = (kradpulse->latency*3)/2;
kradpulse->bufattr.maxlength = pa_usec_to_bytes(kradpulse->latency, &kradpulse->ss);
kradpulse->bufattr.tlength = pa_usec_to_bytes(kradpulse->latency, &kradpulse->ss);
pa_stream_set_buffer_attr(s, &kradpulse->bufattr, NULL, NULL);
kradpulse->underflows = 0;
printf("latency increased to %d\n", kradpulse->latency);
}
}
示例4: audiostream_
AudioStream::AudioStream(pa_context *c, pa_threaded_mainloop *m, const char *desc, int type, int smplrate, std::string& deviceName)
: audiostream_(0), mainloop_(m)
{
static const pa_channel_map channel_map = {
1,
{ PA_CHANNEL_POSITION_MONO },
};
pa_sample_spec sample_spec = {
PA_SAMPLE_S16LE, // PA_SAMPLE_FLOAT32LE,
smplrate,
1
};
assert(pa_sample_spec_valid(&sample_spec));
assert(pa_channel_map_valid(&channel_map));
audiostream_ = pa_stream_new(c, desc, &sample_spec, &channel_map);
if (!audiostream_) {
ERROR("%s: pa_stream_new() failed : %s" , desc, pa_strerror(pa_context_errno(c)));
throw std::runtime_error("Could not create stream\n");
}
pa_buffer_attr attributes;
attributes.maxlength = pa_usec_to_bytes(160 * PA_USEC_PER_MSEC, &sample_spec);
attributes.tlength = pa_usec_to_bytes(80 * PA_USEC_PER_MSEC, &sample_spec);
attributes.prebuf = 0;
attributes.fragsize = pa_usec_to_bytes(80 * PA_USEC_PER_MSEC, &sample_spec);
attributes.minreq = (uint32_t) -1;
pa_threaded_mainloop_lock(mainloop_);
if (type == PLAYBACK_STREAM || type == RINGTONE_STREAM)
pa_stream_connect_playback(audiostream_, deviceName == "" ? NULL : deviceName.c_str(), &attributes,
(pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE), NULL, NULL);
else if (type == CAPTURE_STREAM)
pa_stream_connect_record(audiostream_, deviceName == "" ? NULL : deviceName.c_str(), &attributes,
(pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE));
pa_threaded_mainloop_unlock(mainloop_);
pa_stream_set_state_callback(audiostream_, stream_state_callback, NULL);
}
示例5: thread_func
static void thread_func(void *userdata) {
struct userdata *u = userdata;
pa_assert(u);
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
u->timestamp = pa_rtclock_now();
for (;;) {
int ret;
/* Generate some null data */
if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
pa_usec_t now;
pa_memchunk chunk;
now = pa_rtclock_now();
if ((chunk.length = pa_usec_to_bytes(now - u->timestamp, &u->source->sample_spec)) > 0) {
chunk.memblock = pa_memblock_new(u->core->mempool, (size_t) -1); /* or chunk.length? */
chunk.index = 0;
pa_source_post(u->source, &chunk);
pa_memblock_unref(chunk.memblock);
u->timestamp = now;
}
pa_rtpoll_set_timer_absolute(u->rtpoll, u->timestamp + u->latency_time * PA_USEC_PER_MSEC);
} else
pa_rtpoll_set_timer_disabled(u->rtpoll);
/* Hmm, nothing to do. Let's sleep */
if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
goto fail;
if (ret == 0)
goto finish;
}
fail:
/* If this was no regular exit from the loop we have to continue
* processing messages until we received PA_MESSAGE_SHUTDOWN */
pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN);
finish:
pa_log_debug("Thread shutting down");
}
示例6: adin_standby
boolean
adin_standby(int sfreq, void *dummy)
{
static const pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
.rate = SAMPLE_RATE,
.channels = NBCHANNEL,
};
// low-latency setting
pa_buffer_attr ba;
ba.tlength = pa_usec_to_bytes(50*1000, &ss);
ba.minreq = pa_usec_to_bytes(0, &ss);
ba.maxlength = pa_usec_to_bytes(50*1000, &ss);
ba.fragsize = sizeof(uint32_t) -1;
// input
if (!(r = pa_simple_new(NULL, "kiku", PA_STREAM_RECORD, NULL, "voice recognition", &ss, NULL, &ba, &errorpa))) {
return FALSE;
}
return TRUE;
}
示例7: audio_init
void audio_init() {
pa_threaded_mainloop *pa_ml=pa_threaded_mainloop_new();
pa_mainloop_api *pa_mlapi=pa_threaded_mainloop_get_api(pa_ml);
pa_context *pa_ctx=pa_context_new(pa_mlapi, "te");
pa_context_connect(pa_ctx, NULL, 0, NULL);
int pa_ready = 0;
pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready);
pa_threaded_mainloop_start(pa_ml);
while(pa_ready==0) { ; }
printf("audio ready\n");
if (pa_ready == 2) {
pa_context_disconnect(pa_ctx);
pa_context_unref(pa_ctx);
pa_threaded_mainloop_free(pa_ml);
}
pa_sample_spec ss;
ss.rate=96000;
ss.channels=1;
ss.format=PA_SAMPLE_S24_32LE;
ps=pa_stream_new(pa_ctx,"Playback",&ss,NULL);
pa_stream_set_write_callback(ps,audio_request_cb,NULL);
pa_stream_set_underflow_callback(ps,audio_underflow_cb,NULL);
pa_buffer_attr bufattr;
bufattr.fragsize = (uint32_t)-1;
bufattr.maxlength = pa_usec_to_bytes(20000,&ss);
bufattr.minreq = pa_usec_to_bytes(0,&ss);
bufattr.prebuf = 0;
bufattr.tlength = pa_usec_to_bytes(20000,&ss);
pa_stream_connect_playback(ps,NULL,&bufattr,
PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_START_CORKED,NULL,NULL);
}
示例8: sink_update_requested_latency_cb
static void sink_update_requested_latency_cb(pa_sink *s) {
struct userdata *u;
size_t nbytes;
pa_sink_assert_ref(s);
pa_assert_se(u = s->userdata);
u->block_usec = pa_sink_get_requested_latency_within_thread(s);
if (u->block_usec == (pa_usec_t) -1)
u->block_usec = s->thread_info.max_latency;
nbytes = pa_usec_to_bytes(u->block_usec, &s->sample_spec);
pa_sink_set_max_rewind_within_thread(s, nbytes);
pa_sink_set_max_request_within_thread(s, nbytes);
}
示例9: source_output_state_change_cb
/* Called from output thread context */
static void source_output_state_change_cb(pa_source_output *o, pa_source_output_state_t state) {
struct userdata *u;
pa_source_output_assert_ref(o);
pa_source_output_assert_io_context(o);
pa_assert_se(u = o->userdata);
if (PA_SOURCE_OUTPUT_IS_LINKED(state) && o->thread_info.state == PA_SOURCE_OUTPUT_INIT) {
u->skip = pa_usec_to_bytes(PA_CLIP_SUB(pa_source_get_latency_within_thread(o->source),
u->latency),
&o->sample_spec);
pa_log_info("Skipping %lu bytes", (unsigned long) u->skip);
}
}
开发者ID:freedesktop-unofficial-mirror,项目名称:pulseaudio__pulseaudio.git.backup,代码行数:17,代码来源:module-loopback.c
示例10: sa_stream_get_position
int
sa_stream_get_position(sa_stream_t *s, sa_position_t position, int64_t *pos) {
pa_usec_t usec;
if (s == NULL || s->stream == NULL) {
return SA_ERROR_NO_INIT;
}
if (position != SA_POSITION_WRITE_SOFTWARE) {
return SA_ERROR_NOT_SUPPORTED;
}
pa_threaded_mainloop_lock(s->m);
if(pa_stream_get_time(s->stream, &usec) != PA_ERR_NODATA) {
*pos = pa_usec_to_bytes(usec, &s->sample_spec);
}
else {
*pos = s->bytes_written;
}
pa_threaded_mainloop_unlock(s->m);
return SA_SUCCESS;
}
示例11: cubeb_stream_get_position
int
cubeb_stream_get_position(cubeb_stream * stm, uint64_t * position)
{
int r;
pa_usec_t r_usec;
uint64_t bytes;
pa_threaded_mainloop_lock(stm->context->mainloop);
r = pa_stream_get_time(stm->stream, &r_usec);
pa_threaded_mainloop_unlock(stm->context->mainloop);
if (r != 0) {
return CUBEB_ERROR;
}
/* XXX might be more accurate to compute directly from get_timing_info */
bytes = pa_usec_to_bytes(r_usec, &stm->sample_spec);
*position = bytes / pa_frame_size(&stm->sample_spec);
return CUBEB_OK;
}
示例12: process_rewind
static void process_rewind(struct context *context, pa_usec_t now)
{
size_t rewind_nbytes, in_buffer;
pa_usec_t delay;
pa_assert(context);
/* Figure out how much we shall rewind and reset the counter */
rewind_nbytes = context->sink->thread_info.rewind_nbytes;
context->sink->thread_info.rewind_nbytes = 0;
if (rewind_nbytes <= 0)
goto DO_NOTHING;
pa_log_debug("Requested to rewind %lu bytes.",
(unsigned long) rewind_nbytes);
if (context->timestamp <= now)
goto DO_NOTHING;
delay = context->timestamp - now;
in_buffer = pa_usec_to_bytes(delay, &context->sink->sample_spec);
if (in_buffer <= 0)
goto DO_NOTHING;
if (rewind_nbytes > in_buffer)
rewind_nbytes = in_buffer;
pa_sink_process_rewind(context->sink, rewind_nbytes);
context->timestamp -= pa_bytes_to_usec(rewind_nbytes, &context->sink->sample_spec);
context->skip_bytes += rewind_nbytes;
pa_log_debug("Rewound %lu bytes.", (unsigned long) rewind_nbytes);
return;
DO_NOTHING:
pa_sink_process_rewind(context->sink, 0);
}
示例13: sink_update_requested_latency_cb
static void sink_update_requested_latency_cb(pa_sink *s) {
struct userdata *u;
size_t nbytes;
pa_sink_assert_ref(s);
pa_assert_se(u = s->userdata);
u->block_usec = BLOCK_USEC;
//u->block_usec = pa_sink_get_requested_latency_within_thread(s);
pa_log("1 block_usec %d", u->block_usec);
u->got_max_latency = 0;
if (u->block_usec == (pa_usec_t) -1) {
u->block_usec = s->thread_info.max_latency;
pa_log_debug("2 block_usec %d", u->block_usec);
u->got_max_latency = 1;
}
nbytes = pa_usec_to_bytes(u->block_usec, &s->sample_spec);
pa_sink_set_max_rewind_within_thread(s, nbytes);
pa_sink_set_max_request_within_thread(s, nbytes);
}
示例14: sink_update_requested_latency_cb
static void sink_update_requested_latency_cb(pa_sink *s) {
struct userdata *u;
pa_operation *operation;
size_t nbytes;
pa_usec_t block_usec;
pa_buffer_attr bufferattr;
pa_sink_assert_ref(s);
pa_assert_se(u = s->userdata);
block_usec = pa_sink_get_requested_latency_within_thread(s);
if (block_usec == (pa_usec_t) -1)
block_usec = s->thread_info.max_latency;
nbytes = pa_usec_to_bytes(block_usec, &s->sample_spec);
pa_sink_set_max_request_within_thread(s, nbytes);
if (u->stream) {
switch (pa_stream_get_state(u->stream)) {
case PA_STREAM_READY:
if (pa_stream_get_buffer_attr(u->stream)->tlength == nbytes)
break;
reset_bufferattr(&bufferattr);
bufferattr.tlength = nbytes;
if ((operation = pa_stream_set_buffer_attr(u->stream, &bufferattr, stream_set_buffer_attr_cb, u)))
pa_operation_unref(operation);
break;
case PA_STREAM_CREATING:
/* we have to delay our request until stream is ready */
u->update_stream_bufferattr_after_connect = true;
break;
default:
break;
}
}
}
示例15: process_rewind
static void process_rewind(struct userdata *u, pa_usec_t now) {
size_t rewind_nbytes, in_buffer;
pa_usec_t delay;
pa_assert(u);
/* Figure out how much we shall rewind and reset the counter */
rewind_nbytes = u->sink->thread_info.rewind_nbytes;
u->sink->thread_info.rewind_nbytes = 0;
pa_assert(rewind_nbytes > 0);
pa_log_debug("Requested to rewind %lu bytes.",
(unsigned long) rewind_nbytes);
if (u->timestamp <= now)
goto do_nothing;
delay = u->timestamp - now;
in_buffer = pa_usec_to_bytes(delay, &u->sink->sample_spec);
if (in_buffer <= 0)
goto do_nothing;
if (rewind_nbytes > in_buffer)
rewind_nbytes = in_buffer;
pa_sink_process_rewind(u->sink, rewind_nbytes);
u->timestamp -= pa_bytes_to_usec(rewind_nbytes, &u->sink->sample_spec);
u->skip_bytes += rewind_nbytes;
pa_log_debug("Rewound %lu bytes.", (unsigned long) rewind_nbytes);
return;
do_nothing:
pa_sink_process_rewind(u->sink, 0);
}