本文整理汇总了C++中snd_pcm_delay函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_delay函数的具体用法?C++ snd_pcm_delay怎么用?C++ snd_pcm_delay使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_pcm_delay函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: gst_alsasink_delay
static guint
gst_alsasink_delay (GstAudioSink * asink)
{
GstAlsaSink *alsa;
snd_pcm_sframes_t delay;
int res;
alsa = GST_ALSA_SINK (asink);
GST_DELAY_SINK_LOCK (asink);
res = snd_pcm_delay (alsa->handle, &delay);
GST_DELAY_SINK_UNLOCK (asink);
if (G_UNLIKELY (res < 0)) {
/* on errors, report 0 delay */
GST_DEBUG_OBJECT (alsa, "snd_pcm_delay returned %d", res);
delay = 0;
}
if (G_UNLIKELY (delay < 0)) {
/* make sure we never return a negative delay */
GST_WARNING_OBJECT (alsa, "snd_pcm_delay returned negative delay");
delay = 0;
}
return delay;
}
开发者ID:pli3,项目名称:gst-plugins-base,代码行数:25,代码来源:gstalsasink.c
示例2: Read
int audioStreamer_ALSA::Read(char *buf, int len) // returns 0 if blocked, < 0 if error, > 0 if data
{
int ret;
if (m_sleep >= 0)
{
struct pollfd pfds[32];
int cnt=snd_pcm_poll_descriptors(pcm_handle,pfds,32);
if (cnt>0) poll(pfds,cnt,m_sleep);
}
ret=snd_pcm_readi(pcm_handle, buf, len/(m_nch*(m_bps/8)));
if (ret < 0)
{
if (ret != -EAGAIN) { snd_pcm_prepare(pcm_handle); }
return 0;
}
#if 0
snd_pcm_sframes_t del=0;
if (!snd_pcm_delay(pcm_handle,&del) && del > m_bufsize/2 /* JF>used to be /1 */)
{
audiostream_onover();
for (;;) if (snd_pcm_readi(pcm_handle, buf, len/(m_nch*(m_bps/8)))<0) break;
// we have too many samples, eat some
}
#endif
return ret*m_nch*(m_bps/8);
}
开发者ID:bill-auger,项目名称:webjam,代码行数:29,代码来源:audiostream_alsa.cpp
示例3: Write
int audioStreamer_ALSA::Write(char *buf, int len) // returns 0 on success
{
snd_pcm_sframes_t del=0;
if (!len) return 0;
int cnt=1;
if (!m_started || !snd_pcm_delay(pcm_handle,&del) && del<1)
{
if (m_started) audiostream_onunder();
else m_started=1;
cnt=m_nfrags;
memset(buf,0,len); // reduce noise
}
while (cnt-->0)
{
int ret=snd_pcm_writei(pcm_handle, buf, len/(m_nch*(m_bps/8)));
if (ret < 0)
{
if (ret == -EPIPE) snd_pcm_prepare(pcm_handle);
return 0;
}
}
return 0;
}
开发者ID:bill-auger,项目名称:webjam,代码行数:27,代码来源:audiostream_alsa.cpp
示例4: laudio_alsa_get_pos
static uint64_t
laudio_alsa_get_pos(void)
{
snd_pcm_sframes_t delay;
int ret;
if (pcm_pos == 0)
return 0;
if (pcm_last_error != 0)
return pcm_pos;
if (snd_pcm_state(hdl) != SND_PCM_STATE_RUNNING)
return pcm_pos;
ret = snd_pcm_delay(hdl, &delay);
if (ret < 0)
{
DPRINTF(E_WARN, L_LAUDIO, "Could not obtain PCM delay: %s\n", snd_strerror(ret));
return pcm_pos;
}
return pcm_pos - delay;
}
开发者ID:bjoernricks,项目名称:forked-daapd,代码行数:25,代码来源:laudio_alsa.c
示例5: alsa_stream_get_position
static int
alsa_stream_get_position(cubeb_stream * stm, uint64_t * position)
{
snd_pcm_sframes_t delay;
assert(stm && position);
pthread_mutex_lock(&stm->mutex);
delay = -1;
if (snd_pcm_state(stm->pcm) != SND_PCM_STATE_RUNNING ||
snd_pcm_delay(stm->pcm, &delay) != 0) {
*position = stm->last_position;
pthread_mutex_unlock(&stm->mutex);
return CUBEB_OK;
}
assert(delay >= 0);
*position = 0;
if (stm->write_position >= (snd_pcm_uframes_t) delay) {
*position = stm->write_position - delay;
}
stm->last_position = *position;
pthread_mutex_unlock(&stm->mutex);
return CUBEB_OK;
}
开发者ID:captainbrosset,项目名称:gecko-dev,代码行数:29,代码来源:cubeb_alsa.c
示例6: audio_offset
size_t
audio_offset()
{
snd_pcm_delay(playback_handle, &delay);
return written - delay;
}
开发者ID:Ichthyostega,项目名称:Lumiera,代码行数:7,代码来源:alsa.c
示例7: CheckXRUN
static void CheckXRUN(IDsDriverBufferImpl* This)
{
snd_pcm_state_t state = snd_pcm_state(This->pcm);
snd_pcm_sframes_t delay;
int err;
snd_pcm_hwsync(This->pcm);
snd_pcm_delay(This->pcm, &delay);
if ( state == SND_PCM_STATE_XRUN )
{
err = snd_pcm_prepare(This->pcm);
CommitAll(This);
snd_pcm_start(This->pcm);
WARN("xrun occurred\n");
if ( err < 0 )
ERR("recovery from xrun failed, prepare failed: %s\n", snd_strerror(err));
}
else if ( state == SND_PCM_STATE_SUSPENDED )
{
int err = snd_pcm_resume(This->pcm);
TRACE("recovery from suspension occurred\n");
if (err < 0 && err != -EAGAIN){
err = snd_pcm_prepare(This->pcm);
if (err < 0)
ERR("recovery from suspend failed, prepare failed: %s\n", snd_strerror(err));
}
} else if ( state != SND_PCM_STATE_RUNNING ) {
FIXME("Unhandled state: %d\n", state);
}
}
开发者ID:r6144,项目名称:wine,代码行数:30,代码来源:dsoutput.c
示例8: alsa_pause
void alsa_pause(struct codec *c, int p)
{
struct alsa_state *state = (struct alsa_state *) c->data;
if (snd_pcm_state(state->dev) != SND_PCM_STATE_PAUSED)
snd_pcm_delay(state->dev, &state->delay);
snd_pcm_pause(state->dev, p);
}
开发者ID:kernelOfTruth,项目名称:dsp,代码行数:7,代码来源:alsa.c
示例9: alsa_close
static void alsa_close ()
{
snd_pcm_sframes_t delay;
assert (handle != NULL);
/* play what remained in the buffer */
if (alsa_buf_fill) {
assert (alsa_buf_fill < chunk_size);
snd_pcm_format_set_silence (params.format,
alsa_buf + alsa_buf_fill,
(chunk_size - alsa_buf_fill) / bytes_per_frame
* params.channels);
alsa_buf_fill = chunk_size;
play_buf_chunks ();
}
/* Wait for ALSA buffers to empty.
* Do not be tempted to use snd_pcm_nonblock() and snd_pcm_drain()
* here; there are two bugs in ALSA which make it a bad idea (see
* the SVN commit log for r2550). Instead we sleep for the duration
* of the still unplayed samples. */
if (snd_pcm_delay (handle, &delay) == 0)
usleep ((uint64_t) delay * 1000000 / params.rate);
snd_pcm_close (handle);
logit ("ALSA device closed");
params.format = 0;
params.rate = 0;
params.channels = 0;
handle = NULL;
}
开发者ID:nihlaeth,项目名称:read-the-room,代码行数:33,代码来源:alsa.c
示例10: alsa_delay
ssize_t alsa_delay(struct codec *c)
{
struct alsa_state *state = (struct alsa_state *) c->data;
if (snd_pcm_state(state->dev) == SND_PCM_STATE_PAUSED)
return state->delay;
snd_pcm_delay(state->dev, &state->delay);
return state->delay;
}
开发者ID:kernelOfTruth,项目名称:dsp,代码行数:8,代码来源:alsa.c
示例11: audio_get_output_timestamp
static void
audio_get_output_timestamp(AVFormatContext *s1, int stream,
int64_t *dts, int64_t *wall)
{
AlsaData *s = s1->priv_data;
snd_pcm_sframes_t delay = 0;
*wall = av_gettime();
snd_pcm_delay(s->h, &delay);
*dts = s1->streams[0]->cur_dts - delay;
}
开发者ID:Unhelpful,项目名称:ffmpeg,代码行数:10,代码来源:alsa-audio-enc.c
示例12: delay
float delay()
{
if (!runnable)
return 0.0;
snd_pcm_sframes_t delay;
snd_pcm_delay(pcm, &delay);
return (float)delay / fps;
}
开发者ID:Themaister,项目名称:SLIMPlayer,代码行数:10,代码来源:alsa.hpp
示例13: bytesAvailable
qint64 QAudioInputPrivate::bytesAvailable() const
{
if ( !handle )
return 0;
snd_pcm_sframes_t frames;
if ( snd_pcm_delay( handle, &frames ) < 0 )
return 0;
return snd_pcm_frames_to_bytes( handle, frames );
}
开发者ID:Camelek,项目名称:qtmoko,代码行数:11,代码来源:qaudioinput_alsa.cpp
示例14: alsa_audio_deliver
static int
alsa_audio_deliver(audio_decoder_t *ad, int samples, int64_t pts, int epoch)
{
decoder_t *d = (decoder_t *)ad;
media_pipe_t *mp = ad->ad_mp;
int c;
retry:
c = snd_pcm_wait(d->h, 100);
if(c >= 0) {
c = snd_pcm_avail_update(d->h);
}
if(c == -EPIPE) {
snd_pcm_prepare(d->h);
usleep(100000);
TRACE(TRACE_DEBUG, "ALSA", "Audio underrun");
d->samples = 0;
goto retry;
}
c = MIN(d->max_frames_per_write, c);
uint8_t *planes[8] = {0};
planes[0] = d->tmp;
c = avresample_read(ad->ad_avr, planes, c);
snd_pcm_status_t *status;
int err;
snd_pcm_status_alloca(&status);
if ((err = snd_pcm_status(d->h, status)) >= 0) {
if(pts != AV_NOPTS_VALUE) {
snd_htimestamp_t hts;
snd_pcm_status_get_trigger_htstamp(status, &hts);
int64_t ts = hts.tv_sec * 1000000LL + hts.tv_nsec / 1000;
ts += d->samples * 1000000LL / ad->ad_out_sample_rate;
hts_mutex_lock(&mp->mp_clock_mutex);
mp->mp_audio_clock_avtime = ts;
mp->mp_audio_clock = pts;
mp->mp_audio_clock_epoch = epoch;
hts_mutex_unlock(&mp->mp_clock_mutex);
}
}
snd_pcm_sframes_t fr;
if(!snd_pcm_delay(d->h, &fr))
ad->ad_delay = 1000000L * fr / ad->ad_out_sample_rate;
c = snd_pcm_writei(d->h, d->tmp, c);
d->samples += c;
return 0;
}
开发者ID:copernic-us,项目名称:showtime-1,代码行数:53,代码来源:alsa.c
示例15: alsaspdifsink_delay
static snd_pcm_sframes_t
alsaspdifsink_delay (AlsaSPDIFSink * sink)
{
snd_pcm_sframes_t delay;
int err;
err = snd_pcm_delay (sink->pcm, &delay);
if (err < 0 || delay < 0) {
return 0;
}
return delay;
}
开发者ID:JJCG,项目名称:gst-plugins-bad,代码行数:13,代码来源:alsaspdifsink.c
示例16: tsmf_alsa_get_latency
static UINT64 tsmf_alsa_get_latency(ITSMFAudioDevice *audio)
{
UINT64 latency = 0;
snd_pcm_sframes_t frames = 0;
TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
if(alsa->out_handle && alsa->actual_rate > 0 &&
snd_pcm_delay(alsa->out_handle, &frames) == 0 &&
frames > 0)
{
latency = ((UINT64)frames) * 10000000LL / (UINT64) alsa->actual_rate;
}
return latency;
}
开发者ID:BUGgs,项目名称:FreeRDP,代码行数:13,代码来源:tsmf_alsa.c
示例17: pa_stream_get_timing_info
APULSE_EXPORT
const pa_timing_info *
pa_stream_get_timing_info(pa_stream *s)
{
trace_info_f("F %s s=%p\n", __func__, s);
snd_pcm_sframes_t delay;
if (snd_pcm_delay(s->ph, &delay) != 0)
delay = 0;
s->timing_info.read_index = s->timing_info.write_index - delay * pa_frame_size(&s->ss);
return &s->timing_info;
}
开发者ID:kandeshvari,项目名称:apulse,代码行数:14,代码来源:apulse-stream.c
示例18: get_delay
static long long get_delay(void) {
snd_pcm_sframes_t frames = 0;
snd_pcm_delay(alsa_handle, &frames);
if (frames < 0)
{
#if SND_LIB_VERSION >= 0x000901 /* snd_pcm_forward() exists since 0.9.0rc8 */
snd_pcm_forward(alsa_handle, -frames);
#endif
frames = 0;
}
return (long long)(frames * 1000000L / device_sample_rate);
}
开发者ID:mbedarff,项目名称:shairport,代码行数:14,代码来源:audio_alsa.c
示例19: alsa_bufferspace
static int alsa_bufferspace(void)
{
int err;
snd_pcm_sframes_t delay;
if ((err = snd_pcm_delay(handle, &delay)) < 0) {
if ((err = xrun_recovery(handle, err)) < 0) {
log_message(LOG_DEFAULT, "Delay error: %s", snd_strerror(err));
}
return alsa_bufsize;
}
return alsa_bufsize - delay;
}
开发者ID:martinpiper,项目名称:VICE,代码行数:14,代码来源:soundalsa.c
示例20: sndo_pcm_delay
/**
* \brief Obtain delay for a running PCM handle
* \param pcm ordinary PCM handle
* \param delayp Returned delay in frames
* \return 0 on success otherwise a negative error code
*
* Delay is distance between current application frame position and
* sound frame position.
* It's positive and less than buffer size in normal situation,
* negative on playback underrun and greater than buffer size on
* capture overrun.
*/
int sndo_pcm_delay(sndo_pcm_t *pcm, snd_pcm_sframes_t *delayp)
{
int err;
snd_pcm_sframes_t pdelay, cdelay;
assert(pcm);
assert(delayp);
err = sndo_pcm_check_setup(pcm);
if (err < 0)
return err;
if (pcm->playback)
err = snd_pcm_avail_update(pcm->playback);
if (err >= 0 && pcm->capture)
err = snd_pcm_avail_update(pcm->capture);
if (err >= 0 && pcm->playback)
err = snd_pcm_delay(pcm->playback, &pdelay);
if (err >= 0 && pcm->capture)
err = snd_pcm_delay(pcm->capture, &cdelay);
if (pdelay > cdelay)
pdelay = cdelay;
*delayp = pdelay;
return err;
}
开发者ID:xenyinzen,项目名称:lx_toolset,代码行数:35,代码来源:ordinary_pcm.c
注:本文中的snd_pcm_delay函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论