这篇教程C++ snd_pcm_sw_params_alloca函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中snd_pcm_sw_params_alloca函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_sw_params_alloca函数的具体用法?C++ snd_pcm_sw_params_alloca怎么用?C++ snd_pcm_sw_params_alloca使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了snd_pcm_sw_params_alloca函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: alsa_openint alsa_open( void ){ int err; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; DEBUGLOG("alsa_open/n"); snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); if((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0/*SND_PCM_NONBLOCK*/)) < 0 ) { ERRORLOG("open failed: %s/n", snd_strerror(err)); return -1; } if((err = set_hwparams(hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { ERRORLOG("Setting of hwparams failed: %s/n", snd_strerror(err)); return -1; } if((err = set_swparams(swparams)) < 0) { ERRORLOG("Setting of swparams failed: %s/n", snd_strerror(err)); return -1; } return 0;}
开发者ID:serghei,项目名称:kde3-kdemultimedia,代码行数:28,
示例2: snd_pcm_hw_params_allocastatic snd_pcm_t *open_audiofd( char *device_name, int capture, int rate, int channels, int period, int nperiods ) { int err; snd_pcm_t *handle; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); if ((err = snd_pcm_open(&(handle), device_name, capture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK )) < 0) { printf("Capture open error: %s/n", snd_strerror(err)); return NULL; } if ((err = set_hwparams(handle, hwparams,SND_PCM_ACCESS_RW_INTERLEAVED, rate, channels, period, nperiods )) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); return NULL; } if ((err = set_swparams(handle, swparams, period)) < 0) { printf("Setting of swparams failed: %s/n", snd_strerror(err)); return NULL; } snd_pcm_start( handle ); snd_pcm_wait( handle, 200 ); return handle;}
开发者ID:rufferson,项目名称:jack2,代码行数:28,
示例3: snd_pcm_hw_params_allocastatic snd_pcm_t *open_audiofd( char *device_name, int capture, int rate, int channels, int period, int nperiods ) { int err; snd_pcm_t *handle; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); if ((err = snd_pcm_open(&(handle), device_name, capture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK )) < 0) { printf("Capture open error: %s/n", snd_strerror(err)); return NULL; } if ((err = set_hwparams(handle, hwparams,SND_PCM_ACCESS_RW_INTERLEAVED, rate, channels, period, nperiods )) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); return NULL; } if ((err = set_swparams(handle, swparams, period, nperiods)) < 0) { printf("Setting of swparams failed: %s/n", snd_strerror(err)); return NULL; } //snd_pcm_start( handle ); //snd_pcm_wait( handle, 200 ); int num_null_samples = nperiods * period * channels; char *tmp = alloca( num_null_samples * formats[format].sample_size ); memset( tmp, 0, num_null_samples * formats[format].sample_size ); snd_pcm_writei( handle, tmp, num_null_samples ); return handle;}
开发者ID:recri,项目名称:keyer,代码行数:33,
示例4: fprintfsnd_pcm_t *open_pcm(char *pcm_name) { snd_pcm_t *playback_handle; snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; if (snd_pcm_open (&playback_handle, pcm_name, SND_PCM_STREAM_PLAYBACK, 0) < 0) { fprintf (stderr, "cannot open audio device %s/n", pcm_name); exit (1); } snd_pcm_hw_params_alloca(&hw_params); snd_pcm_hw_params_any(playback_handle, hw_params); snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_S16_LE); snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, 44100, 0); snd_pcm_hw_params_set_channels(playback_handle, hw_params, 2); snd_pcm_hw_params_set_periods(playback_handle, hw_params, 2, 0); snd_pcm_hw_params_set_period_size(playback_handle, hw_params, BUFSIZE, 0); snd_pcm_hw_params(playback_handle, hw_params); snd_pcm_sw_params_alloca(&sw_params); snd_pcm_sw_params_current(playback_handle, sw_params); snd_pcm_sw_params_set_avail_min(playback_handle, sw_params, BUFSIZE); snd_pcm_sw_params(playback_handle, sw_params); return(playback_handle);}
开发者ID:babycool111,项目名称:Learn,代码行数:25,
示例5: pcm_init/*********************************************************************************** pcm_init()************************************************************************************/static void pcm_init(void){ int err; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { printf("Playback open error: %s/n", snd_strerror(err)); } if ((err = set_hwparams(handle, hwparams,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } if ((err = set_swparams(handle, swparams)) < 0) { printf("Setting of swparams failed: %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } /*分配空间 period的空间,period指向空间首地址*/ period_size_real = period_size * channels * snd_pcm_format_physical_width(format) / 8;//snd_pcm_format_physical_width:return bits needed to store a PCM sample. period = malloc(period_size_real); if (period == NULL) { printf("No enough memory/n"); exit(EXIT_FAILURE); } fprintf(stdout,"pcm_init sucess !/n");}
开发者ID:hello2mhb,项目名称:mhbcode,代码行数:36,
示例6: mainint main(int argc, char *argv[]){ snd_pcm_t *handle; snd_pcm_t *handle_play; int err, morehelp; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; int method = 0; signed short *samples; unsigned int chn; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); printf("Capture device is %s/n", device); printf("Stream parameters are %iHz, %s, %i channels/n", rate, snd_pcm_format_name(format), channels); /*open the playback*/ if ((err = snd_pcm_open(&handle_play, device,SND_PCM_STREAM_PLAYBACK, 0)) < 0) { printf("Capture open error: %s/n", snd_strerror(err)); return 0; } /* set the hard ware parameter*/ if ((err = set_hwparams(handle_play,hwparams,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } /*open the capture*/ if ((err = snd_pcm_open(&handle, device,SND_PCM_STREAM_CAPTURE, 0)) < 0) { printf("Capture open error: %s/n", snd_strerror(err)); return 0; } /* set the hard ware parameter*/ if ((err = set_hwparams(handle, hwparams,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } static struct timeval oldtv; static struct timeval tv; /*avasounil = snd_pcm_avail_update(handle);*/ gettimeofday(&tv,NULL); // printf("play back time %lu/n",(tv.tv_sec-oldtv.tv_sec)*1000000+tv.tv_usec-oldtv.tv_usec); printf("main time %u: %u /n",tv.tv_sec,tv.tv_usec); oldtv = tv; /*async for capture */ async_loop(handle); /* */ write_loop(handle_play); /*while(1) { }*/}
开发者ID:alatagoo,项目名称:test,代码行数:58,
示例7: alsa_open_audioBOOL alsa_open_audio(BOOL use_mmap) { snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; int err; snd_pcm_access_t access = (use_mmap)?(SND_PCM_ACCESS_MMAP_INTERLEAVED) :(SND_PCM_ACCESS_RW_INTERLEAVED); format = (use_mmap)?(format_8):(format_16); if (alsa_audiodev_is_open) return TRUE; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); err = snd_output_stdio_attach(&output, stdout, 0); if (err < 0) { printf("Output failed: %s/n", snd_strerror(err)); return 0; } if ((err = snd_pcm_open(&playback_handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { printf("Playback open error: %s/n", snd_strerror(err)); return 0; } if ((err = set_hwparams(playback_handle, hwparams, access)) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); return 0; } if ((err = set_swparams(playback_handle, swparams)) < 0) { printf("Setting of swparams failed: %s/n", snd_strerror(err)); return 0; } snd_pcm_dump(playback_handle, output); samples = malloc((period_size * channels * snd_pcm_format_width(format)) / 8); if (samples == NULL) { printf("No enough memory/n"); exit(EXIT_FAILURE); } areas = calloc(channels, sizeof(snd_pcm_channel_area_t)); if (areas == NULL) { printf("No enough memory/n"); exit(EXIT_FAILURE); } for (chn = 0; chn < channels; chn++) { areas[chn].addr = samples; areas[chn].first = chn * snd_pcm_format_width(format); areas[chn].step = channels * snd_pcm_format_width(format); } alsa_audiodev_is_open = TRUE; //err = snd_pcm_writei(playback_handle, samples, (period_size * channels * snd_pcm_format_width(format)) / 8); return TRUE;}
开发者ID:BackupTheBerlios,项目名称:arnold,代码行数:56,
示例8: mainint main(int argc, char *argv[]){ snd_pcm_t *handle; snd_pcm_t *handle_play; int err, morehelp; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; int method = 0; signed short *samples; unsigned int chn; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); printf("Capture device is %s/n", device); printf("Stream parameters are %iHz, %s, %i channels/n", rate, snd_pcm_format_name(format), channels); /*open the playback*/ if ((err = snd_pcm_open(&handle_play, device,SND_PCM_STREAM_PLAYBACK, 0)) < 0) { printf("Capture open error: %s/n", snd_strerror(err)); return 0; } /* set the hard ware parameter*/ if ((err = set_hwparams(handle_play,hwparams,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } /*open the capture*/ if ((err = snd_pcm_open(&handle, device,SND_PCM_STREAM_CAPTURE, 0)) < 0) { printf("Capture open error: %s/n", snd_strerror(err)); return 0; } /* set the hard ware parameter*/ if ((err = set_hwparams(handle, hwparams,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { printf("Setting of hwparams failed: %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } /*async for capture */ async_loop(handle); /* */ write_loop(handle_play); /*while(1) { }*/}
开发者ID:alatagoo,项目名称:test,代码行数:51,
示例9: set_paramsstatic void set_params(void){ hwparams.format=SND_PCM_FORMAT_S16_LE; hwparams.channels=2; hwparams.rate=44100; snd_pcm_hw_params_t *params; snd_pcm_sw_params_t *swparams; snd_pcm_hw_params_alloca(¶ms); snd_pcm_sw_params_alloca(&swparams); snd_pcm_hw_params_any(handle, params); snd_pcm_hw_params_set_format(handle, params, hwparams.format); snd_pcm_hw_params_set_channels(handle, params, hwparams.channels); snd_pcm_hw_params_set_rate_near(handle, params, &hwparams.rate, 0); buffer_time=0; snd_pcm_hw_params_get_buffer_time_max(params,&buffer_time, 0); period_time=125000; snd_pcm_hw_params_set_period_time_near(handle, params,&period_time, 0); buffer_time = 500000; snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, 0); /*monotonic = */snd_pcm_hw_params_is_monotonic(params); /*can_pause = */snd_pcm_hw_params_can_pause(params); printf("sizeof(params) : %d/n",sizeof(params)); snd_pcm_hw_params(handle, params); snd_pcm_uframes_t buffer_size; snd_pcm_hw_params_get_period_size(params, &chunk_size, 0); size_t n=chunk_size; snd_pcm_sw_params_set_avail_min(handle, swparams, n); snd_pcm_uframes_t start_threshold, stop_threshold; start_threshold=22050; snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold); stop_threshold=22050; snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold); snd_pcm_format_physical_width(hwparams.format); }
开发者ID:cty222,项目名称:Note,代码行数:51,
示例10: mixer_openvoid mixer_open(){ memset(&channels, 0, sizeof(channels)); int err = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0); if (err < 0) { printf("Failed to open pcm device: %s/n", snd_strerror(err)); exit(1); } unsigned int rate = 44100; snd_pcm_hw_params_t *hw_params = 0; snd_pcm_hw_params_alloca(&hw_params); snd_pcm_hw_params_any(pcm, hw_params); snd_pcm_hw_params_set_rate_resample(pcm, hw_params, 0); snd_pcm_hw_params_set_access(pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); snd_pcm_hw_params_set_format(pcm, hw_params, SND_PCM_FORMAT_S16_LE); snd_pcm_hw_params_set_rate_near(pcm, hw_params, &rate, 0); snd_pcm_hw_params_set_channels(pcm, hw_params, 2); snd_pcm_hw_params_set_period_size(pcm, hw_params, BUFFER_SIZE, 0); snd_pcm_hw_params_set_buffer_size(pcm, hw_params, BUFFER_SIZE * 4); err = snd_pcm_hw_params(pcm, hw_params); if (err < 0) { printf("Failed to apply pcm hardware settings: %s/n", snd_strerror(err)); exit(1); } snd_pcm_sw_params_t *sw_params = 0; snd_pcm_sw_params_alloca(&sw_params); snd_pcm_sw_params_current(pcm, sw_params); snd_pcm_sw_params_set_avail_min(pcm, sw_params, BUFFER_SIZE * 4); err = snd_pcm_sw_params(pcm, sw_params); if (err < 0) { printf("Failed to apply pcm software settings: %s/n", snd_strerror(err)); exit(1); } err = snd_pcm_prepare(pcm); if (err < 0) { printf("Failed to prepare pcm interface: %s/n", snd_strerror(err)); exit(1); } memset(delay_left, 0, sizeof(delay_left)); memset(delay_right, 0, sizeof(delay_right));}
开发者ID:wsmind,项目名称:funpad,代码行数:50,
示例11: set_mic_swparamsintset_mic_swparams(snd_pcm_t *handle) { // set software params snd_pcm_sw_params_t *swparams; snd_pcm_sw_params_alloca(&swparams); /* get the current swparams */ int ret = snd_pcm_sw_params_current(handle, swparams); if (ret < 0) { fprintf(stderr, "Unable to determine current swparams for mic: %s/n", snd_strerror(ret)); return ret; } /* allow transfer when at least period_frames can be processed */ ret = snd_pcm_sw_params_set_avail_min(handle, swparams, get_period_frames(handle)); if (ret < 0) { fprintf(stderr, "Unable to set avail min for mic: %s/n", snd_strerror(ret)); return ret; } /* align all transfers to 1 sample */ ret = snd_pcm_sw_params_set_xfer_align(handle, swparams, 1); if (ret < 0) { fprintf(stderr, "Unable to set transfer align for mic: %s/n", snd_strerror(ret)); return ret; } /* write the parameters to the microphone device */ ret = snd_pcm_sw_params(handle, swparams); if (ret < 0) { fprintf(stderr, "Unable to set sw params for mic: %s/n", snd_strerror(ret)); return ret; } dump_swparams(handle); return 0;}
开发者ID:chenqiang712,项目名称:openwonderland-jvoicebridge,代码行数:47,
示例12: drvHostALSAAudioSetThresholdstatic int drvHostALSAAudioSetThreshold(snd_pcm_t *phPCM, snd_pcm_uframes_t threshold){ snd_pcm_sw_params_t *pSWParms = NULL; snd_pcm_sw_params_alloca(&pSWParms); if (!pSWParms) return VERR_NO_MEMORY; int rc; do { int err = snd_pcm_sw_params_current(phPCM, pSWParms); if (err < 0) { LogRel(("ALSA: Failed to get current software parameters for threshold: %s/n", snd_strerror(err))); rc = VERR_ACCESS_DENIED; break; } err = snd_pcm_sw_params_set_start_threshold(phPCM, pSWParms, threshold); if (err < 0) { LogRel(("ALSA: Failed to set software threshold to %ld: %s/n", threshold, snd_strerror(err))); rc = VERR_ACCESS_DENIED; break; } err = snd_pcm_sw_params(phPCM, pSWParms); if (err < 0) { LogRel(("ALSA: Failed to set new software parameters for threshold: %s/n", snd_strerror(err))); rc = VERR_ACCESS_DENIED; break; } LogFlowFunc(("Setting threshold to %RU32/n", threshold)); rc = VINF_SUCCESS; } while (0); return rc;}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:45,
示例13: alsa_set_hwparamsstatic int alsa_set_hwparams(){ snd_pcm_hw_params_t *hwp; snd_pcm_sw_params_t *swp; int dir = 1; unsigned period_time; snd_pcm_uframes_t buffer_size, period_size; snd_pcm_hw_params_alloca(&hwp); snd_pcm_sw_params_alloca(&swp); // ALSA bug? If we request 44100 Hz, it rounds the value up to 48000... alsa_hw.rate--; if (alsa_error("hw_params_any", snd_pcm_hw_params_any(alsa_hw.handle, hwp)) || alsa_error("hw_params_set_format", snd_pcm_hw_params_set_format(alsa_hw.handle, hwp, alsa_hw.format)) || alsa_error("hw_params_set_channels", snd_pcm_hw_params_set_channels(alsa_hw.handle, hwp, alsa_hw.num_channels)) || alsa_error("hw_params_set_rate_near", snd_pcm_hw_params_set_rate_near(alsa_hw.handle, hwp, &alsa_hw.rate, &dir)) || alsa_error("hw_params_set_access", snd_pcm_hw_params_set_access(alsa_hw.handle, hwp, SND_PCM_ACCESS_RW_INTERLEAVED)) || alsa_error("hw_params_set_buffer_time_near", snd_pcm_hw_params_set_buffer_time_near(alsa_hw.handle, hwp, &alsa_hw.buffer_time, 0))) return -1; /* How often to call our SIGIO handler (~40Hz) */ period_time = alsa_hw.buffer_time / 4; if (alsa_error ("hw_params_set_period_time_near", snd_pcm_hw_params_set_period_time_near(alsa_hw.handle, hwp, &period_time, &dir)) || alsa_error("hw_params_get_buffer_size", snd_pcm_hw_params_get_buffer_size(hwp, &buffer_size)) || alsa_error("hw_params_get_period_size", snd_pcm_hw_params_get_period_size(hwp, &period_size, 0)) || alsa_error("hw_params", snd_pcm_hw_params(alsa_hw.handle, hwp))) return -1; snd_pcm_sw_params_current(alsa_hw.handle, swp); if (alsa_error ("sw_params_set_start_threshold", snd_pcm_sw_params_set_start_threshold(alsa_hw.handle, swp, period_size)) || alsa_error("sw_params_set_avail_min", snd_pcm_sw_params_set_avail_min(alsa_hw.handle, swp, period_size)) || alsa_error("sw_params", snd_pcm_sw_params(alsa_hw.handle, swp))) return -1; return 0;}
开发者ID:TryndamereStark,项目名称:lirc,代码行数:45,
示例14: sa_stream_get_min_writeintsa_stream_get_min_write(sa_stream_t *s, size_t *size) { int r; snd_pcm_uframes_t threshold; snd_pcm_sw_params_t* swparams; if (s == NULL || s->output_unit == NULL) { return SA_ERROR_NO_INIT; } snd_pcm_sw_params_alloca(&swparams); snd_pcm_sw_params_current(s->output_unit, swparams); r = snd_pcm_sw_params_get_start_threshold(swparams, &threshold); if (r < 0) { return SA_ERROR_NO_INIT; } *size = snd_pcm_frames_to_bytes(s->output_unit, threshold); return SA_SUCCESS;}
开发者ID:hadicoffee,项目名称:jb412gecko,代码行数:18,
示例15: alsa_set_swparams/* setup alsa data transfer behavior */static inline int alsa_set_swparams(ao_alsa_internal *internal){ snd_pcm_sw_params_t *params; int err; /* allocate the software parameter structure */ snd_pcm_sw_params_alloca(¶ms); /* fetch the current software parameters */ internal->cmd = "snd_pcm_sw_params_current"; err = snd_pcm_sw_params_current(internal->pcm_handle, params); if (err < 0) return err; /* allow transfers to start when there is one period */ internal->cmd = "snd_pcm_sw_params_set_start_threshold"; err = snd_pcm_sw_params_set_start_threshold(internal->pcm_handle, params, internal->period_size); if (err < 0) return err; /* require a minimum of one full transfer in the buffer */ internal->cmd = "snd_pcm_sw_params_set_avail_min"; err = snd_pcm_sw_params_set_avail_min(internal->pcm_handle, params, internal->period_size); if (err < 0) return err; /* do not align transfers */ internal->cmd = "snd_pcm_sw_params_set_xfer_align"; err = snd_pcm_sw_params_set_xfer_align(internal->pcm_handle, params, 1); if (err < 0) return err; /* commit the params structure to ALSA */ internal->cmd = "snd_pcm_sw_params"; err = snd_pcm_sw_params(internal->pcm_handle, params); if (err < 0) return err; return 1;}
开发者ID:OpenInkpot-archive,项目名称:iplinux-libao,代码行数:43,
示例16: snd_pcm_sw_params_alloca// On error return a negative value// If the requested buffer size can be served return 0,// otherwise return the number of 16 bit words contained in the obtained buffermp_sint32 AudioDriver_ALSA::initDevice(mp_sint32 periodSizeAsSamples, const mp_uint32 mixFrequency, MasterMixer* mixer){ snd_pcm_sw_params_t *swparams; snd_pcm_uframes_t buffer_size; int err; snd_pcm_sw_params_alloca(&swparams); if ((err = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) { fprintf(stderr, "ALSA: Failed to open device 'default' (%s)/n", snd_strerror(err)); return -1; } if ((err = snd_pcm_set_params(pcm, SND_PCM_FORMAT_S16, SND_PCM_ACCESS_MMAP_INTERLEAVED, 2, // channels mixFrequency, 0, // disallow soft resampling (2000000 * static_cast<unsigned long long> (periodSizeAsSamples)) / mixFrequency)) < 0) // period size in uS { fprintf(stderr, "ALSA: Playback open error (%s)/nALSA: Is your mixer frequency correct? Try 48000Hz/nALSA: If you are seeing /"Access type not available for PLAYBACK/" then your audio driver does not support MMAP access, and will not work with this version of MilkyTracker using the ALSA driver (try SDL instead)./n", snd_strerror(err)); return -1; } snd_pcm_prepare(pcm); period_size = periodSizeAsSamples * 2; snd_pcm_get_params(pcm, &buffer_size, &period_size); stream = new char[period_size * 2]; printf("ALSA: Period size = %lu frames (requested %i), buffer size = %lu frames/n", period_size, periodSizeAsSamples / 2, buffer_size); /* get the current swparams */ err = snd_pcm_sw_params_current(pcm, swparams); if (err < 0) { fprintf(stderr, "ALSA: Unable to determine current swparams for playback: %s/n", snd_strerror(err)); return -1; } AudioDriverBase::initDevice(period_size * 2, mixFrequency, mixer); return period_size * 2; // 2 = number of channels}
开发者ID:FyiurAmron,项目名称:MilkyTracker,代码行数:45,
示例17: get_boundary/* Get the pcm boundary value. */static int get_boundary(snd_pcm_t *pcm, snd_pcm_uframes_t *boundary){ snd_pcm_sw_params_t *sw_params; int rc; snd_pcm_sw_params_alloca(&sw_params); rc = snd_pcm_sw_params_current(pcm, sw_params); if (rc < 0) { fprintf(stderr, "sw_params_current: %s/n", snd_strerror(rc)); return rc; } rc = snd_pcm_sw_params_get_boundary(sw_params, boundary); if (rc < 0) { fprintf(stderr, "get_boundary: %s/n", snd_strerror(rc)); return rc; } return 0;}
开发者ID:drinkcat,项目名称:adhd,代码行数:22,
示例18: snd_spcm_init/** * /brief Set up a simple PCM * /param pcm PCM handle * /param rate Sample rate * /param channels Number of channels * /param format PCM format * /param subformat PCM subformat * /param latency Latency type * /param access PCM acceess type * /param xrun_type XRUN type * /return 0 if successful, or a negative error code * * /warning The simple PCM API may be broken in the current release. */int snd_spcm_init(snd_pcm_t *pcm, unsigned int rate, unsigned int channels, snd_pcm_format_t format, snd_pcm_subformat_t subformat, snd_spcm_latency_t latency, snd_pcm_access_t access, snd_spcm_xrun_type_t xrun_type){ int err; snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; unsigned int rrate; unsigned int buffer_time; snd_pcm_hw_params_alloca(&hw_params); snd_pcm_sw_params_alloca(&sw_params); assert(pcm); assert(rate > 5000 && rate < 192000); assert(channels > 1 && channels < 512); rrate = rate; err = set_buffer_time(latency, &buffer_time); if (err < 0) return err; err = set_hw_params(pcm, hw_params, &rrate, channels, format, subformat, &buffer_time, NULL, access); if (err < 0) return err; err = set_sw_params(pcm, sw_params, xrun_type); if (err < 0) return err; return 0;}
开发者ID:xenyinzen,项目名称:lx_toolset,代码行数:52,
示例19: fprintfsnd_pcm_t *open_pcm(char *pcm_name) { snd_pcm_t *playback_handle; snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; if (snd_pcm_open (&playback_handle, pcm_name, SND_PCM_STREAM_PLAYBACK, 0) < 0) { fprintf (stderr, "cannot open audio device %s/n", pcm_name); return NULL;//it seems greedy and wants exclusive control?! } snd_pcm_hw_params_alloca(&hw_params); snd_pcm_hw_params_any(playback_handle, hw_params); snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_S16_LE); snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &rate, 0); snd_pcm_hw_params_set_channels(playback_handle, hw_params, 2); snd_pcm_hw_params_set_periods(playback_handle, hw_params, 2, 0); snd_pcm_hw_params_set_period_size(playback_handle, hw_params, BUFSAMPS, 0); snd_pcm_hw_params(playback_handle, hw_params); snd_pcm_sw_params_alloca(&sw_params); snd_pcm_sw_params_current(playback_handle, sw_params); snd_pcm_sw_params_set_avail_min(playback_handle, sw_params, BUFSAMPS); snd_pcm_sw_params(playback_handle, sw_params); return(playback_handle);}
开发者ID:eiffie,项目名称:ShaderDemo,代码行数:23,
示例20: snd_pcm_sw_params_allocabool CAESinkALSA::InitializeSW(AEAudioFormat &format){ snd_pcm_sw_params_t *sw_params; snd_pcm_uframes_t boundary; snd_pcm_sw_params_alloca(&sw_params); memset(sw_params, 0, snd_pcm_sw_params_sizeof()); snd_pcm_sw_params_current (m_pcm, sw_params); snd_pcm_sw_params_set_start_threshold (m_pcm, sw_params, INT_MAX); snd_pcm_sw_params_set_silence_threshold(m_pcm, sw_params, 0); snd_pcm_sw_params_get_boundary (sw_params, &boundary); snd_pcm_sw_params_set_silence_size (m_pcm, sw_params, boundary); snd_pcm_sw_params_set_avail_min (m_pcm, sw_params, format.m_frames); if (snd_pcm_sw_params(m_pcm, sw_params) < 0) { CLog::Log(LOGERROR, "CAESinkALSA::InitializeSW - Failed to set the parameters"); return false; } return true;}
开发者ID:CharlieMarshall,项目名称:xbmc,代码行数:23,
示例21: snd_pcm_sw_params_allocabool AudioInputALSA::PrepSwParams(void){ snd_pcm_sw_params_t* swparams; snd_pcm_sw_params_alloca(&swparams); snd_pcm_uframes_t boundary; if (AlsaBad(snd_pcm_sw_params_current(pcm_handle, swparams), "failed to get swparams")) return false; if (AlsaBad(snd_pcm_sw_params_get_boundary(swparams, &boundary), "failed to get boundary")) return false; // explicit start, not auto start if (AlsaBad(snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, boundary), "failed to set start threshold")) return false; if (AlsaBad(snd_pcm_sw_params_set_stop_threshold(pcm_handle, swparams, boundary), "failed to set stop threshold")) return false; if (AlsaBad(snd_pcm_sw_params(pcm_handle, swparams), "failed to set software parameters")) return false; return true;}
开发者ID:kzmi,项目名称:mythtv_isdb,代码行数:24,
示例22: mainint main(int argc, char *argv[]) { const char *dev; int r, cap, count = 0; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; snd_pcm_status_t *status; snd_pcm_t *pcm; unsigned rate = 44100; unsigned periods = 2; snd_pcm_uframes_t boundary, buffer_size = 44100/10; /* 100s */ int dir = 1; struct timespec start, last_timestamp = { 0, 0 }; uint64_t start_us, last_us = 0; snd_pcm_sframes_t last_avail = 0, last_delay = 0; struct pollfd *pollfds; int n_pollfd; int64_t sample_count = 0; struct sched_param sp; r = -1;#ifdef _POSIX_PRIORITY_SCHEDULING sp.sched_priority = 5; r = pthread_setschedparam(pthread_self(), SCHED_RR, &sp);#endif if (r) printf("Could not get RT prio. :(/n"); snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); snd_pcm_status_alloca(&status); r = clock_gettime(CLOCK_MONOTONIC, &start); assert(r == 0); start_us = timespec_us(&start); dev = argc > 1 ? argv[1] : "front:AudioPCI"; cap = argc > 2 ? atoi(argv[2]) : 0; if (cap == 0) r = snd_pcm_open(&pcm, dev, SND_PCM_STREAM_PLAYBACK, 0); else r = snd_pcm_open(&pcm, dev, SND_PCM_STREAM_CAPTURE, 0); assert(r == 0); r = snd_pcm_hw_params_any(pcm, hwparams); assert(r == 0); r = snd_pcm_hw_params_set_rate_resample(pcm, hwparams, 0); assert(r == 0); r = snd_pcm_hw_params_set_access(pcm, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); assert(r == 0); r = snd_pcm_hw_params_set_format(pcm, hwparams, SND_PCM_FORMAT_S16_LE); assert(r == 0); r = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, NULL); assert(r == 0); r = snd_pcm_hw_params_set_channels(pcm, hwparams, 2); assert(r == 0); r = snd_pcm_hw_params_set_periods_integer(pcm, hwparams); assert(r == 0); r = snd_pcm_hw_params_set_periods_near(pcm, hwparams, &periods, &dir); assert(r == 0); r = snd_pcm_hw_params_set_buffer_size_near(pcm, hwparams, &buffer_size); assert(r == 0); r = snd_pcm_hw_params(pcm, hwparams); assert(r == 0); r = snd_pcm_hw_params_current(pcm, hwparams); assert(r == 0); r = snd_pcm_sw_params_current(pcm, swparams); assert(r == 0); if (cap == 0) r = snd_pcm_sw_params_set_avail_min(pcm, swparams, 1); else r = snd_pcm_sw_params_set_avail_min(pcm, swparams, 0); assert(r == 0); r = snd_pcm_sw_params_set_period_event(pcm, swparams, 0); assert(r == 0); r = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size); assert(r == 0); r = snd_pcm_sw_params_set_start_threshold(pcm, swparams, buffer_size); assert(r == 0); r = snd_pcm_sw_params_get_boundary(swparams, &boundary); assert(r == 0); r = snd_pcm_sw_params_set_stop_threshold(pcm, swparams, boundary); assert(r == 0);//.........这里部分代码省略.........
开发者ID:DryakhlyyZlodey,项目名称:pulseaudio,代码行数:101,
示例23: GLOBAL_DEFError AudioDriverALSA::init_device() { mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE); speaker_mode = SPEAKER_MODE_STEREO; channels = 2; // If there is a specified device check that it is really present if (device_name != "Default") { Array list = get_device_list(); if (list.find(device_name) == -1) { device_name = "Default"; new_device = "Default"; } } int status; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams;#define CHECK_FAIL(m_cond) / if (m_cond) { / fprintf(stderr, "ALSA ERR: %s/n", snd_strerror(status)); / if (pcm_handle) { / snd_pcm_close(pcm_handle); / pcm_handle = NULL; / } / ERR_FAIL_COND_V(m_cond, ERR_CANT_OPEN); / } //todo, add //6 chans - "plug:surround51" //4 chans - "plug:surround40"; if (device_name == "Default") { status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); } else { String device = device_name; int pos = device.find(";"); if (pos != -1) { device = device.substr(0, pos); } status = snd_pcm_open(&pcm_handle, device.utf8().get_data(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); } ERR_FAIL_COND_V(status < 0, ERR_CANT_OPEN); snd_pcm_hw_params_alloca(&hwparams); status = snd_pcm_hw_params_any(pcm_handle, hwparams); CHECK_FAIL(status < 0); status = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); CHECK_FAIL(status < 0); //not interested in anything else status = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE); CHECK_FAIL(status < 0); //todo: support 4 and 6 status = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2); CHECK_FAIL(status < 0); status = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &mix_rate, NULL); CHECK_FAIL(status < 0); // In ALSA the period size seems to be the one that will determine the actual latency // Ref: https://www.alsa-project.org/main/index.php/FramesPeriods unsigned int periods = 2; int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY); buffer_frames = closest_power_of_2(latency * mix_rate / 1000); buffer_size = buffer_frames * periods; period_size = buffer_frames; // set buffer size from project settings status = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size); CHECK_FAIL(status < 0); status = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &period_size, NULL); CHECK_FAIL(status < 0); if (OS::get_singleton()->is_stdout_verbose()) { print_line("audio buffer frames: " + itos(period_size) + " calculated latency: " + itos(period_size * 1000 / mix_rate) + "ms"); } status = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &periods, NULL); CHECK_FAIL(status < 0); status = snd_pcm_hw_params(pcm_handle, hwparams); CHECK_FAIL(status < 0); //snd_pcm_hw_params_free(&hwparams); snd_pcm_sw_params_alloca(&swparams); status = snd_pcm_sw_params_current(pcm_handle, swparams); CHECK_FAIL(status < 0); status = snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, period_size); CHECK_FAIL(status < 0); status = snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);//.........这里部分代码省略.........
开发者ID:ippan,项目名称:godot,代码行数:101,
示例24: snd_spcm_init_duplex/** * /brief Initialize simple PCMs in the duplex mode * /param playback_pcm PCM handle for playback * /param capture_pcm PCM handle for capture * /param rate Sample rate * /param channels Number of channels * /param format PCM format * /param subformat PCM subformat * /param latency Latency type * /param access PCM acceess type * /param xrun_type XRUN type * /param duplex_type Duplex mode * /return 0 if successful, or a negative error code * * /warning The simple PCM API may be broken in the current release. */int snd_spcm_init_duplex(snd_pcm_t *playback_pcm, snd_pcm_t *capture_pcm, unsigned int rate, unsigned int channels, snd_pcm_format_t format, snd_pcm_subformat_t subformat, snd_spcm_latency_t latency, snd_pcm_access_t access, snd_spcm_xrun_type_t xrun_type, snd_spcm_duplex_type_t duplex_type){ int err, i; snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; unsigned int rrate; unsigned int xbuffer_time, buffer_time[2]; unsigned int period_time[2]; snd_pcm_t *pcms[2]; snd_pcm_hw_params_alloca(&hw_params); snd_pcm_sw_params_alloca(&sw_params); assert(playback_pcm); assert(capture_pcm); assert(rate > 5000 && rate < 192000); assert(channels > 1 && channels < 512); pcms[0] = playback_pcm; pcms[1] = capture_pcm; /* * hardware parameters */ err = set_buffer_time(latency, &xbuffer_time); if (err < 0) return err; for (i = 0; i < 2; i++) { buffer_time[i] = xbuffer_time; period_time[i] = i > 0 ? period_time[0] : 0; rrate = rate; err = set_hw_params(pcms[i], hw_params, &rrate, channels, format, subformat, &buffer_time[i], &period_time[i], access); if (err < 0) return err; } if (buffer_time[0] == buffer_time[1] && period_time[0] == period_time[1]) goto __sw_params; if (duplex_type == SND_SPCM_DUPLEX_LIBERAL) goto __sw_params; /* FIXME: */ return -EINVAL; /* * software parameters */__sw_params: for (i = 0; i < 2; i++) { err = set_sw_params(pcms[i], sw_params, xrun_type); if (err < 0) return err; } return 0;}
开发者ID:xenyinzen,项目名称:lx_toolset,代码行数:83,
示例25: now//.........这里部分代码省略......... if ( !fatal ) { err = snd_pcm_hw_params_set_access( handle, hwparams, access ); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_access: err = %1").arg(err); } } if ( !fatal ) { err = setFormat(); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_format: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() ); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 ); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params(handle, hwparams); if ( err < 0 ) { fatal = true; errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params: err = %1").arg(err); } } if( err < 0) { qWarning()<<errMessage; errorState = QAudio::OpenError; deviceState = QAudio::StoppedState; return false; } snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames); buffer_size = snd_pcm_frames_to_bytes(handle,buffer_frames); snd_pcm_hw_params_get_period_size(hwparams,&period_frames, &dir); period_size = snd_pcm_frames_to_bytes(handle,period_frames); snd_pcm_hw_params_get_buffer_time(hwparams,&buffer_time, &dir); snd_pcm_hw_params_get_period_time(hwparams,&period_time, &dir); // Step 3: Set the desired SW parameters. snd_pcm_sw_params_t *swparams; snd_pcm_sw_params_alloca(&swparams); snd_pcm_sw_params_current(handle, swparams); snd_pcm_sw_params_set_start_threshold(handle,swparams,period_frames); snd_pcm_sw_params_set_stop_threshold(handle,swparams,buffer_frames); snd_pcm_sw_params_set_avail_min(handle, swparams,period_frames); snd_pcm_sw_params(handle, swparams); // Step 4: Prepare audio if(audioBuffer == 0) audioBuffer = new char[snd_pcm_frames_to_bytes(handle,buffer_frames)]; snd_pcm_prepare( handle ); snd_pcm_start(handle); // Step 5: Setup callback and timer fallback snd_async_add_pcm_handler(&ahandler, handle, async_callback, this); bytesAvailable = bytesFree(); // Step 6: Start audio processing timer->start(period_time/1000); clockStamp.restart(); timeStamp.restart(); elapsedTimeOffset = 0; errorState = QAudio::NoError; totalTimeValue = 0; opened = true; return true;}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:101,
示例26: set_paramsstatic void set_params(void){ snd_pcm_hw_params_t *params; snd_pcm_sw_params_t *swparams; snd_pcm_uframes_t buffer_size; int err; size_t n; snd_pcm_uframes_t xfer_align; unsigned int rate; snd_pcm_uframes_t start_threshold, stop_threshold; snd_pcm_hw_params_alloca(¶ms); snd_pcm_sw_params_alloca(&swparams); err = snd_pcm_hw_params_any(handle, params); if (err < 0) { error(_("Broken configuration for this PCM: no configurations available")); exit(EXIT_FAILURE); } err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { error(_("Access type not available")); exit(EXIT_FAILURE); } err = snd_pcm_hw_params_set_format(handle, params, hwparams.format); if (err < 0) { error(_("Sample format non available")); exit(EXIT_FAILURE); } err = snd_pcm_hw_params_set_channels(handle, params, hwparams.channels); if (err < 0) { error(_("Channels count non available")); exit(EXIT_FAILURE); }#if 0 err = snd_pcm_hw_params_set_periods_min(handle, params, 2); assert(err >= 0);#endif rate = hwparams.rate; err = snd_pcm_hw_params_set_rate_near(handle, params, &hwparams.rate, 0); assert(err >= 0); if ((float)rate * 1.05 < hwparams.rate || (float)rate * 0.95 > hwparams.rate) { if (!quiet_mode) { char plugex[64]; const char *pcmname = snd_pcm_name(handle); fprintf(stderr, _("Warning: rate is not accurate (requested = %iHz, got = %iHz)/n"), rate, hwparams.rate); if (! pcmname || strchr(snd_pcm_name(handle), ':')) *plugex = 0; else snprintf(plugex, sizeof(plugex), "(-Dplug:%s)", snd_pcm_name(handle)); fprintf(stderr, _(" please, try the plug plugin %s/n"), plugex); } } rate = hwparams.rate; if (buffer_time == 0 && buffer_frames == 0) { err = snd_pcm_hw_params_get_buffer_time_max(params, &buffer_time, 0); assert(err >= 0); if (buffer_time > 500000) buffer_time = 500000; } if (period_time == 0 && period_frames == 0) { if (buffer_time > 0) period_time = buffer_time / 4; else period_frames = buffer_frames / 4; } if (period_time > 0) err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, 0); else err = snd_pcm_hw_params_set_period_size_near(handle, params, &period_frames, 0); assert(err >= 0); if (buffer_time > 0) { err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, 0); } else { err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &buffer_frames); } assert(err >= 0); err = snd_pcm_hw_params(handle, params); if (err < 0) { error(_("Unable to install hw params:")); snd_pcm_hw_params_dump(params, log); exit(EXIT_FAILURE); } snd_pcm_hw_params_get_period_size(params, &chunk_size, 0); snd_pcm_hw_params_get_buffer_size(params, &buffer_size); if (chunk_size == buffer_size) { error(_("Can't use period equal to buffer size (%lu == %lu)"), chunk_size, buffer_size); exit(EXIT_FAILURE); } snd_pcm_sw_params_current(handle, swparams); err = snd_pcm_sw_params_get_xfer_align(swparams, &xfer_align); if (err < 0) { error(_("Unable to obtain xfer align/n"));//.........这里部分代码省略.........
开发者ID:hishamhm,项目名称:protosampler,代码行数:101,
示例27: aplaypop_openstatic int aplaypop_open(void){ int err; snd_pcm_t *handle; if (pcm_handle) return 0; snd_pcm_info_t *info; snd_pcm_info_alloca(&info); snd_output_t *log; err = snd_output_stdio_attach(&log, stderr, 0); assert(err == 0); err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0); if (err != 0) { fprintf(stderr, "snd_pcm_open(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } err = snd_pcm_nonblock(handle, 0); if (err != 0) { fprintf(stderr, "snd_pcm_nonblock(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } err = snd_pcm_info(handle, info); if (err != 0) { fprintf(stderr, "snd_pcm_info(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } // DOESN'T WORK! err = snd_pcm_set_params(handle, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, CHANNELS, RATE, 1, 50000); if (err != 0) { fprintf(stderr, "snd_pcm_set_params(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } // RIGHT WAY: snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; unsigned int channels = CHANNELS; unsigned int rate = RATE; snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); err = snd_pcm_hw_params_any(handle, hwparams); if (err != 0) { fprintf(stderr, "Broken configuration for this PCM: %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } err = snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); if (err != 0) { fprintf(stderr, "snd_pcm_hw_params_set_access(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } err = snd_pcm_hw_params_set_format(handle, hwparams, format); if (err != 0) { fprintf(stderr, "snd_pcm_hw_params_set_format(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } err = snd_pcm_hw_params_set_channels(handle, hwparams, channels); if (err != 0) { fprintf(stderr, "snd_pcm_hw_params_set_channels(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); } err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &rate, 0); if (err != 0) { fprintf(stderr, "snd_pcm_hw_params_set_rate_near(): %s/n", snd_strerror(err)); exit(EXIT_FAILURE); }/* unsigned buffer_time = 0; snd_pcm_uframes_t buffer_frames = 0; if (buffer_time == 0 && buffer_frames == 0) { err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, 0); assert(err == 0); if (buffer_time > 500000) buffer_time = 500000; } unsigned period_time = 0; snd_pcm_uframes_t period_frames = 0; if (period_time == 0 && period_frames == 0) { if (buffer_time > 0) period_time = buffer_time / 4; else period_frames = buffer_frames / 4; } if (period_time > 0) err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0); else err = snd_pcm_hw_params_set_period_size_near(handle, hwparams, &period_frames, 0);//.........这里部分代码省略.........
开发者ID:vovcat,项目名称:xcrutchd,代码行数:101,
示例28: ga_alsa_set_paramintga_alsa_set_param(struct Xcap_alsa_param *param) { snd_pcm_hw_params_t *hwparams = NULL; snd_pcm_sw_params_t *swparams = NULL; size_t bits_per_sample; unsigned int rate; unsigned int buffer_time = 500000; // in the unit of microsecond unsigned int period_time = 125000; // = buffer_time/4; int monotonic = 0; snd_pcm_uframes_t start_threshold, stop_threshold; int err; // snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); if((err = snd_pcm_hw_params_any(param->handle, hwparams)) < 0) { ga_error("ALSA: set_param - no configurations available/n"); return -1; } if((err = snd_pcm_hw_params_set_access(param->handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { ga_error("ALSA: set_param - access type (interleaved) not available/n"); return -1; } if((err = snd_pcm_hw_params_set_format(param->handle, hwparams, param->format)) < 0) { ga_error("ALSA: set_param - unsupported sample format./n"); return -1; } if((err = snd_pcm_hw_params_set_channels(param->handle, hwparams, param->channels)) < 0) { ga_error("ALSA: set_param - channles count not available/n"); return -1; } rate = param->samplerate; if((err = snd_pcm_hw_params_set_rate_near(param->handle, hwparams, &rate, 0)) < 0) { ga_error("ALSA: set_param - set rate failed./n"); return -1; } if((double)param->samplerate*1.05 < rate || (double)param->samplerate*0.95 > rate) { ga_error("ALSA: set_param/warning - inaccurate rate (req=%iHz, got=%iHz)/n", param->samplerate, rate); } // period_time = buffer_time/4; if((err = snd_pcm_hw_params_set_period_time_near(param->handle, hwparams, &period_time, 0)) < 0) { ga_error("ALSA: set_param - set period time failed./n"); return -1; } if((err = snd_pcm_hw_params_set_buffer_time_near(param->handle, hwparams, &buffer_time, 0)) < 0) { ga_error("ALSA: set_param - set buffer time failed./n"); return -1; } // monotonic = snd_pcm_hw_params_is_monotonic(hwparams); if((err = snd_pcm_hw_params(param->handle, hwparams)) < 0) { ga_error("ALSA: set_param - unable to install hw params:"); snd_pcm_hw_params_dump(hwparams, sndlog); return -1; } snd_pcm_hw_params_get_period_size(hwparams, ¶m->chunk_size, 0); snd_pcm_hw_params_get_buffer_size(hwparams, ¶m->buffer_size); if(param->chunk_size == param->buffer_size) { ga_error("ALSA: set_param - cannot use period equal to buffer size (%lu==%lu)/n", param->chunk_size, param->buffer_size); return -1; } // snd_pcm_sw_params_current(param->handle, swparams); err = snd_pcm_sw_params_set_avail_min(param->handle, swparams, param->chunk_size); // start_delay = 1 for capture start_threshold = (double) param->samplerate * /*start_delay=*/ 1 / 1000000; if(start_threshold < 1) start_threshold = 1; if(start_threshold > param->buffer_size) start_threshold = param->buffer_size; if((err = snd_pcm_sw_params_set_start_threshold(param->handle, swparams, start_threshold)) < 0) { ga_error("ALSA: set_param - set start threshold failed./n"); return -1; } // stop_delay = 0 stop_threshold = param->buffer_size; if((err = snd_pcm_sw_params_set_stop_threshold(param->handle, swparams, stop_threshold)) < 0) { ga_error("ALSA: set_param - set stop threshold failed./n"); return -1; } // if(snd_pcm_sw_params(param->handle, swparams) < 0) { ga_error("ALSA: set_param - unable to install sw params:"); snd_pcm_sw_params_dump(swparams, sndlog); return -1; } bits_per_sample = snd_pcm_format_physical_width(param->format); if(param->bits_per_sample != bits_per_sample) { ga_error("ALSA: set_param - BPS/HW configuration mismatched %d != %d)/n", param->bits_per_sample, bits_per_sample); } param->bits_per_frame = param->bits_per_sample * param->channels; param->chunk_bytes = param->chunk_size * param->bits_per_frame / 8; return 0;}
开发者ID:Ljinod,项目名称:gaminganywhere,代码行数:96,
示例29: ai_alsa_setupint ai_alsa_setup(audio_in_t *ai){ snd_pcm_hw_params_t *params; snd_pcm_sw_params_t *swparams; snd_pcm_uframes_t buffer_size, period_size; int err; int dir; unsigned int rate; snd_pcm_hw_params_alloca(¶ms); snd_pcm_sw_params_alloca(&swparams); err = snd_pcm_hw_params_any(ai->alsa.handle, params); if (err < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Broken configuration for this PCM: no configurations available./n"); return -1; } err = snd_pcm_hw_params_set_access(ai->alsa.handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Access type not available./n"); return -1; } err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE); if (err < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Sample format not available./n"); return -1; } err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels); if (err < 0) { snd_pcm_hw_params_get_channels(params, &ai->channels); mp_tmsg(MSGT_TV, MSGL_ERR, "Channel count not available - reverting to default: %d/n", ai->channels); } else { ai->channels = ai->req_channels; } dir = 0; rate = ai->req_samplerate; err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, &rate, &dir); if (err < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Cannot set samplerate./n"); } ai->samplerate = rate; dir = 0; ai->alsa.buffer_time = 1000000; err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, &ai->alsa.buffer_time, &dir); if (err < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Cannot set buffer time./n"); } dir = 0; ai->alsa.period_time = ai->alsa.buffer_time / 4; err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, &ai->alsa.period_time, &dir); if (err < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Cannot set period time./n"); } err = snd_pcm_hw_params(ai->alsa.handle, params); if (err < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Unable to install hardware parameters: %s", snd_strerror(err)); snd_pcm_hw_params_dump(params, ai->alsa.log); return -1; } dir = -1; snd_pcm_hw_params_get_period_size(params, &period_size, &dir); snd_pcm_hw_params_get_buffer_size(params, &buffer_size); ai->alsa.chunk_size = period_size; if (period_size == buffer_size) { mp_tmsg(MSGT_TV, MSGL_ERR, "Can't use period equal to buffer size (%u == %lu)/n", ai->alsa.chunk_size, (long)buffer_size); return -1; } snd_pcm_sw_params_current(ai->alsa.handle, swparams); err = snd_pcm_sw_params_set_avail_min(ai->alsa.handle, swparams, ai->alsa.chunk_size); err = snd_pcm_sw_params_set_start_threshold(ai->alsa.handle, swparams, 0); err = snd_pcm_sw_params_set_stop_threshold(ai->alsa.handle, swparams, buffer_size); if (snd_pcm_sw_params(ai->alsa.handle, swparams) < 0) { mp_tmsg(MSGT_TV, MSGL_ERR, "Unable to install software parameters:/n"); snd_pcm_sw_params_dump(swparams, ai->alsa.log); return -1; } if (mp_msg_test(MSGT_TV, MSGL_V)) { snd_pcm_dump(ai->alsa.handle, ai->alsa.log); } ai->alsa.bits_per_sample = snd_pcm_format_physical_width(SND_PCM_FORMAT_S16_LE); ai->alsa.bits_per_frame = ai->alsa.bits_per_sample * ai->channels; ai->blocksize = ai->alsa.chunk_size * ai->alsa.bits_per_frame / 8; ai->samplesize = ai->alsa.bits_per_sample;//.........这里部分代码省略.........
开发者ID:ArcherSeven,项目名称:mpv,代码行数:101,
示例30: ags_devout_alsa_initvoidags_devout_alsa_init(AgsSoundcard *soundcard, GError **error){ AgsDevout *devout; int rc; snd_pcm_t *handle; snd_pcm_hw_params_t *hwparams; unsigned int val; snd_pcm_uframes_t frames; unsigned int rate; unsigned int rrate; unsigned int channels; snd_pcm_uframes_t size; snd_pcm_sframes_t buffer_size; snd_pcm_sframes_t period_size; snd_pcm_sw_params_t *swparams; int period_event = 0; int err, dir; static unsigned int period_time = 100000; static snd_pcm_format_t format = SND_PCM_FORMAT_S16; devout = AGS_DEVOUT(soundcard); /* */ devout->flags |= (AGS_DEVOUT_BUFFER3 | AGS_DEVOUT_START_PLAY | AGS_DEVOUT_PLAY | AGS_DEVOUT_NONBLOCKING); devout->note_offset = 0; memset(devout->buffer[0], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short)); memset(devout->buffer[1], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short)); memset(devout->buffer[2], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short)); memset(devout->buffer[3], 0, devout->dsp_channels * devout->buffer_size * sizeof(signed short)); /* Open PCM device for playback. */ if ((err = snd_pcm_open(&handle, devout->out.alsa.device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { printf("Playback open error: %s/n", snd_strerror(err)); g_set_error(error, AGS_DEVOUT_ERROR, AGS_DEVOUT_ERROR_LOCKED_SOUNDCARD, "unable to open pcm device: %s/n/0", snd_strerror(err)); return; } snd_pcm_hw_params_alloca(&hwparams); snd_pcm_sw_params_alloca(&swparams); /* choose all parameters */ err = snd_pcm_hw_params_any(handle, hwparams); if (err < 0) { printf("Broken configuration for playback: no configurations available: %s/n", snd_strerror(err)); return; } /* set hardware resampling */ err = snd_pcm_hw_params_set_rate_resample(handle, hwparams, 1); if (err < 0) { printf("Resampling setup failed for playback: %s/n", snd_strerror(err)); return; } /* set the interleaved read/write format */ err = snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { printf("Access type not available for playback: %s/n", snd_strerror(err)); return; } /* set the sample format */ err = snd_pcm_hw_params_set_format(handle, hwparams, format); if (err < 0) { printf("Sample format not available for playback: %s/n", snd_strerror(err)); return; } /* set the count of channels */ channels = devout->dsp_channels; err = snd_pcm_hw_params_set_channels(handle, hwparams, channels); if (err < 0) { printf("Channels count (%i) not available for playbacks: %s/n", channels, snd_strerror(err)); return; } /* set the stream rate */ rate = devout->samplerate; rrate = rate; err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &rrate, 0); if (err < 0) { printf("Rate %iHz not available for playback: %s/n", rate, snd_strerror(err)); return; } if (rrate != rate) { printf("Rate doesn't match (requested %iHz, get %iHz)/n", rate, err);//.........这里部分代码省略.........
开发者ID:joelkraehemann,项目名称:gsequencer,代码行数:101,
注:本文中的snd_pcm_sw_params_alloca函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ snd_pcm_sw_params_current函数代码示例 C++ snd_pcm_sw_params函数代码示例 |