• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ snd_pcm_drain函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中snd_pcm_drain函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_drain函数的具体用法?C++ snd_pcm_drain怎么用?C++ snd_pcm_drain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了snd_pcm_drain函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:BenWBrown,项目名称:cs453_final_project,代码行数:51,代码来源:ao_alsa.c


示例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();
    }
}
开发者ID:vsicurella,项目名称:CS490_Final,代码行数:29,代码来源:audio.cpp


示例3: stop

static void stop(void) {
    if (alsa_handle) {
        snd_pcm_drain(alsa_handle);
        snd_pcm_close(alsa_handle);
        alsa_handle = NULL;
    }
}
开发者ID:mbedarff,项目名称:shairport,代码行数:7,代码来源:audio_alsa.c


示例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;
}
开发者ID:hadicoffee,项目名称:jb412gecko,代码行数:30,代码来源:sydney_audio_alsa.c


示例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;
 }
开发者ID:Deslon,项目名称:Supernova,代码行数:26,代码来源:soloud_alsa.cpp


示例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;
}
开发者ID:TheBaobabTeam,项目名称:linphone-android,代码行数:29,代码来源:alsa.c


示例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);
}
开发者ID:chenshuchao,项目名称:c_chat,代码行数:8,代码来源:sound.c


示例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; 
 } 
开发者ID:MMMeng,项目名称:ASR_User_Words,代码行数:60,代码来源:lplay.c


示例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;
}
开发者ID:digitaltembo,项目名称:jade,代码行数:7,代码来源:Mouth.cpp


示例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;
}
开发者ID:jolygit,项目名称:code,代码行数:29,代码来源:soundProcessor.cpp


示例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;
}
开发者ID:axiomatic-systems,项目名称:BlueTune,代码行数:33,代码来源:BltAlsaOutput.c


示例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);
}
开发者ID:vaicebine,项目名称:puppyguard,代码行数:7,代码来源:alsa.c


示例13: alsa_close

static void
alsa_close( void )
{
	snd_pcm_drain( alsa.pcm );
	snd_pcm_close( alsa.pcm );
	alsa.pcm = NULL;
}
开发者ID:threader,项目名称:Mac-On-Linux,代码行数:7,代码来源:alsa.c


示例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);
}
开发者ID:xdsopl,项目名称:spectrum,代码行数:7,代码来源:alsa.c


示例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;
} 
开发者ID:weedlight,项目名称:ags,代码行数:7,代码来源:ags_devout.c


示例16: while

bool SoundProcessor::Play(){
  while (true) {
    rc_s = read(0, buffer_s, size);
    if (rc_s == 0) {
      fprintf(stderr, "end of file on input\n");
      break;
    } else if (rc_s != size) {
      fprintf(stderr,
              "short read: read %d bytes\n", rc_s);
    }
    rc_s = snd_pcm_writei(handle_s, buffer_s, frames);
    if (rc_s == -EPIPE) {
      /* EPIPE means underrun */
      // fprintf(stderr, "underrun occurred\n");
      snd_pcm_prepare(handle_s);
    } else if (rc_s < 0) {
      fprintf(stderr,
              "error from writei: %s\n",
              snd_strerror(rc_s));
    }  else if (rc_s != (int)frames) {
      fprintf(stderr,
              "short write, write %d frames\n", rc_s);
    }
  }

  snd_pcm_drain(handle_s);
  snd_pcm_close(handle_s);
  free(buffer_s);
  return true;
}
开发者ID:jolygit,项目名称:code,代码行数:30,代码来源:soundProcessor.cpp


示例17: snd_pcm_drain

CMAlsaAudioSink::~CMAlsaAudioSink()
{
    if (handle) {
        snd_pcm_drain(handle);
        snd_pcm_close(handle);
    }
}
开发者ID:oniongarlic,项目名称:qtsidplayer-test,代码行数:7,代码来源:cmalsaaudiosink.cpp


示例18: sound_close

void sound_close() {

	switch(sound_type) {
	case SOUND_NO:
	break;
	case SOUND_SDL:
	SDL_CloseAudio();
	break;
#ifdef D_SOUND_OSS
	case SOUND_OSS:
		close(audio_fd);
	break;
#endif
#ifdef D_SOUND_ALSA
	case SOUND_ALSA:
		snd_pcm_drain (_soundDevice);
		snd_pcm_close (_soundDevice);
	break;
#endif
#ifdef D_SOUND_PULSE
	case SOUND_PULSEAUDIO:
		pa_simple_free(pulse_s);
	break;
#endif
#ifdef GEKKO
	case SOUND_ASND:
		ASND_End();
	break;
#endif

	default:
	break;
	}
}
开发者ID:Oibaf66,项目名称:fbzx-wii,代码行数:34,代码来源:sound.c


示例19: snd_pcm_drain

void AlsaRenderer::Close()
{
    if (m_PcmHandle != nullptr) {
        snd_pcm_drain(m_PcmHandle);
        snd_pcm_close(m_PcmHandle);
        m_PcmHandle = nullptr;
    }
}
开发者ID:ClarkWang12,项目名称:mous,代码行数:8,代码来源:AlsaRenderer.cpp


示例20: pcm_player_free

void pcm_player_free(pcm_player *player)
{
    snd_pcm_drain(player->pcm_handle);
    snd_pcm_close(player->pcm_handle);

    free(player->buffer);
    free(player);
}
开发者ID:physacco,项目名称:asobi,代码行数:8,代码来源:libplaypcm.c



注:本文中的snd_pcm_drain函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ snd_pcm_format_physical_width函数代码示例发布时间:2022-05-30
下一篇:
C++ snd_pcm_delay函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap