本文整理汇总了C++中snd_pcm_sw_params函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_sw_params函数的具体用法?C++ snd_pcm_sw_params怎么用?C++ snd_pcm_sw_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_pcm_sw_params函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: snd_pcm_ioctl_sw_params_compat
static int snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream *substream,
struct snd_pcm_sw_params32 __user *src)
{
struct snd_pcm_sw_params params;
snd_pcm_uframes_t boundary;
int err;
memset(¶ms, 0, sizeof(params));
if (get_user(params.tstamp_mode, &src->tstamp_mode) ||
get_user(params.period_step, &src->period_step) ||
get_user(params.sleep_min, &src->sleep_min) ||
get_user(params.avail_min, &src->avail_min) ||
get_user(params.xfer_align, &src->xfer_align) ||
get_user(params.start_threshold, &src->start_threshold) ||
get_user(params.stop_threshold, &src->stop_threshold) ||
get_user(params.silence_threshold, &src->silence_threshold) ||
get_user(params.silence_size, &src->silence_size))
return -EFAULT;
/*
* Check silent_size parameter. Since we have 64bit boundary,
* silence_size must be compared with the 32bit boundary.
*/
boundary = recalculate_boundary(substream->runtime);
if (boundary && params.silence_size >= boundary)
params.silence_size = substream->runtime->boundary;
err = snd_pcm_sw_params(substream, ¶ms);
if (err < 0)
return err;
if (boundary && put_user(boundary, &src->boundary))
return -EFAULT;
return err;
}
开发者ID:Core2idiot,项目名称:Kernel-Samsung-3.0...-,代码行数:32,代码来源:pcm_compat.c
示例3: setSWParams
// returns 1 if successful
int setSWParams(AlsaPcmInfo* info) {
int ret;
/* get the current swparams */
ret = snd_pcm_sw_params_current(info->handle, info->swParams);
if (ret < 0) {
ERROR1("Unable to determine current swparams: %s\n", snd_strerror(ret));
return FALSE;
}
/* never start the transfer automatically */
if (!setStartThresholdNoCommit(info, FALSE /* don't use threshold */)) {
return FALSE;
}
/* allow the transfer when at least period_size samples can be processed */
ret = snd_pcm_sw_params_set_avail_min(info->handle, info->swParams, info->periodSize);
if (ret < 0) {
ERROR1("Unable to set avail min for playback: %s\n", snd_strerror(ret));
return FALSE;
}
/* align all transfers to 1 sample */
ret = snd_pcm_sw_params_set_xfer_align(info->handle, info->swParams, 1);
if (ret < 0) {
ERROR1("Unable to set transfer align: %s\n", snd_strerror(ret));
return FALSE;
}
/* write the parameters to the playback device */
ret = snd_pcm_sw_params(info->handle, info->swParams);
if (ret < 0) {
ERROR1("Unable to set sw params: %s\n", snd_strerror(ret));
return FALSE;
}
return TRUE;
}
开发者ID:michalwarecki,项目名称:ManagedRuntimeInitiative,代码行数:35,代码来源:PLATFORM_API_LinuxOS_ALSA_PCM.c
示例4: alsa_set_sw_params
static void alsa_set_sw_params(struct alsa_dev *dev, snd_pcm_t *handle,
int period, int thres)
{
int ret;
snd_pcm_sw_params_t *sw_params;
ret = snd_pcm_sw_params_malloc(&sw_params);
if (ret < 0)
syslog_panic("Cannot allocate software parameters: %s\n",
snd_strerror(ret));
ret = snd_pcm_sw_params_current(handle, sw_params);
if (ret < 0)
syslog_panic("Cannot initialize software parameters: %s\n",
snd_strerror(ret));
ret = snd_pcm_sw_params_set_avail_min(handle, sw_params, period);
if (ret < 0)
syslog_panic("Cannot set minimum available count: %s\n",
snd_strerror(ret));
if (thres) {
ret = snd_pcm_sw_params_set_start_threshold(handle, sw_params,
period);
if (ret < 0)
syslog_panic("Cannot set start mode: %s\n",
snd_strerror(ret));
}
ret = snd_pcm_sw_params(handle, sw_params);
if (ret < 0)
syslog_panic("Cannot set software parameters: %s\n",
snd_strerror(ret));
snd_pcm_sw_params_free(sw_params);
}
开发者ID:ipoerner,项目名称:transsip,代码行数:32,代码来源:alsa.c
示例5: audio_renderer_init
static void audio_renderer_init() {
int rc;
decoder = opus_decoder_create(SAMPLE_RATE, CHANNEL_COUNT, &rc);
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
snd_pcm_uframes_t period_size = FRAME_SIZE * CHANNEL_COUNT * 2;
snd_pcm_uframes_t buffer_size = 12 * period_size;
unsigned int sampleRate = SAMPLE_RATE;
/* Open PCM device for playback. */
CHECK_RETURN(snd_pcm_open(&handle, audio_device, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK))
/* Set hardware parameters */
CHECK_RETURN(snd_pcm_hw_params_malloc(&hw_params));
CHECK_RETURN(snd_pcm_hw_params_any(handle, hw_params));
CHECK_RETURN(snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED));
CHECK_RETURN(snd_pcm_hw_params_set_format(handle, hw_params, SND_PCM_FORMAT_S16_LE));
CHECK_RETURN(snd_pcm_hw_params_set_rate_near(handle, hw_params, &sampleRate, NULL));
CHECK_RETURN(snd_pcm_hw_params_set_channels(handle, hw_params, CHANNEL_COUNT));
CHECK_RETURN(snd_pcm_hw_params_set_buffer_size_near(handle, hw_params, &buffer_size));
CHECK_RETURN(snd_pcm_hw_params_set_period_size_near(handle, hw_params, &period_size, NULL));
CHECK_RETURN(snd_pcm_hw_params(handle, hw_params));
snd_pcm_hw_params_free(hw_params);
/* Set software parameters */
CHECK_RETURN(snd_pcm_sw_params_malloc(&sw_params));
CHECK_RETURN(snd_pcm_sw_params_current(handle, sw_params));
CHECK_RETURN(snd_pcm_sw_params_set_start_threshold(handle, sw_params, buffer_size - period_size));
CHECK_RETURN(snd_pcm_sw_params_set_avail_min(handle, sw_params, period_size));
CHECK_RETURN(snd_pcm_sw_params(handle, sw_params));
snd_pcm_sw_params_free(sw_params);
CHECK_RETURN(snd_pcm_prepare(handle));
}
开发者ID:Tri125,项目名称:moonlight-embedded,代码行数:35,代码来源:audio.c
示例6: set_swparams
int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams)
{
int err;
/* get the current swparams */
err = snd_pcm_sw_params_current(handle, swparams);
if (err < 0) {
printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err));
return err;
}
/* start the transfer when the buffer is almost full: */
/* (buffer_size / avail_min) * avail_min */
//err = snd_pcm_sw_params_set_start_threshold(handle, swparams, (buffer_size / period_size) * period_size);
err = snd_pcm_sw_params_set_start_threshold(handle, swparams, period_size * periods - arnold_frame_size);
if (err < 0) {
printf("Unable to set start threshold mode for playback: %s\n", snd_strerror(err));
return err;
}
/* allow the transfer when at least period_size samples can be processed */
err = snd_pcm_sw_params_set_avail_min(handle, swparams, arnold_frame_size);
if (err < 0) {
printf("Unable to set avail min for playback: %s\n", snd_strerror(err));
return err;
}
/* write the parameters to the playback device */
err = snd_pcm_sw_params(handle, swparams);
if (err < 0) {
printf("Unable to set sw params for playback: %s\n", snd_strerror(err));
return err;
}
return 0;
}
开发者ID:BackupTheBerlios,项目名称:arnold,代码行数:32,代码来源:alsasound-common.c
示例7: set_sw_params
static int set_sw_params(snd_pcm_t *pcm,
snd_pcm_sw_params_t *sw_params,
snd_spcm_xrun_type_t xrun_type)
{
int err;
err = snd_pcm_sw_params_current(pcm, sw_params);
if (err < 0)
return err;
err = snd_pcm_sw_params_set_start_threshold(pcm, sw_params, (pcm->buffer_size / pcm->period_size) * pcm->period_size);
if (err < 0)
return err;
err = snd_pcm_sw_params_set_avail_min(pcm, sw_params, pcm->period_size);
if (err < 0)
return err;
switch (xrun_type) {
case SND_SPCM_XRUN_STOP:
err = snd_pcm_sw_params_set_stop_threshold(pcm, sw_params, pcm->buffer_size);
break;
case SND_SPCM_XRUN_IGNORE:
err = snd_pcm_sw_params_set_stop_threshold(pcm, sw_params, pcm->boundary);
break;
default:
return -EINVAL;
}
if (err < 0)
return err;
err = snd_pcm_sw_params_set_xfer_align(pcm, sw_params, 1);
if (err < 0)
return err;
err = snd_pcm_sw_params(pcm, sw_params);
if (err < 0)
return err;
return 0;
}
开发者ID:xenyinzen,项目名称:lx_toolset,代码行数:35,代码来源:pcm_simple.c
示例8: tsmf_alsa_set_format
static BOOL tsmf_alsa_set_format(ITSMFAudioDevice *audio,
UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample)
{
int error;
snd_pcm_uframes_t frames;
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
if(!alsa->out_handle)
return FALSE;
snd_pcm_drop(alsa->out_handle);
alsa->actual_rate = alsa->source_rate = sample_rate;
alsa->actual_channels = alsa->source_channels = channels;
alsa->bytes_per_sample = bits_per_sample / 8;
error = snd_pcm_hw_params_malloc(&hw_params);
if(error < 0)
{
WLog_ERR(TAG, "snd_pcm_hw_params_malloc failed");
return FALSE;
}
snd_pcm_hw_params_any(alsa->out_handle, hw_params);
snd_pcm_hw_params_set_access(alsa->out_handle, hw_params,
SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(alsa->out_handle, hw_params,
SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_rate_near(alsa->out_handle, hw_params,
&alsa->actual_rate, NULL);
snd_pcm_hw_params_set_channels_near(alsa->out_handle, hw_params,
&alsa->actual_channels);
frames = sample_rate;
snd_pcm_hw_params_set_buffer_size_near(alsa->out_handle, hw_params,
&frames);
snd_pcm_hw_params(alsa->out_handle, hw_params);
snd_pcm_hw_params_free(hw_params);
error = snd_pcm_sw_params_malloc(&sw_params);
if(error < 0)
{
WLog_ERR(TAG, "snd_pcm_sw_params_malloc");
return FALSE;
}
snd_pcm_sw_params_current(alsa->out_handle, sw_params);
snd_pcm_sw_params_set_start_threshold(alsa->out_handle, sw_params,
frames / 2);
snd_pcm_sw_params(alsa->out_handle, sw_params);
snd_pcm_sw_params_free(sw_params);
snd_pcm_prepare(alsa->out_handle);
DEBUG_TSMF("sample_rate %d channels %d bits_per_sample %d",
sample_rate, channels, bits_per_sample);
DEBUG_TSMF("hardware buffer %d frames", (int)frames);
if((alsa->actual_rate != alsa->source_rate) ||
(alsa->actual_channels != alsa->source_channels))
{
DEBUG_TSMF("actual rate %d / channel %d is different "
"from source rate %d / channel %d, resampling required.",
alsa->actual_rate, alsa->actual_channels,
alsa->source_rate, alsa->source_channels);
}
return TRUE;
}
开发者ID:BUGgs,项目名称:FreeRDP,代码行数:59,代码来源:tsmf_alsa.c
示例9: audio_read_header
static av_cold int audio_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
{
AlsaData *s = s1->priv_data;
AVStream *st;
int ret;
enum CodecID codec_id;
snd_pcm_sw_params_t *sw_params;
st = av_new_stream(s1, 0);
if (!st) {
av_log(s1, AV_LOG_ERROR, "Cannot add stream\n");
return AVERROR(ENOMEM);
}
codec_id = s1->audio_codec_id;
ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->channels,
&codec_id);
if (ret < 0) {
return AVERROR(EIO);
}
if (snd_pcm_type(s->h) != SND_PCM_TYPE_HW)
av_log(s1, AV_LOG_WARNING,
"capture with some ALSA plugins, especially dsnoop, "
"may hang.\n");
ret = snd_pcm_sw_params_malloc(&sw_params);
if (ret < 0) {
av_log(s1, AV_LOG_ERROR, "cannot allocate software parameters structure (%s)\n",
snd_strerror(ret));
goto fail;
}
snd_pcm_sw_params_current(s->h, sw_params);
snd_pcm_sw_params_set_tstamp_mode(s->h, sw_params, SND_PCM_TSTAMP_ENABLE);
ret = snd_pcm_sw_params(s->h, sw_params);
snd_pcm_sw_params_free(sw_params);
if (ret < 0) {
av_log(s1, AV_LOG_ERROR, "cannot install ALSA software parameters (%s)\n",
snd_strerror(ret));
goto fail;
}
/* take real parameters */
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = codec_id;
st->codec->sample_rate = s->sample_rate;
st->codec->channels = s->channels;
av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
return 0;
fail:
snd_pcm_close(s->h);
return AVERROR(EIO);
}
开发者ID:ttrask,项目名称:unf,代码行数:59,代码来源:alsa-audio-dec.c
示例10: set_params
static int
set_params(struct alsa_device_data * alsa_data)
{
snd_pcm_hw_params_t * hw_params;
snd_pcm_sw_params_t * sw_params;
int error;
snd_pcm_uframes_t frames;
snd_pcm_drop(alsa_data->out_handle);
error = snd_pcm_hw_params_malloc(&hw_params);
if (error < 0)
{
LLOGLN(0, ("set_params: snd_pcm_hw_params_malloc failed"));
return 1;
}
snd_pcm_hw_params_any(alsa_data->out_handle, hw_params);
snd_pcm_hw_params_set_access(alsa_data->out_handle, hw_params,
SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(alsa_data->out_handle, hw_params,
alsa_data->format);
snd_pcm_hw_params_set_rate_near(alsa_data->out_handle, hw_params,
&alsa_data->actual_rate, NULL);
snd_pcm_hw_params_set_channels_near(alsa_data->out_handle, hw_params,
&alsa_data->actual_channels);
frames = alsa_data->actual_rate * 4;
snd_pcm_hw_params_set_buffer_size_near(alsa_data->out_handle, hw_params,
&frames);
snd_pcm_hw_params(alsa_data->out_handle, hw_params);
snd_pcm_hw_params_free(hw_params);
error = snd_pcm_sw_params_malloc(&sw_params);
if (error < 0)
{
LLOGLN(0, ("set_params: snd_pcm_sw_params_malloc"));
return 1;
}
snd_pcm_sw_params_current(alsa_data->out_handle, sw_params);
snd_pcm_sw_params_set_start_threshold(alsa_data->out_handle, sw_params,
frames / 2);
snd_pcm_sw_params(alsa_data->out_handle, sw_params);
snd_pcm_sw_params_free(sw_params);
snd_pcm_prepare(alsa_data->out_handle);
LLOGLN(10, ("set_params: hardware buffer %d frames, playback buffer %.2g seconds",
(int)frames, (double)frames / 2.0 / (double)alsa_data->actual_rate));
if ((alsa_data->actual_rate != alsa_data->source_rate) ||
(alsa_data->actual_channels != alsa_data->source_channels))
{
LLOGLN(0, ("set_params: actual rate %d / channel %d is different from source rate %d / channel %d, resampling required.",
alsa_data->actual_rate, alsa_data->actual_channels, alsa_data->source_rate, alsa_data->source_channels));
}
return 0;
}
开发者ID:FreeRDP,项目名称:FreeRDP-old,代码行数:55,代码来源:rdpsnd_alsa.c
示例11: printf
int AudioAlsa::setSWParams()
{
int err;
// get the current swparams
if( ( err = snd_pcm_sw_params_current( m_handle, m_swParams ) ) < 0 )
{
printf( "Unable to determine current swparams for playback: %s"
"\n", snd_strerror( err ) );
return err;
}
// start the transfer when a period is full
if( ( err = snd_pcm_sw_params_set_start_threshold( m_handle,
m_swParams, m_periodSize ) ) < 0 )
{
printf( "Unable to set start threshold mode for playback: %s\n",
snd_strerror( err ) );
return err;
}
// allow the transfer when at least m_periodSize samples can be
// processed
if( ( err = snd_pcm_sw_params_set_avail_min( m_handle, m_swParams,
m_periodSize ) ) < 0 )
{
printf( "Unable to set avail min for playback: %s\n",
snd_strerror( err ) );
return err;
}
// align all transfers to 1 sample
#if SND_LIB_VERSION < ((1<<16)|(0)|16)
if( ( err = snd_pcm_sw_params_set_xfer_align( m_handle,
m_swParams, 1 ) ) < 0 )
{
printf( "Unable to set transfer align for playback: %s\n",
snd_strerror( err ) );
return err;
}
#endif
// write the parameters to the playback device
if( ( err = snd_pcm_sw_params( m_handle, m_swParams ) ) < 0 )
{
printf( "Unable to set sw params for playback: %s\n",
snd_strerror( err ) );
return err;
}
return 0; // all ok
}
开发者ID:uro5h,项目名称:lmms,代码行数:53,代码来源:AudioAlsa.cpp
示例12: 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
示例13: setparams_set
static int setparams_set(snd_pcm_t *handle,
snd_pcm_hw_params_t *params,
snd_pcm_sw_params_t *swparams,
snd_pcm_uframes_t start_treshold,
const char *id)
{
int err;
err = snd_pcm_hw_params(handle, params);
if (err < 0) {
fprintf(error_fp, "alsa: Unable to set hw params for %s: %s\n",
id, snd_strerror(err));
return err;
}
err = snd_pcm_sw_params_current(handle, swparams);
if (err < 0) {
fprintf(error_fp, "alsa: Unable to determine current swparams for %s: %s\n",
id, snd_strerror(err));
return err;
}
err = snd_pcm_sw_params_set_start_threshold(handle, swparams,
start_treshold);
if (err < 0) {
fprintf(error_fp, "alsa: Unable to set start threshold mode for %s: %s\n",
id, snd_strerror(err));
return err;
}
err = snd_pcm_sw_params_set_avail_min(handle, swparams, 4);
if (err < 0) {
fprintf(error_fp, "alsa: Unable to set avail min for %s: %s\n",
id, snd_strerror(err));
return err;
}
err = snd_pcm_sw_params_set_tstamp_mode(handle, swparams, SND_PCM_TSTAMP_ENABLE);
if (err < 0) {
fprintf(error_fp, "alsa: Unable to enable timestamps for %s: %s\n",
id, snd_strerror(err));
}
err = snd_pcm_sw_params(handle, swparams);
if (err < 0) {
fprintf(error_fp, "alsa: Unable to set sw params for %s: %s\n",
id, snd_strerror(err));
return err;
}
return 0;
}
开发者ID:doriangarcia,项目名称:v4l-utils,代码行数:49,代码来源:alsa_stream.c
示例14: setStartThreshold
int setStartThreshold(AlsaPcmInfo* info, int useThreshold) {
int ret = 0;
if (!setStartThresholdNoCommit(info, useThreshold)) {
ret = -1;
}
if (ret == 0) {
// commit it
ret = snd_pcm_sw_params(info->handle, info->swParams);
if (ret < 0) {
ERROR1("Unable to set sw params: %s\n", snd_strerror(ret));
}
}
return (ret == 0)?TRUE:FALSE;
}
开发者ID:michalwarecki,项目名称:ManagedRuntimeInitiative,代码行数:15,代码来源:PLATFORM_API_LinuxOS_ALSA_PCM.c
示例15: set_swparams
/**************************************************************************************
* set_swparams
* history: (1) 2014 03 30 mhb
*
**************************************************************************************/
static int set_swparams(snd_pcm_t *handle,
snd_pcm_sw_params_t *swparams)
{
int err;
/* get the current swparams */
err = snd_pcm_sw_params_current(handle, swparams);
if (err < 0)
{
printf("Unable to determine current swparams : %s\n", snd_strerror(err));
return err;
}
/* start the transfer when the buffer is almost full: */
/* (buffer_size / avail_min) * avail_min */
err = snd_pcm_sw_params_set_start_threshold(handle, swparams, (buffer_size / period_size) * period_size);
//err = snd_pcm_sw_params_set_start_threshold(handle, swparams, 3*period_size);// mhb| 修改此值,太小程序会卡死
if (err < 0)
{
printf("Unable to set start threshold mode : %s\n", snd_strerror(err));
return err;
}
/* allow the transfer when at least period_size samples can be processed */
/* or disable this mechanism when period event is enabled (aka interrupt like style processing) */
err = snd_pcm_sw_params_set_avail_min(handle, swparams, period_event ? buffer_size : period_size);
//err = snd_pcm_sw_params_set_avail_min(handle, swparams, 0);//mhb
if (err < 0)
{
printf("Unable to set avail min : %s\n", snd_strerror(err));
return err;
}
/* enable period events when requested */
if (period_event)
{
err = snd_pcm_sw_params_set_period_event(handle, swparams, 1);
if (err < 0)
{
printf("Unable to set period event: %s\n", snd_strerror(err));
return err;
}
}
/* write the parameters to the playback device */
err = snd_pcm_sw_params(handle, swparams);
if (err < 0)
{
printf("Unable to set sw params : %s\n", snd_strerror(err));
return err;
}
return 0;
}
开发者ID:hello2mhb,项目名称:mhbcode,代码行数:53,代码来源:server.c
示例16: 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
示例17: 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
示例18: laudio_alsa_set_start_threshold
static int
laudio_alsa_set_start_threshold(snd_pcm_uframes_t threshold)
{
snd_pcm_sw_params_t *sw_params;
int ret;
ret = snd_pcm_sw_params_malloc(&sw_params);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not allocate sw params: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_sw_params_current(hdl, sw_params);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not retrieve current sw params: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_sw_params_set_start_threshold(hdl, sw_params, threshold);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set start threshold: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_sw_params(hdl, sw_params);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set sw params: %s\n", snd_strerror(ret));
goto out_fail;
}
return 0;
out_fail:
snd_pcm_sw_params_free(sw_params);
return -1;
}
开发者ID:feihugao,项目名称:forked-daapd,代码行数:45,代码来源:laudio_alsa.c
示例19: 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
示例20: 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
注:本文中的snd_pcm_sw_params函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论