本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: alsa_open
int 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,代码来源:audio_alsa.c
示例2: snd_pcm_hw_params_alloca
static 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,代码来源:alsa_in.c
示例3: snd_pcm_hw_params_alloca
static 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,代码来源:alsa_out.c
示例4: fprintf
snd_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,代码来源:miniFMsynth.c
示例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,代码来源:server.c
示例6: main
int 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,代码来源:alsa_play.c
示例7: alsa_open_audio
BOOL 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,代码来源:alsasound-common.c
示例8: main
int 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,代码来源:alsa_capture_play+(copy).c
示例9: set_params
static 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,代码来源:newPlayer1.c
示例10: mixer_open
void 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,代码来源:mixer.c
示例11: set_mic_swparams
int
set_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,代码来源:Setup.c
示例12: drvHostALSAAudioSetThreshold
static 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,代码来源:DrvHostALSAAudio.cpp
示例13: alsa_set_hwparams
static 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,代码来源:hw_audio_alsa.c
示例14: sa_stream_get_min_write
int
sa_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,代码来源:sydney_audio_alsa.c
示例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,代码来源:ao_alsa09.c
示例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 buffer
mp_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,代码来源:AudioDriver_ALSA.cpp
示例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,代码来源:pcm_cras.c
示例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,代码来源:pcm_simple.c
示例19: fprintf
snd_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,代码来源:ShaderDemoX.c
示例20: snd_pcm_sw_params_alloca
bool 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,代码来源:AESinkALSA.cpp
注:本文中的snd_pcm_sw_params_alloca函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论