本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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);
}
示例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");
}
示例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)
{
}*/
}
示例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;
}
示例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)
{
}*/
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}