当前位置: 首页>>代码示例>>C++>>正文


C++ snd_pcm_hw_params_malloc函数代码示例

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


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

示例1: BH_TRACE_INIT

void SoundPlayer::main()
{
  BH_TRACE_INIT("SoundPlayer");
  unsigned i;
  for(i = 0; i < retries; ++i)
  {
    if(snd_pcm_open(&handle, "hw:0", SND_PCM_STREAM_PLAYBACK, 0) >= 0)
      break;
    Thread::sleep(retryDelay);
  }
  ASSERT(i < retries);
  snd_pcm_hw_params_t* params;
  VERIFY(!snd_pcm_hw_params_malloc(&params));
  VERIFY(!snd_pcm_hw_params_any(handle, params));
  VERIFY(!snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED));
  VERIFY(!snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE));
  VERIFY(!snd_pcm_hw_params_set_rate_near(handle, params, &sampleRate, 0));;
  VERIFY(!snd_pcm_hw_params_set_channels(handle, params, 2));
  VERIFY(!snd_pcm_hw_params(handle, params));
  VERIFY(!snd_pcm_hw_params_get_period_size(params, &periodSize, 0));
  snd_pcm_hw_params_free(params);

  while(isRunning() && !closing)
  {
    flush();
    VERIFY(sem.wait());
  }
  VERIFY(!snd_pcm_close(handle));
}
开发者ID:weilandetian,项目名称:Yoyo,代码行数:29,代码来源:SoundPlayer.cpp

示例2: snd_pcm_stream_t

AudioProvider::AudioProvider()
{
  allChannels ? channels = 4 : channels = 2;
  int brokenFirst = (theDamageConfigurationHead.audioChannelsDefect[0] ? 1 : 0) + (theDamageConfigurationHead.audioChannelsDefect[1] ? 1 : 0);
  int brokenSecond = (theDamageConfigurationHead.audioChannelsDefect[2] ? 1 : 0) + (theDamageConfigurationHead.audioChannelsDefect[3] ? 1 : 0);
  unsigned i;
  for(i = 0; i < retries; ++i)
  {
    if(snd_pcm_open(&handle, allChannels ? "4channelsDeinterleaved" : brokenFirst > brokenSecond ? "hw:0,0,1" : "hw:0",
                    snd_pcm_stream_t(SND_PCM_STREAM_CAPTURE | SND_PCM_NONBLOCK), 0) >= 0)
      break;
    Thread::sleep(retryDelay);
  }
  ASSERT(i < retries);

  snd_pcm_hw_params_t* params;
  VERIFY(!snd_pcm_hw_params_malloc(&params));
  VERIFY(!snd_pcm_hw_params_any(handle, params));
  VERIFY(!snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED));
  VERIFY(!snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE));
  VERIFY(!snd_pcm_hw_params_set_rate_near(handle, params, &sampleRate, 0));
  VERIFY(!snd_pcm_hw_params_set_channels(handle, params, channels));
  VERIFY(!snd_pcm_hw_params(handle, params));
  snd_pcm_hw_params_free(params);

  VERIFY(!snd_pcm_prepare(handle));

  ASSERT(channels <= 4);
  short buf[4];
  VERIFY(snd_pcm_readi(handle, buf, 1) >= 0);
}
开发者ID:weilandetian,项目名称:Yoyo,代码行数:31,代码来源:AudioProvider.cpp

示例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: ASSERT

AudioProvider::AudioProvider()
{
  unsigned i;
  for(i = 0; i < retries; ++i)
  {
    if(snd_pcm_open(&handle, "hw:0", snd_pcm_stream_t(SND_PCM_STREAM_CAPTURE | SND_PCM_NONBLOCK), 0) >= 0)
      break;
    SystemCall::sleep(retryDelay);
  }
  ASSERT(i < retries);

  snd_pcm_hw_params_t* params;
  VERIFY(!snd_pcm_hw_params_malloc(&params));
  VERIFY(!snd_pcm_hw_params_any(handle, params));
  VERIFY(!snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED));
  VERIFY(!snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE));
  VERIFY(!snd_pcm_hw_params_set_rate_near(handle, params, &sampleRate, 0));
  VERIFY(!snd_pcm_hw_params_set_channels(handle, params, channels));
  VERIFY(!snd_pcm_hw_params(handle, params));
  snd_pcm_hw_params_free(params);

  VERIFY(!snd_pcm_prepare(handle));

  ASSERT(channels <= 4);
  short buf[4];
  VERIFY(snd_pcm_readi(handle, buf, 1) >= 0);
}
开发者ID:Yanzqing,项目名称:BHumanCodeRelease,代码行数:27,代码来源:AudioProvider.cpp

示例5: alsa_format_supported

RD_BOOL
alsa_format_supported(RD_WAVEFORMATEX * pwfx)
{
#if 0
	int err;
	snd_pcm_hw_params_t *hwparams = NULL;

	if ((err = snd_pcm_hw_params_malloc(&hwparams)) < 0)
	{
		error("snd_pcm_hw_params_malloc: %s\n", snd_strerror(err));
		return False;
	}

	if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0)
	{
		error("snd_pcm_hw_params_malloc: %s\n", snd_strerror(err));
		return False;
	}
	snd_pcm_hw_params_free(hwparams);
#endif

	if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
		return False;
	if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
		return False;
	if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
		return False;
	if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050))
		return False;

	return True;
}
开发者ID:AmesianX,项目名称:rdesktop-fuzzer,代码行数:32,代码来源:rdpsnd_alsa.c

示例6: audin_alsa_set_params

static boolean audin_alsa_set_params(AudinALSADevice* alsa, snd_pcm_t* capture_handle)
{
	int error;
	snd_pcm_hw_params_t* hw_params;

	if ((error = snd_pcm_hw_params_malloc(&hw_params)) < 0)
	{
		DEBUG_WARN("snd_pcm_hw_params_malloc (%s)",
			 snd_strerror(error));
		return False;
	}
	snd_pcm_hw_params_any(capture_handle, hw_params);
	snd_pcm_hw_params_set_access(capture_handle, hw_params,
		SND_PCM_ACCESS_RW_INTERLEAVED);
	snd_pcm_hw_params_set_format(capture_handle, hw_params,
		alsa->format);
	snd_pcm_hw_params_set_rate_near(capture_handle, hw_params,
		&alsa->actual_rate, NULL);
	snd_pcm_hw_params_set_channels_near(capture_handle, hw_params,
		&alsa->actual_channels);
	snd_pcm_hw_params(capture_handle, hw_params);
	snd_pcm_hw_params_free(hw_params);
	snd_pcm_prepare(capture_handle);

	if ((alsa->actual_rate != alsa->target_rate) ||
		(alsa->actual_channels != alsa->target_channels))
	{
		DEBUG_DVC("actual rate %d / channel %d is "
			"different from target rate %d / channel %d, resampling required.",
			alsa->actual_rate, alsa->actual_channels,
			alsa->target_rate, alsa->target_channels);
	}
	return True;
}
开发者ID:kidfolk,项目名称:FreeRDP,代码行数:34,代码来源:audin_alsa.c

示例7: ALSA

            ALSA(unsigned channels, unsigned samplerate, const std::string& device = "default") : runnable(true), pcm(nullptr), params(nullptr), fps(samplerate)
            {
               int rc = snd_pcm_open(&pcm, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
               if (rc < 0)
               {
                  runnable = false;
                  throw DeviceException(General::join("Unable to open PCM device ", snd_strerror(rc)));
               }

               snd_pcm_format_t fmt = type_to_format(T());

               if (snd_pcm_hw_params_malloc(&params) < 0)
               {
                  runnable = false;
                  throw DeviceException("Failed to allocate memory.");
               }

               runnable = false;
               if (
                     (snd_pcm_hw_params_any(pcm, params) < 0) ||
                     (snd_pcm_hw_params_set_access(pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) ||
                     (snd_pcm_hw_params_set_channels(pcm, params, channels) < 0) ||
                     (snd_pcm_hw_params_set_format(pcm, params, fmt) < 0) ||
                     (snd_pcm_hw_params_set_rate(pcm, params, samplerate, 0) < 0) ||
                     ((rc = snd_pcm_hw_params(pcm, params)) < 0)
                  )
                  throw DeviceException(General::join("Unable to install HW params: ", snd_strerror(rc)));

               runnable = true;
            }
开发者ID:Themaister,项目名称:SLIMPlayer,代码行数:30,代码来源:alsa.hpp

示例8: configureInitialState

/*
 * Set some stuff up.
 */
static int configureInitialState(const char* pathName, AudioState* audioState)
{
#if BUILD_SIM_WITHOUT_AUDIO
    return 0;
#else
    audioState->handle = NULL;

    snd_pcm_open(&audioState->handle, "default", SND_PCM_STREAM_PLAYBACK, 0);

    if (audioState->handle) {
        snd_pcm_hw_params_t *params;
        snd_pcm_hw_params_malloc(&params);
        snd_pcm_hw_params_any(audioState->handle, params);
        snd_pcm_hw_params_set_access(audioState->handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
        snd_pcm_hw_params_set_format(audioState->handle, params, SND_PCM_FORMAT_S16_LE);
        unsigned int rate = 44100;
        snd_pcm_hw_params_set_rate_near(audioState->handle, params, &rate, NULL);
        snd_pcm_hw_params_set_channels(audioState->handle, params, 2);
        snd_pcm_hw_params(audioState->handle, params);
        snd_pcm_hw_params_free(params);
    } else {
        wsLog("Couldn't open audio hardware, faking it\n");
    }

    return 0;
#endif
}
开发者ID:Andproject,项目名称:platform_development,代码行数:30,代码来源:DevAudio.c

示例9: main

int main(int argc,char *argv[]){
	int i = 0;
	int err;
	char buf[128];
	snd_pcm_t *playback_handle;
	int rate = 22025;
	int channels = 2;
	snd_pcm_hw_params_t *hw_params;
	if((err = snd_pcm_open(&playback_handle,"default",SND_PCM_STREAM_PLAYBACK,0)) < 0){
		fprintf(stderr,"can't open!%s(%s)\n","default",snd_strerror(err));
		exit(1);
	}
	if((err = snd_pcm_hw_params_malloc(&hw_params) < 0)){
		fprintf(stderr,"can't open!(%s)\n",snd_strerror(err));
		exit(1);
	}
	if((err = snd_pcm_hw_params_any(playback_handle,hw_params)) < 0){
		fprintf(stderr,"can't open(%s)\n",snd_strerror(err));
		exit(1);
	}
	if((err = snd_pcm_hw_params_set_access(playback_handle,hw_params,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0){
		fprintf(stderr,"can't open(%s)\n",snd_strerror(err));
		exit(1);
	}
	if((err = snd_pcm_hw_params_set_format(playback_handle,hw_params,SND_PCM_FORMAT_S16_LE)) < 0){
		fprintf(stderr,"can't set(%s)\n",snd_strerror(err));
		exit(1);
	}
	if((err = snd_pcm_hw_params_set_rate_near(playback_handle,hw_params,&rate,0)) < 0){
		fprintf(stderr,"can't set(%s)\n",snd_strerror(err));
		exit(1);
	}
	if((err = snd_pcm_hw_params_set_channels(playback_handle,hw_params,channels)) < 0){
		fprintf(stderr,"can't set(%s)\n",snd_strerror(err));
		exit(1);
	}
	if((err = snd_pcm_hw_params(playback_handle,hw_params)) < 0){
		fprintf(stderr,"can't open(%s)\n",snd_strerror(err));
		exit(1);
	}
	snd_pcm_hw_params_free(hw_params);
	if((err = snd_pcm_prepare(playback_handle)) < 0){
		fprintf(stderr,"can't prepare(%s)\n",snd_strerror(err));
		exit(1);
	}
	i = 0;
	while(i < 256){
		memset(buf,i,128);
		err = snd_pcm_writei(playback_handle,buf,32);
		//fprintf(stderr,"write %d\n",err);
		if(err < 0){
			snd_pcm_prepare(playback_handle);
			printf("a");
		}
		i++;
	}
	snd_pcm_close(playback_handle);
	exit(0);
}
开发者ID:windleos,项目名称:sound-card,代码行数:59,代码来源:demo8.c

示例10: InitAudioCaptureDevice

static Int32 InitAudioCaptureDevice (Int32 channels, UInt32 sample_rate, Int32 driver_buf_size)
{
    snd_pcm_hw_params_t *hw_params;
    Int32 err;

    if ((err = snd_pcm_open (&capture_handle, ALSA_CAPTURE_DEVICE, SND_PCM_STREAM_CAPTURE, 0)) < 0)
    {
        fprintf (stderr, "AUDIO >>  cannot open audio device plughw:1,0 (%s)\n", snd_strerror (err));
        return  -1;
    }
//  printf ("AUDIO >>  opened %s device\n", ALSA_CAPTURE_DEVICE);
    if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot allocate hardware parameter structure (%s)\n", err, capture_handle);
    }

    if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot initialize hardware parameter structure (%s)\n", err, capture_handle);
    }

    if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set access type (%s)\n", err, capture_handle);
    }

    if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set sample format (%s)\n", err, capture_handle);
    }

    if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &sample_rate, 0)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set sample rate (%s)\n", err, capture_handle);
    }

    if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, channels)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set channel count (%s)\n", err, capture_handle);
    }

    if ((err = snd_pcm_hw_params_set_buffer_size (capture_handle, hw_params, driver_buf_size)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set buffer size (%s)\n", err, capture_handle);
    }

    if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set parameters (%s)\n", err, capture_handle);
    }

    snd_pcm_hw_params_free (hw_params);

    if ((err = snd_pcm_prepare (capture_handle)) < 0)
    {
        AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot prepare audio interface for use (%s)\n", err, capture_handle);
    }
    return 0;
}
开发者ID:sdut10523,项目名称:dvr_rdk,代码行数:59,代码来源:audio_capture.c

示例11: tsmf_alsa_set_format

static BOOL tsmf_alsa_set_format(ITSMFAudioDevice *audio,
								 UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample)
{
	int error;
	snd_pcm_uframes_t frames;
	snd_pcm_hw_params_t *hw_params;
	snd_pcm_sw_params_t *sw_params;
	TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
	if(!alsa->out_handle)
		return FALSE;
	snd_pcm_drop(alsa->out_handle);
	alsa->actual_rate = alsa->source_rate = sample_rate;
	alsa->actual_channels = alsa->source_channels = channels;
	alsa->bytes_per_sample = bits_per_sample / 8;
	error = snd_pcm_hw_params_malloc(&hw_params);
	if(error < 0)
	{
		WLog_ERR(TAG, "snd_pcm_hw_params_malloc failed");
		return FALSE;
	}
	snd_pcm_hw_params_any(alsa->out_handle, hw_params);
	snd_pcm_hw_params_set_access(alsa->out_handle, hw_params,
								 SND_PCM_ACCESS_RW_INTERLEAVED);
	snd_pcm_hw_params_set_format(alsa->out_handle, hw_params,
								 SND_PCM_FORMAT_S16_LE);
	snd_pcm_hw_params_set_rate_near(alsa->out_handle, hw_params,
									&alsa->actual_rate, NULL);
	snd_pcm_hw_params_set_channels_near(alsa->out_handle, hw_params,
										&alsa->actual_channels);
	frames = sample_rate;
	snd_pcm_hw_params_set_buffer_size_near(alsa->out_handle, hw_params,
										   &frames);
	snd_pcm_hw_params(alsa->out_handle, hw_params);
	snd_pcm_hw_params_free(hw_params);
	error = snd_pcm_sw_params_malloc(&sw_params);
	if(error < 0)
	{
		WLog_ERR(TAG, "snd_pcm_sw_params_malloc");
		return FALSE;
	}
	snd_pcm_sw_params_current(alsa->out_handle, sw_params);
	snd_pcm_sw_params_set_start_threshold(alsa->out_handle, sw_params,
										  frames / 2);
	snd_pcm_sw_params(alsa->out_handle, sw_params);
	snd_pcm_sw_params_free(sw_params);
	snd_pcm_prepare(alsa->out_handle);
	DEBUG_TSMF("sample_rate %d channels %d bits_per_sample %d",
			   sample_rate, channels, bits_per_sample);
	DEBUG_TSMF("hardware buffer %d frames", (int)frames);
	if((alsa->actual_rate != alsa->source_rate) ||
			(alsa->actual_channels != alsa->source_channels))
	{
		DEBUG_TSMF("actual rate %d / channel %d is different "
				   "from source rate %d / channel %d, resampling required.",
				   alsa->actual_rate, alsa->actual_channels,
				   alsa->source_rate, alsa->source_channels);
	}
	return TRUE;
}
开发者ID:BUGgs,项目名称:FreeRDP,代码行数:59,代码来源:tsmf_alsa.c

示例12: qPrintable

int AudioALSA::init_audio()
{
  int err = 0, dir = 1;
  unsigned int tmp_sampfreq = sampfreq;
  std::cout << qPrintable(tr("initializing audio at ")) << qPrintable(dsp_devicename) << std::endl;

  if ((err = snd_pcm_open(&capture_handle, dsp_devicename.toStdString().c_str(), SND_PCM_STREAM_CAPTURE, 0)) < 0) {
    std::cerr << "cannot open audio device " << qPrintable(dsp_devicename) << " (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
  
  if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
    std::cerr << "cannot allocate hardware parameter structure (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
				 
  if ((err = snd_pcm_hw_params_any(capture_handle, hw_params)) < 0) {
    std::cerr << "cannot initialize hardware parameter structure (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
  
  if ((err = snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
    std::cerr << "cannot set access type (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
  
  if ((err = snd_pcm_hw_params_set_format(capture_handle, hw_params, SND_PCM_FORMAT_U8)) < 0) {
    std::cerr << "cannot set sample format (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
  
  if ((err = snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &tmp_sampfreq, &dir)) < 0) {
    std::cerr << "cannot set sample rate (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
  sampfreq = tmp_sampfreq;
  
  if ((err = snd_pcm_hw_params_set_channels(capture_handle, hw_params, 1)) < 0) {
    std::cerr << "cannot set channel count (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
  
  if ((err = snd_pcm_hw_params(capture_handle, hw_params)) < 0) {
    std::cerr << "cannot set parameters (" << snd_strerror(err) << ")." << std::endl;
    exit (1);
  }
  
  snd_pcm_hw_params_free(hw_params);
  
  if ((err = snd_pcm_prepare(capture_handle)) < 0) {
    std::cerr << "cannot prepare audio interface for use (" << snd_strerror(err) << std::endl;
    exit (1);
  }

  blksize = 256;

  return 1;
}
开发者ID:ycollet,项目名称:qtguitune,代码行数:58,代码来源:audio_alsa.cpp

示例13: malloc

AlsaDevice *alsa_device_sample( const char *device_name, unsigned int rate )
{
   int err;
   snd_pcm_hw_params_t *hw_params;
   static snd_output_t *jcd_out;
   AlsaDevice *dev = malloc( sizeof( *dev ) );
   if ( !dev )
      return NULL;
   dev->device_name = malloc( 1 + strlen( device_name ) );
   if ( !dev->device_name )
   {
      free(dev);
      return NULL;
   }
   strcpy(dev->device_name, device_name);
   err = snd_output_stdio_attach( &jcd_out, stdout, 0 );

   if ( ( err = snd_pcm_open ( &dev->capture_handle, dev->device_name, SND_PCM_STREAM_CAPTURE, 0 ) ) < 0 )
   {
      rc = 0;
      fprintf (stderr, "\033[0;31m[vokoscreen] alsa_device_sample() in alsadevice.c: cannot open audio device %s (%s)\033[0;0m\n", dev->device_name, snd_strerror (err) );
      return NULL;
   }
   else
   {
        rc = 1;
        // fprintf (stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: open audio device %s (%s)\n", dev->device_name, snd_strerror (err) );
   }

   if ( ( err = snd_pcm_hw_params_malloc ( &hw_params ) ) < 0 )
   {
      fprintf (stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: cannot allocate hardware parameter structure (%s)\n", snd_strerror( err ) );
   }

   if ( ( err = snd_pcm_hw_params_any( dev->capture_handle, hw_params ) ) < 0 )
   {
      fprintf (stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: cannot initialize hardware parameter structure (%s)\n", snd_strerror( err ) );
   }
   
   
   if ( ( err = snd_pcm_hw_params_set_rate_near (dev->capture_handle, hw_params, &rate, 0 ) ) < 0 )
   {
      fprintf( stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: cannot set sample rate (%s)\n", snd_strerror( err ) );
      rc = 0;
   }
   else
   {
      rc = 1;
      rcSampleRate = rate;
   }
   
   //fprintf ( stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: Samplerate = %d\n", rate );

   snd_pcm_close( dev->capture_handle );
   free( dev->device_name );
   free( dev );
   return dev;
}
开发者ID:TheDudeWithThreeHands,项目名称:CapScreen,代码行数:58,代码来源:alsa_device.c

示例14: AudioDevice

AudioAlsa::AudioAlsa( bool & _success_ful, Mixer*  _mixer ) :
	AudioDevice( tLimit<ch_cnt_t>(
		ConfigManager::inst()->value( "audioalsa", "channels" ).toInt(),
					DEFAULT_CHANNELS, SURROUND_CHANNELS ),
								_mixer ),
	m_handle( NULL ),
	m_hwParams( NULL ),
	m_swParams( NULL ),
	m_convertEndian( false )
{
	_success_ful = false;

	int err;

	if( ( err = snd_pcm_open( &m_handle,
					probeDevice().toLatin1().constData(),
						SND_PCM_STREAM_PLAYBACK,
						0 ) ) < 0 )
	{
		printf( "Playback open error: %s\n", snd_strerror( err ) );
		return;
	}

	snd_pcm_hw_params_malloc( &m_hwParams );
	snd_pcm_sw_params_malloc( &m_swParams );

	if( ( err = setHWParams( channels(),
					SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 )
	{
		printf( "Setting of hwparams failed: %s\n",
							snd_strerror( err ) );
		return;
	}
	if( ( err = setSWParams() ) < 0 )
	{
		printf( "Setting of swparams failed: %s\n",
							snd_strerror( err ) );
		return;
	}

	// set FD_CLOEXEC flag for all file descriptors so forked processes
	// do not inherit them
	struct pollfd * ufds;
	int count = snd_pcm_poll_descriptors_count( m_handle );
	ufds = new pollfd[count];
	snd_pcm_poll_descriptors( m_handle, ufds, count );
	for( int i = 0; i < qMax( 3, count ); ++i )
	{
		const int fd = ( i >= count ) ? ufds[0].fd+i : ufds[i].fd;
		int oldflags = fcntl( fd, F_GETFD, 0 );
		if( oldflags < 0 )
			continue;
		oldflags |= FD_CLOEXEC;
		fcntl( fd, F_SETFD, oldflags );
	}
	delete[] ufds;
	_success_ful = true;
}
开发者ID:GNUMariano,项目名称:lmms,代码行数:58,代码来源:AudioAlsa.cpp

示例15: 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


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