本文整理汇总了C++中snd_pcm_drain函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_drain函数的具体用法?C++ snd_pcm_drain怎么用?C++ snd_pcm_drain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_pcm_drain函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ao_plugin_close
/* close the audio device */
int ao_plugin_close(ao_device *device)
{
ao_alsa_internal *internal;
if (device) {
if ((internal = (ao_alsa_internal *) device->internal)) {
if (internal->pcm_handle) {
/* this is a PulseAudio ALSA emulation bug workaround;
snd_pcm_drain always takes about 2 seconds, even if
there's nothing to drain. Rather than wait for no
reason, determine the current playback depth, wait
that long, then kill the stream. Remove this code
once Pulse gets fixed. */
snd_pcm_sframes_t sframes;
if(snd_pcm_delay (internal->pcm_handle, &sframes)){
snd_pcm_drain(internal->pcm_handle);
}else{
double s = (double)(sframes - internal->static_delay)/internal->sample_rate;
if(s>1){
/* something went wrong; fall back */
snd_pcm_drain(internal->pcm_handle);
}else{
if(s>0){
struct timespec sleep,wake;
sleep.tv_sec = (int)s;
sleep.tv_nsec = (s-sleep.tv_sec)*1000000000;
while(nanosleep(&sleep,&wake)<0){
if(errno==EINTR)
sleep=wake;
else
break;
}
}
}
}
snd_pcm_close(internal->pcm_handle);
if(internal->local_config)
snd_config_delete(internal->local_config);
internal->local_config=NULL;
internal->pcm_handle=NULL;
}
} else
awarn("ao_plugin_close called with uninitialized ao_device->internal\n");
} else
awarn("ao_plugin_close called with uninitialized ao_device\n");
return 1;
}
示例2: init
void Audio::run()
{
if (!initialized)
{
init();
initialized = true;
qDebug() << "Audio components initialized.";
}
if (synth->masterPlaying && synth->isPlaying())
{
replaceBuffer(synth->genChunk());
playBuffer();
// resetBuffer();
}
if (state != snd_pcm_state(handle))
{
state = snd_pcm_state(handle);
qDebug() << "State: " << state;
}
// Buffer underrun (not being written to fast enough)
if (state == 4)
{
snd_pcm_drain(handle);
prepareDevice();
}
}
示例3: stop
static void stop(void) {
if (alsa_handle) {
snd_pcm_drain(alsa_handle);
snd_pcm_close(alsa_handle);
alsa_handle = NULL;
}
}
示例4: sa_stream_drain
int
sa_stream_drain(sa_stream_t *s)
{
if (s == NULL || s->output_unit == NULL) {
return SA_ERROR_NO_INIT;
}
if (snd_pcm_state(s->output_unit) == SND_PCM_STATE_PREPARED) {
size_t min_samples = 0;
size_t min_bytes = 0;
void *buf;
if (sa_stream_get_min_write(s, &min_samples) < 0)
return SA_ERROR_SYSTEM;
min_bytes = snd_pcm_frames_to_bytes(s->output_unit, min_samples);
buf = malloc(min_bytes);
if (!buf)
return SA_ERROR_SYSTEM;
memset(buf, 0, min_bytes);
sa_stream_write(s, buf, min_bytes);
free(buf);
}
if (snd_pcm_state(s->output_unit) != SND_PCM_STATE_RUNNING) {
return SA_ERROR_INVALID;
}
snd_pcm_drain(s->output_unit);
return SA_SUCCESS;
}
示例5: alsaCleanup
static void alsaCleanup(Soloud *aSoloud)
{
if (0 == aSoloud->mBackendData)
{
return;
}
ALSAData *data = static_cast<ALSAData*>(aSoloud->mBackendData);
data->audioProcessingDone = true;
if (data->threadHandle)
{
Thread::wait(data->threadHandle);
Thread::release(data->threadHandle);
}
snd_pcm_drain(data->alsaDeviceHandle);
snd_pcm_close(data->alsaDeviceHandle);
if (0 != data->sampleBuffer)
{
delete[] data->sampleBuffer;
}
if (0 != data->buffer)
{
delete[] data->buffer;
}
delete data;
aSoloud->mBackendData = 0;
}
示例6: alsa_can_read
static int alsa_can_read(snd_pcm_t *dev)
{
snd_pcm_sframes_t avail;
int err;
alsa_resume(dev);
avail = snd_pcm_avail_update(dev);
/* A buggy driver does not return an error while being in Xrun */
if (avail >= 0 && snd_pcm_state(dev) == SND_PCM_STATE_XRUN) avail=-EPIPE;
if (avail < 0) {
ms_error("snd_pcm_avail_update: %s", snd_strerror(avail)); // most probably -EPIPE
/* overrun occured, snd_pcm_state() would return SND_PCM_STATE_XRUN
FIXME: handle other error conditions*/
ms_error("*** alsa_can_read fixup, trying to recover");
snd_pcm_drain(dev); /* Ignore possible error, at least -EAGAIN.*/
err = snd_pcm_recover(dev, avail, 0);
if (err){
ms_error("snd_pcm_recover() failed with err %d: %s", err, snd_strerror(err));
return -1;
}
err = snd_pcm_start(dev);
if (err){
ms_error("snd_pcm_start() failed with err %d: %s", err, snd_strerror(err));
return -1;
}
ms_message("Recovery done");
}
return avail;
}
示例7: sound_info_free
// 释放资源
void sound_info_free(struct SoundInfo *info) {
snd_pcm_drain(info->handle);
snd_pcm_close(info->handle);
free(info->buffer);
free(info);
}
示例8: main
int main(int argc, char *argv[])
{
char *filename;
char *devicename = "default";
int fd;
WAVContainer_t wav;
SNDPCMContainer_t playback;
if (argc != 2) {
fprintf(stderr, "Usage: ./lplay <file name>/n");
return -1;
}
memset(&playback, 0x0, sizeof(playback));
filename = argv[1];
fd = open(filename, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Error open [%s]/n", filename);
return -1;
}
if (WAV_ReadHeader(fd, &wav) < 0) {
fprintf(stderr, "Error WAV_Parse [%s]/n", filename);
goto Err;
}
if (snd_output_stdio_attach(&playback.log, stderr, 0) < 0) {
fprintf(stderr, "Error snd_output_stdio_attach/n");
goto Err;
}
if (snd_pcm_open(&playback.handle, devicename, SND_PCM_STREAM_PLAYBACK, 0) < 0) {
fprintf(stderr, "Error snd_pcm_open [ %s]/n", devicename);
goto Err;
}
if (SNDWAV_SetParams(&playback, &wav) < 0) {
fprintf(stderr, "Error set_snd_pcm_params/n");
goto Err;
}
snd_pcm_dump(playback.handle, playback.log);
SNDWAV_Play(&playback, &wav, fd);
snd_pcm_drain(playback.handle);
close(fd);
free(playback.data_buf);
snd_output_close(playback.log);
snd_pcm_close(playback.handle);
return 0;
Err:
close(fd);
if (playback.data_buf) free(playback.data_buf);
if (playback.log) snd_output_close(playback.log);
if (playback.handle) snd_pcm_close(playback.handle);
return -1;
}
示例9: snd_pcm_hw_params_free
void Mouth::close(){
snd_pcm_hw_params_free(params);
snd_pcm_drain(capture_handle);
snd_pcm_close(capture_handle);
snd_config_update_free_global();
open=false;
}
示例10: SetUpRecorder
bool SoundProcessor::Record(){
SetUpRecorder();
snd_pcm_sframes_t fwdframes=snd_pcm_forwardable(handle_m);
printf("forwarding %d\n",fwdframes);
snd_pcm_forward(handle_m,fwdframes);
while (true) {
rc_m = snd_pcm_readi(handle_m, buffer_m, frames);
if (rc_m == -EPIPE) {
/* EPIPE means overrun */
fprintf(stderr, "overrun occurred\n");
snd_pcm_prepare(handle_m);
} else if (rc_m < 0) {
fprintf(stderr,
"error from read: %s\n",
snd_strerror(rc_m));
} else if (rc_m != (int)frames) {
fprintf(stderr, "short read, read %d frames\n", rc_m);
}
rc_m = write(1, buffer_m, size);
if (rc_m != size)
fprintf(stderr,
"short write: wrote %d bytes\n", rc_m);
}
snd_pcm_drain(handle_m);
snd_pcm_close(handle_m);
free(buffer_m);
return true;
}
示例11: AlsaOutput_Close
/*----------------------------------------------------------------------
| AlsaOutput_Close
+---------------------------------------------------------------------*/
static BLT_Result
AlsaOutput_Close(AlsaOutput* self)
{
ATX_LOG_FINER("closing output");
switch (self->state) {
case BLT_ALSA_OUTPUT_STATE_CLOSED:
/* ignore */
return BLT_SUCCESS;
case BLT_ALSA_OUTPUT_STATE_PREPARED:
/* wait for buffers to finish */
ATX_LOG_FINER("snd_pcm_drain");
snd_pcm_drain(self->device_handle);
/* FALLTHROUGH */
case BLT_ALSA_OUTPUT_STATE_OPEN:
case BLT_ALSA_OUTPUT_STATE_CONFIGURED:
/* close the device */
ATX_LOG_FINER("snd_pcm_close");
snd_pcm_close(self->device_handle);
self->device_handle = NULL;
break;
}
/* update the state */
AlsaOutput_SetState(self, BLT_ALSA_OUTPUT_STATE_CLOSED);
return BLT_SUCCESS;
}
示例12: alsa_close
void alsa_close(alsa_dev_t *alsa_dev)
{
snd_pcm_drain(alsa_dev->snd_pcm);
snd_pcm_close(alsa_dev->snd_pcm);
free(alsa_dev);
}
示例13: alsa_close
static void
alsa_close( void )
{
snd_pcm_drain( alsa.pcm );
snd_pcm_close( alsa.pcm );
alsa.pcm = NULL;
}
示例14: close_alsa
void close_alsa(struct pcm *pcm)
{
struct alsa *alsa = (struct alsa *)(pcm->data);
snd_pcm_drain(alsa->pcm);
snd_pcm_close(alsa->pcm);
free(alsa);
}
示例15: ags_devout_alsa_free
void
ags_devout_alsa_free(AgsDevout *devout)
{
snd_pcm_drain(devout->out.alsa.handle);
snd_pcm_close(devout->out.alsa.handle);
devout->out.alsa.handle = NULL;
}