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

C++ snd_pcm_hw_params_set_period_size_near函数代码示例

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

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



在下文中一共展示了snd_pcm_hw_params_set_period_size_near函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: setparams_bufsize

int setparams_bufsize(snd_pcm_t *handle,
		      snd_pcm_hw_params_t *params,
		      snd_pcm_hw_params_t *tparams,
		      snd_pcm_uframes_t bufsize,
		      const char *id)
{
	int err;
	snd_pcm_uframes_t periodsize;

	snd_pcm_hw_params_copy(params, tparams);
	periodsize = bufsize * 2;
	err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &periodsize);
	if (err < 0) {
		printf("Unable to set buffer size %li for %s: %s\n", bufsize * 2, id, snd_strerror(err));
		return err;
	}
	if (period_size > 0)
		periodsize = period_size;
	else
		periodsize /= 2;
	err = snd_pcm_hw_params_set_period_size_near(handle, params, &periodsize, 0);
	if (err < 0) {
		printf("Unable to set period size %li for %s: %s\n", periodsize, id, snd_strerror(err));
		return err;
	}
	return 0;
}
开发者ID:CarbonDev,项目名称:android_device_motorola_solana,代码行数:27,代码来源:latency.c


示例2: start_snd_device

//open a sound device with specified period, rate, channels(0=mono,1=stereo or MONO_SOUND/STEREO_SOUND) 
//  and direction(0=playback,1=capture), returns the buffer (also PLAYBACK_DIR/CAPTURE_DIR)
snd_pcm_t* start_snd_device(size_t period, unsigned int rate, int stereo, int direction){
  //Open PCM device for playback/capture, check for errors
  snd_pcm_t *pcm_handle; //handler struct
  int dir = (direction)? SND_PCM_STREAM_CAPTURE:SND_PCM_STREAM_PLAYBACK;
  int rc = snd_pcm_open(&pcm_handle, "default",dir, 0);
  if (rc < 0){ //make sure it landed
    fprintf(stderr,"unable to open pcm device: %s\n",snd_strerror(rc));
    return 0; //return null pointer
  }

  //Setup the hardware parameters
  snd_pcm_hw_params_t *params;  //create pointer
  snd_pcm_hw_params_alloca(&params); //allocate struct
  snd_pcm_hw_params_any(pcm_handle, params); //fill with defaults
  snd_pcm_hw_params_set_access(pcm_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); //interleaved mode
  snd_pcm_hw_params_set_format(pcm_handle, params, SND_PCM_FORMAT_S16_LE); //signed 16-bit LE
  snd_pcm_hw_params_set_channels(pcm_handle, params, (stereo+1)); //stereo mode
  unsigned int rate2 = rate; //copy rate (will be overwritten on mismatch)
  int err_dir = 0; //try to set rate exactly
  snd_pcm_hw_params_set_rate_near(pcm_handle, params, &rate2, &err_dir); //get closest match
  if(rate != rate2) printf("Rate mismatch, %d give, %d set\n",rate,rate2);
  size_t frames = period; //once again,copy value in case of mismatch
  snd_pcm_hw_params_set_period_size_near(pcm_handle, params, &period, &dir); //set the period
  if(period != frames) printf("Period size mismatch, %d given, %d set", (int)period, (int)frames);
 
  //Write the parameters to the driver
  rc = snd_pcm_hw_params(pcm_handle, params);
  if (rc < 0){ //make sure it landed
    fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(rc));
    return 0; //return null
  }
  
  return pcm_handle;
}
开发者ID:jpanikulam,项目名称:visar,代码行数:36,代码来源:sound.c


示例3: audio_renderer_init

static void audio_renderer_init() {
  int rc;
  decoder = opus_decoder_create(SAMPLE_RATE, CHANNEL_COUNT, &rc);

  snd_pcm_hw_params_t *hw_params;
  snd_pcm_sw_params_t *sw_params;
  snd_pcm_uframes_t period_size = FRAME_SIZE * CHANNEL_COUNT * 2;
  snd_pcm_uframes_t buffer_size = 12 * period_size;
  unsigned int sampleRate = SAMPLE_RATE;

  /* Open PCM device for playback. */
  CHECK_RETURN(snd_pcm_open(&handle, audio_device, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK))

  /* Set hardware parameters */
  CHECK_RETURN(snd_pcm_hw_params_malloc(&hw_params));
  CHECK_RETURN(snd_pcm_hw_params_any(handle, hw_params));
  CHECK_RETURN(snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED));
  CHECK_RETURN(snd_pcm_hw_params_set_format(handle, hw_params, SND_PCM_FORMAT_S16_LE));
  CHECK_RETURN(snd_pcm_hw_params_set_rate_near(handle, hw_params, &sampleRate, NULL));
  CHECK_RETURN(snd_pcm_hw_params_set_channels(handle, hw_params, CHANNEL_COUNT));
  CHECK_RETURN(snd_pcm_hw_params_set_buffer_size_near(handle, hw_params, &buffer_size));
  CHECK_RETURN(snd_pcm_hw_params_set_period_size_near(handle, hw_params, &period_size, NULL));
  CHECK_RETURN(snd_pcm_hw_params(handle, hw_params));
  snd_pcm_hw_params_free(hw_params);

  /* Set software parameters */
  CHECK_RETURN(snd_pcm_sw_params_malloc(&sw_params));
  CHECK_RETURN(snd_pcm_sw_params_current(handle, sw_params));
  CHECK_RETURN(snd_pcm_sw_params_set_start_threshold(handle, sw_params, buffer_size - period_size));
  CHECK_RETURN(snd_pcm_sw_params_set_avail_min(handle, sw_params, period_size));
  CHECK_RETURN(snd_pcm_sw_params(handle, sw_params));
  snd_pcm_sw_params_free(sw_params);

  CHECK_RETURN(snd_pcm_prepare(handle));
}
开发者ID:Tri125,项目名称:moonlight-embedded,代码行数:35,代码来源:audio.c


示例4: nv_alsa_init

int nv_alsa_init(unsigned int channelCount, unsigned int sampleRate, unsigned char* device) {
	int rc;
	snd_pcm_hw_params_t *params;
	int dir;
	
	/* Open PCM device for playback. */
	if ((rc = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) != 0)
		return rc;
	
	snd_pcm_hw_params_alloca(&params);
	snd_pcm_hw_params_any(handle, params);
	
	if ((rc = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED)) != 0)
                return rc;

	if ((rc = snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE)) != 0)
                return rc;

	if ((rc = snd_pcm_hw_params_set_channels(handle, params, channelCount)) != 0)
                return rc;

	if ((rc = snd_pcm_hw_params_set_rate_near(handle, params, &sampleRate, &dir)) != 0)
                return rc;
	
	snd_pcm_uframes_t frames = 32;
	if ((rc = snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir)) != 0)
		return rc;
	
	if ((rc = snd_pcm_hw_params(handle, params)) != 0)
		return rc;
}
开发者ID:syc0n,项目名称:limelight-pi,代码行数:31,代码来源:nv_alsa.c


示例5: snd_pcm_hw_params_alloca

	// Set device parameters.
	MapilVoid ALSASoundDevice::SetParam( PCMDevConf* pConf )
	{
		_snd_pcm_format pcmFmt[] = {	SND_PCM_FORMAT_UNKNOWN,
										SND_PCM_FORMAT_U8,
										SND_PCM_FORMAT_S8,
										SND_PCM_FORMAT_U16_LE,
										SND_PCM_FORMAT_U16_BE,
										SND_PCM_FORMAT_S16_LE,
										SND_PCM_FORMAT_S16_BE };

		// Allocate hardware parameter.
		snd_pcm_hw_params_alloca( &m_pParam );
		// Get default hardware parameter.
		snd_pcm_hw_params_any( m_pHandle, m_pParam );

		// Set parameters.
		snd_pcm_hw_params_set_access( m_pHandle, m_pParam, SND_PCM_ACCESS_RW_INTERLEAVED );
		snd_pcm_hw_params_set_format( m_pHandle, m_pParam, pcmFmt[ pConf->m_Fmt ] );
		snd_pcm_hw_params_set_channels( m_pHandle, m_pParam, pConf->m_Channel );
		MapilInt32 val;
		snd_pcm_hw_params_set_rate_near( m_pHandle, m_pParam, &pConf->m_Freq, &val );
		snd_pcm_uframes_t frame = 32;
		snd_pcm_hw_params_set_period_size_near( m_pHandle, m_pParam, &frame, &val );

		if( snd_pcm_hw_params( m_pHandle, m_pParam ) < 0 ){
			exit( 1 );
		}
	}
开发者ID:nutti,项目名称:MAPIL,代码行数:29,代码来源:ALSASoundDevice.cpp


示例6: audio_init

void* audio_init(int sampling_rate)
{
    syslog(LOG_INFO, "ALSA: audio_set_driver: this sets the PCM device to :%s\n",g_card);
#ifdef DEBUGALSA
    syslog(LOG_DEBUG,"ALSA: Sample rate proposed %d\n",sampling_rate);
#endif
    int rc, dir = 0;
    snd_pcm_uframes_t frames = 32;
//    rc = snd_pcm_open(&alsa_handle, g_card, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
    rc = snd_pcm_open(&alsa_handle, g_card, SND_PCM_STREAM_PLAYBACK, 0);
    if (rc < 0) {
        syslog(LOG_ERR, "unable to open pcm device: %s\n", snd_strerror(rc));
        die("alsa initialization failed");
    }
    snd_pcm_hw_params_alloca(&alsa_params);
    snd_pcm_hw_params_any(alsa_handle, alsa_params);
    snd_pcm_hw_params_set_access(alsa_handle, alsa_params, SND_PCM_ACCESS_RW_INTERLEAVED);
    snd_pcm_hw_params_set_format(alsa_handle, alsa_params, SND_PCM_FORMAT_S16);
    snd_pcm_hw_params_set_channels(alsa_handle, alsa_params, NUM_CHANNELS);
    snd_pcm_hw_params_set_rate_near(alsa_handle, alsa_params, (unsigned int *)&sampling_rate, &dir);
#ifdef DEBUGALSA
    syslog(LOG_DEBUG,"ALSA: Sample rate gotten %d\n",sampling_rate);
#endif
    snd_pcm_hw_params_set_period_size_near(alsa_handle, alsa_params, &frames, &dir);
    rc = snd_pcm_hw_params(alsa_handle, alsa_params);
    if (rc < 0) {
        syslog(LOG_ERR, "unable to set hw parameters: %s\n", snd_strerror(rc));
        die("alsa initialization failed");
    }

    return alsa_handle;
}
开发者ID:mikejuni,项目名称:shairport,代码行数:32,代码来源:audio_alsa.c


示例7: audio_init

void audio_init(void)
{
    int ret, dir;
    unsigned int rate;
    snd_pcm_hw_params_t * params;

    rate = 44100;
    frames = 32;
    ret = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);

    if (ret < 0)
    {
        fprintf(stderr, "Unable to open pcm device: %s\n", snd_strerror(ret));
        exit(EXIT_FAILURE);
    }

    snd_pcm_hw_params_alloca(&params);
    snd_pcm_hw_params_any(handle, params);
    snd_pcm_hw_params_set_access(handle, params, 
            SND_PCM_ACCESS_RW_INTERLEAVED);
    snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);
    snd_pcm_hw_params_set_channels(handle, params, 2);
    snd_pcm_hw_params_set_rate_near(handle, params, &rate, &dir);
    snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir);

    ret = snd_pcm_hw_params(handle, params);
    
    if (ret < 0)
    {
        fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(ret));
        exit(EXIT_FAILURE);
    }

    snd_pcm_hw_params_get_period_size(params, &frames, &dir);
}
开发者ID:alyx,项目名称:metrodwarf,代码行数:35,代码来源:alsa.c


示例8: alsa_set_hw_params

static void alsa_set_hw_params(struct alsa_dev *dev, snd_pcm_t *handle,
			       unsigned int rate, int channels, int period)
{
	int dir, ret;
	snd_pcm_uframes_t period_size;
	snd_pcm_uframes_t buffer_size;
	snd_pcm_hw_params_t *hw_params;

	ret = snd_pcm_hw_params_malloc(&hw_params);
	if (ret < 0)
		syslog_panic("Cannot allocate hardware parameters: %s\n",
			     snd_strerror(ret));
	ret = snd_pcm_hw_params_any(handle, hw_params);
	if (ret < 0)
		syslog_panic("Cannot initialize hardware parameters: %s\n",
			     snd_strerror(ret));
	ret = snd_pcm_hw_params_set_access(handle, hw_params,
					   SND_PCM_ACCESS_RW_INTERLEAVED);
	if (ret < 0)
		syslog_panic("Cannot set access type: %s\n",
			     snd_strerror(ret));
	ret = snd_pcm_hw_params_set_format(handle, hw_params,
					   SND_PCM_FORMAT_S16_LE);
	if (ret < 0)
		syslog_panic("Cannot set sample format: %s\n",
			     snd_strerror(ret));
	ret = snd_pcm_hw_params_set_rate_near(handle, hw_params, &rate, 0);
	if (ret < 0)
		syslog_panic("Cannot set sample rate: %s\n",
			     snd_strerror(ret));
	ret = snd_pcm_hw_params_set_channels(handle, hw_params, channels);
	if (ret < 0)
		syslog_panic("Cannot set channel number: %s\n",
			     snd_strerror(ret));
	period_size = period;
	dir = 0;
	ret = snd_pcm_hw_params_set_period_size_near(handle, hw_params,
						     &period_size, &dir);
	if (ret < 0)
		syslog_panic("Cannot set period size: %s\n",
			     snd_strerror(ret));
	ret = snd_pcm_hw_params_set_periods(handle, hw_params, PERIODS, 0);
	if (ret < 0)
		syslog_panic("Cannot set period number: %s\n",
			     snd_strerror(ret));
	buffer_size = period_size * PERIODS;
	dir = 0;
	ret = snd_pcm_hw_params_set_buffer_size_near(handle, hw_params,
						     &buffer_size);
	if (ret < 0)
		syslog_panic("Cannot set buffer size: %s\n",
			     snd_strerror(ret));
	ret = snd_pcm_hw_params(handle, hw_params);
	if (ret < 0)
		syslog_panic("Cannot set capture parameters: %s\n",
			     snd_strerror(ret));
	snd_pcm_hw_params_free(hw_params);
}
开发者ID:ipoerner,项目名称:transsip,代码行数:58,代码来源:alsa.c


示例9: snd_pcm_open

bool SoundProcessor::SetUpRecorder(){
  rc_m = snd_pcm_open(&handle_m, "default",
                    SND_PCM_STREAM_CAPTURE, 0);
  if (rc_m < 0) {
    fprintf(stderr,
            "unable to open pcm device: %s\n",
            snd_strerror(rc_m));
    exit(1);
  }

  /* Allocate a hardware parameters object. */
  snd_pcm_hw_params_alloca(&params_m);

  /* Fill it in with default values. */
  snd_pcm_hw_params_any(handle_m, params_m);

  /* Set the desired hardware parameters. */

  /* Interleaved mode */
  snd_pcm_hw_params_set_access(handle_m, params_m,
                      SND_PCM_ACCESS_RW_INTERLEAVED);

  /* Signed 16-bit little-endian format */
  snd_pcm_hw_params_set_format(handle_m, params_m,
                              SND_PCM_FORMAT_U8);

  /* Two channels (stereo) */
  snd_pcm_hw_params_set_channels(handle_m, params_m, 1);

  /* 44100 bits/second sampling rate (CD quality) */
  val_m = 8000;
  snd_pcm_hw_params_set_rate_near(handle_m, params_m,
                                  &val_m, &dir_m);

  /* Set period size to 32 frames. */
  //frames = 32;
  snd_pcm_hw_params_set_period_size_near(handle_m,
                              params_m, &frames, &dir_m);

  /* Write the parameters to the driver */
  rc_m = snd_pcm_hw_params(handle_m, params_m);
  if (rc_m < 0) {
    fprintf(stderr,
            "unable to set hw parameters: %s\n",
            snd_strerror(rc_m));
    exit(1);
  }

  /* Use a buffer large enough to hold one period */
  snd_pcm_hw_params_get_period_size(params_m,
                                      &frames, &dir_m);
  size = frames; /* 2 bytes/sample, 2 channels */
  buffer_m = (char *) malloc(size);
  /* We want to loop for 5 seconds */
  snd_pcm_hw_params_get_period_time(params_m,
                                         &val_m, &dir_m);
  return true;
}
开发者ID:jolygit,项目名称:code,代码行数:58,代码来源:soundProcessor.cpp


示例10: snd_pcm_open

void Recorder::initRecoder()
{
    int rc;
    snd_pcm_hw_params_t *params;
    unsigned int val;
    int dir=0;
    /* Open PCM device for recording (capture). */
    rc = snd_pcm_open(&handle, "default",SND_PCM_STREAM_CAPTURE, 0);
    if (rc < 0) {
        fprintf(stderr,"unable to open pcm device: %s\n",snd_strerror(rc));
        exit(1);
    }

    /* Allocate a hardware parameters object. */
    snd_pcm_hw_params_alloca(&params);

    /* Fill it in with default values. */
    snd_pcm_hw_params_any(handle, params);

    /* Set the desired hardware parameters. */

    /* Interleaved mode */
    snd_pcm_hw_params_set_access(handle, params,
                          SND_PCM_ACCESS_RW_INTERLEAVED);

    /* Signed 16-bit little-endian format */
    snd_pcm_hw_params_set_format(handle, params,SND_PCM_FORMAT_S16_LE);

    /* Two channels (stereo) */
    snd_pcm_hw_params_set_channels(handle, params, CHANNELS);

    /* 44100 bits/second sampling rate (CD quality) */
    val = SAMPLERATE;
    snd_pcm_hw_params_set_rate_near(handle, params,
                                      &val, &dir);

    /* Set period size to 32 frames. */
    frames = 32;
    snd_pcm_hw_params_set_period_size_near(handle,
                                  params, &frames, &dir);

    /* Write the parameters to the driver */
    rc = snd_pcm_hw_params(handle, params);
    if (rc < 0)
    {
        fprintf(stderr,"unable to set hw parameters: %s\n",snd_strerror(rc));
        exit(1);
    }

    /* Use a buffer large enough to hold one period */
    snd_pcm_hw_params_get_period_size(params,&frames, &dir);
    size = frames * 2; /* 2 bytes/sample, 2 channels */

    /* We want to loop for 5 seconds */
    snd_pcm_hw_params_get_period_time(params,&val, &dir);
    //loops = 5000000 / val;  //获取5秒中所对应的loop这里用不到

}
开发者ID:asdfjkl697,项目名称:projects,代码行数:58,代码来源:recorder.cpp


示例11: audio_capture_init

int audio_capture_init(char *audio_dev)
{
	unsigned int val;
	int dir, rc, size;

	/* Open PCM device for recording (capture). */
	rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_CAPTURE, 0);
	if (rc < 0) {
		fprintf(stderr, "unable to open pcm device: %s\n", snd_strerror(rc));
		return -1;
	}

	/* Allocate a hardware parameters object. */
	snd_pcm_hw_params_alloca(&hw_params);

	/* Fill it in with default values. */
	snd_pcm_hw_params_any(handle, hw_params);

	/* Set the desired hardware parameters. */

	/* Interleaved mode */
	snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);

	/* Signed 16-bit little-endian format */
	snd_pcm_hw_params_set_format(handle, hw_params, SND_PCM_FORMAT_S16_LE);

	/* 1 channel mono */
	snd_pcm_hw_params_set_channels(handle, hw_params, 1);

	/* 44100 bits/second sampling rate (CD quality) */
	val = 44100;
	snd_pcm_hw_params_set_rate_near(handle, hw_params, &val, &dir);

	/* Set period size to 32 frames. */
	frames = 32;
	snd_pcm_hw_params_set_period_size_near(handle, hw_params, &frames, &dir);

	/* Write the parameters to the driver */
	rc = snd_pcm_hw_params(handle, hw_params);
	if (rc < 0) {
		fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(rc));
		return -1;
	}

	/* Use a buffer large enough to hold one period */
	snd_pcm_hw_params_get_period_size(hw_params, &frames, &dir);
	size = frames * 4;	/* 2 bytes/sample, 2 channels */
	frame_buffer = (char *) malloc(size);
	printf("- Allocated %d bytes frame buffer\n", size);

	snd_pcm_hw_params_get_period_time(hw_params, &val, &dir);

	return 0;
}
开发者ID:tiberig,项目名称:aprsdump,代码行数:54,代码来源:audio_capture.c


示例12: set_hwparams

void set_hwparams(snd_pcm_t *phandle)
{
	int err;
	snd_pcm_hw_params_t *params;

	err = snd_output_stdio_attach(&log, stderr, 0);
	if (err < 0) {
		fprintf(stderr, "cannot attach output stdio\n");
		exit(0);
	}

	snd_pcm_hw_params_alloca(&params);
	err = snd_pcm_hw_params_any(phandle, params);
	if (err < 0) {
		fprintf(stderr, "Broken configuration for this PCM: no configurations available\n");
		exit(0);
	}

	err = snd_pcm_hw_params_set_access(phandle, params,
					   SND_PCM_ACCESS_RW_INTERLEAVED);
	if (err < 0) {
		fprintf(stderr, "Access type not available\n");
		exit(0);
	}
	err = snd_pcm_hw_params_set_format(phandle, params, SND_PCM_FORMAT_S16_LE);
	if (err < 0) {
		fprintf(stderr, "cannot set format\n");
		exit(0);
	}
	err = snd_pcm_hw_params_set_channels(phandle, params, 2);
	if (err < 0) {
		fprintf(stderr, "cannot set channels 2\n");
		exit(0);
	}
	err = snd_pcm_hw_params_set_rate_near(phandle, params, 44100, 0);
	if (err < 0) {
		fprintf(stderr, "cannot set rate\n");
		exit(0);
	}
	err = snd_pcm_hw_params_set_period_size_near(phandle, params, period_size);
	if (err < 0) {
		fprintf(stderr, "cannot set period size\n");
		exit(0);
	}
	err = snd_pcm_hw_params(phandle, params);
	if (err < 0) {
		fprintf(stderr, "Unable to install hw params:\n");
		exit(0);
	}
	snd_pcm_hw_params_dump(params, log);
}
开发者ID:Ace-III-Dev,项目名称:android_device_samsung_bcm_common_alsa-lib,代码行数:51,代码来源:seq-sender.c


示例13: init_alsa_play

/****************************************************************************************
*   函数名: init_alsa_play
*   输  入: 无
*   输  出: 无
*   功能说明:alsa音频播放器初始化
*
*       
******************************************************************************************/
void init_alsa_play()
{
		snd_pcm_hw_params_t *params; 
		unsigned int val; 
		int dir; 
				
		/* Open PCM device for playback. */
		rc=snd_pcm_open(&handle,"plughw:0,0", SND_PCM_STREAM_PLAYBACK, 0);
		if (rc< 0) 
		{ 
			fprintf(stderr,  "unable to open pcm device: %s\n",    snd_strerror(rc));
			exit(1); 
		} 
		 
		/* Allocate a hardware parameters object. */
		 snd_pcm_hw_params_alloca(&params); 
		/* Fill it in with default values. */
		 snd_pcm_hw_params_any(handle, params);
		 /* Set the desired hardware parameters. */ 

		/* Interleaved mode */ 
		snd_pcm_hw_params_set_access(handle,params, SND_PCM_ACCESS_RW_INTERLEAVED); 

		/* Signed 16-bit little-endian format 格式*/ 
		snd_pcm_hw_params_set_format(handle,params, SND_PCM_FORMAT_S16_LE); 


		/* Two channels (stereo) 声道*/  
		snd_pcm_hw_params_set_channels(handle, params, channels); 
		/* 32000 bits/second sampling rate (CD quality) 采样率设置*/ 
		snd_pcm_hw_params_set_rate_near(handle,params, &rate, &dir);  /* Set period size to 32 frames. */ 
		frames = SAMPLERATE/1000*READMSFORONCE; 
		snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir);
		/* Write the parameters to the driver */
		 rc = snd_pcm_hw_params(handle, params);
		 if (rc < 0) 
		 {   
				fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(rc));   
				exit(1); 
		}

		/*Use a buffer large enough to hold one period*/
		snd_pcm_hw_params_get_period_size(params, &frames,  &dir); //32个采样点算一帧
		size = frames * (channels);
		/* 2 bytes/sample, 2 channels */ 
		buffer = (char *) malloc(size); 
		/* We want to loop for 5 seconds */
		snd_pcm_hw_params_get_period_time(params, &val, &dir); 
}
开发者ID:naeems,项目名称:bkvoice,代码行数:57,代码来源:simple_speex_dec.c


示例14: carmen_sound_set_device_parameters

void
carmen_sound_set_device_parameters(snd_pcm_t *handle, int sampling_rate, int num_frames)
{
	int rc, dir;
	unsigned int val;
	snd_pcm_hw_params_t *params;
	snd_pcm_uframes_t frames;

	val = sampling_rate;
	frames = (snd_pcm_uframes_t) num_frames;

	/* Allocate a hardware parameters object. */
	snd_pcm_hw_params_alloca(&params);

	/* Fill it in with default values. */
	snd_pcm_hw_params_any(handle, params);

	/* Interleaved mode */
	snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);

	/* Signed 16-bit little-endian format */
	snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);

	/* Two channels (stereo) */
	snd_pcm_hw_params_set_channels(handle, params, 2);

	/* set bits/second sampling rate */
	snd_pcm_hw_params_set_rate_near(handle, params, &val, &dir);

	/* Set period size to num of frames. */
	snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir);

	/* Write the parameters to the driver */
	rc = snd_pcm_hw_params(handle, params);

	if (rc < 0)
		exit(printf("unable to set hw parameters: %s\n", snd_strerror(rc)));

	/* Use a buffer large enough to hold one period */
	snd_pcm_hw_params_get_period_size(params, &frames, &dir);

	/* We want to loop for 5 seconds */
	snd_pcm_hw_params_get_period_time(params, &val, &dir);

	// @TODO: pesquisar por que tem que ler um pouco que vem vazio nao sei por que...
	char buffer[4 * 32];
	rc = snd_pcm_readi(handle, buffer, 32);
}
开发者ID:ulyssesrr,项目名称:carmen_lcad,代码行数:48,代码来源:sound.c


示例15: snd_pcm_open

void AudioWalkera::setupAlsa(){

	int dir;

	int t = 0, i, c;

	rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_CAPTURE, 0);

	if(rc < 0)
		exitError("Could not open pcm device");

	snd_pcm_hw_params_alloca(&params);
	//rc = setupHardware(handle, params, &dir);


	snd_pcm_uframes_t frames_inner;
	unsigned int val;

	snd_pcm_hw_params_any(handle, params);

	snd_pcm_hw_params_set_access(handle, params, 
			SND_PCM_ACCESS_RW_INTERLEAVED);

	snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);

	snd_pcm_hw_params_set_channels(handle, params, 1);


	val = 48000;
	snd_pcm_hw_params_set_rate_near(handle, params, &val, &dir);

	frames_inner = 2304;
	snd_pcm_hw_params_set_period_size_near(handle, params, &frames_inner, &dir);

	rc = snd_pcm_hw_params(handle, params);
 

	if(rc < 0)
		exitError("Could not set hardware parameters");

	snd_pcm_hw_params_get_period_size(params, &frames, &dir);

	buffer = (short*) calloc(frames, sizeof(short));


}
开发者ID:hitcher404,项目名称:AudioWalkera,代码行数:46,代码来源:audiowalkera.cpp


示例16: sound_init

int
sound_init ()
{
  int rc;

  rc = snd_pcm_open (&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
  if (rc < 0)
    {
      fprintf (stderr, "unable to open pcm device: %s\n", snd_strerror (rc));
      return rc;
    }

  g_paused = 0;

  snd_pcm_hw_params_alloca (&params);

  snd_pcm_hw_params_any (handle, params);

  snd_pcm_hw_params_set_access (handle, params,
				SND_PCM_ACCESS_RW_INTERLEAVED);

  snd_pcm_hw_params_set_format (handle, params, SND_PCM_FORMAT_S16_LE);

  snd_pcm_hw_params_set_channels (handle, params, CHANNELS);

  val = RATE;
  snd_pcm_hw_params_set_rate_near (handle, params, &val, &dir);

  frames = FRAMES;
  snd_pcm_hw_params_set_period_size_near (handle, params, &frames, &dir);

  rc = snd_pcm_hw_params (handle, params);
  if (rc < 0)
    return rc;

  snd_pcm_hw_params_get_period_size (params, &frames, &dir);

  snd_pcm_hw_params_get_period_time (params, &val, &dir);

  return 0;
}
开发者ID:giuseppe,项目名称:shpotify,代码行数:41,代码来源:alsa.c


示例17: start

static void start(int sample_rate) {
    if (sample_rate != 44100)
        die("Unexpected sample rate!");

    int ret, dir = 0;
    snd_pcm_uframes_t frames = 64;
    ret = snd_pcm_open(&alsa_handle, alsa_out_dev, SND_PCM_STREAM_PLAYBACK, 0);
    if (ret < 0)
        die("Alsa initialization failed: unable to open pcm device: %s\n", snd_strerror(ret));

    snd_pcm_hw_params_alloca(&alsa_params);
    snd_pcm_hw_params_any(alsa_handle, alsa_params);
    snd_pcm_hw_params_set_access(alsa_handle, alsa_params, SND_PCM_ACCESS_RW_INTERLEAVED);
    snd_pcm_hw_params_set_format(alsa_handle, alsa_params, SND_PCM_FORMAT_S16);
    snd_pcm_hw_params_set_channels(alsa_handle, alsa_params, 2);
    snd_pcm_hw_params_set_rate_near(alsa_handle, alsa_params, (unsigned int *)&sample_rate, &dir);
    snd_pcm_hw_params_set_period_size_near(alsa_handle, alsa_params, &frames, &dir);
    ret = snd_pcm_hw_params(alsa_handle, alsa_params);
    if (ret < 0)
        die("unable to set hw parameters: %s\n", snd_strerror(ret));
}
开发者ID:ATgeir,项目名称:shairport,代码行数:21,代码来源:audio_alsa.c


示例18: SoundOutput_Impl

SoundOutput_alsa::SoundOutput_alsa(int mixing_frequency, int mixing_latency) :
	SoundOutput_Impl(mixing_frequency, mixing_latency), frames_in_buffer(4096),
	frames_in_period(1024)
{
	int rc;
	snd_pcm_hw_params_t *hwparams;
	
	rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
	if (rc < 0)
	{
		log_event("warn", "ClanSound: Couldn't open sound device, disabling sound");
		handle = nullptr;
		return;
	}

	snd_pcm_hw_params_alloca(&hwparams);
	snd_pcm_hw_params_any(handle, hwparams);
	snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
	snd_pcm_hw_params_set_format(handle, hwparams, SND_PCM_FORMAT_FLOAT);
	snd_pcm_hw_params_set_channels(handle, hwparams, 2);
	snd_pcm_hw_params_set_rate_near(handle, hwparams,
				(unsigned int *)&this->mixing_frequency, nullptr);
	snd_pcm_hw_params_set_buffer_size_near(handle, hwparams, &frames_in_buffer);
	frames_in_period = frames_in_buffer / 4;
	snd_pcm_hw_params_set_period_size_near(handle, hwparams, &frames_in_period, nullptr);
	
	rc = snd_pcm_hw_params(handle, hwparams);
	if (rc < 0)
	{
		log_event("warn", "ClanSound: Couldn't initialize sound device, disabling sound");
		snd_pcm_close(handle);
		handle = nullptr;
		return;
	}
	
	snd_pcm_hw_params_get_period_size(hwparams, &frames_in_period, nullptr);

	start_mixer_thread();
}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:39,代码来源:soundoutput_alsa.cpp


示例19: sound_info_record_new

// 声卡采集初始化
struct SoundInfo* sound_info_record_new() {
    struct SoundInfo *info = (struct SoundInfo*)malloc(sizeof(struct SoundInfo));
    int rc;
    int dir = 0;

    info->channels = 2; 
    info->frequency = 44100;

    rc = snd_pcm_open(&info->handle, "default", SND_PCM_STREAM_CAPTURE, 0);

    snd_pcm_hw_params_alloca(&info->params);

    rc = snd_pcm_hw_params_any(info->handle, info->params);

    rc = snd_pcm_hw_params_set_access(info->handle, info->params, SND_PCM_ACCESS_RW_INTERLEAVED);

    snd_pcm_hw_params_set_format(info->handle, info->params, SND_PCM_FORMAT_S16_LE);

    rc = snd_pcm_hw_params_set_channels(info->handle, info->params, info->channels);

    unsigned int val = info->frequency;
    rc = snd_pcm_hw_params_set_rate_near(info->handle, info->params, &val, &dir);

    rc = snd_pcm_hw_params(info->handle, info->params);

    info->frames = 32;//"frames"=channel*size/8=4, frames = "frames"*8 one period contains 8 "frames"    
    snd_pcm_hw_params_set_period_size_near(info->handle, info->params, &info->frames, &dir);

    rc = snd_pcm_hw_params(info->handle, info->params);

    snd_pcm_hw_params_get_period_size(info->params, &info->frames, &dir);

    info->bufferSize = info->frames * 4;
    info->buffer = (char*) malloc(info->bufferSize);
    snd_pcm_hw_params_get_period_time(info->params, &val, &dir);
    memset(info->buffer, 0, info->bufferSize);

    return info;
}
开发者ID:chenshuchao,项目名称:c_chat,代码行数:40,代码来源:sound.c


示例20: card

    optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::DefaultAsInt(std::map<String,String> Parameters) {
        if (!Parameters.count("CARD")) return optional<int>::nothing;

        // obtain information from given sound card
        ParameterCard card(Parameters["CARD"]);
        String pcm_name = "hw:" + card.ValueAsString();
        snd_pcm_t* pcm_handle = NULL;
        if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing;
        snd_pcm_hw_params_t* hwparams;
        snd_pcm_hw_params_alloca(&hwparams);
        if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) {
            snd_pcm_close(pcm_handle);
            return optional<int>::nothing;
        }
        snd_pcm_uframes_t size = 128;
        if (snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &size, NULL) < 0) {
            snd_pcm_close(pcm_handle);
            return optional<int>::nothing;
        }
        snd_pcm_close(pcm_handle);
        return size;
    }
开发者ID:lxlxlo,项目名称:LS-linuxsampler,代码行数:22,代码来源:AudioOutputDeviceAlsa.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ snd_pcm_hw_params_set_period_time_near函数代码示例发布时间:2022-05-30
下一篇:
C++ snd_pcm_hw_params_set_format函数代码示例发布时间: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