本文整理汇总了C++中snd_pcm_hw_params_get_buffer_size函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_hw_params_get_buffer_size函数的具体用法?C++ snd_pcm_hw_params_get_buffer_size怎么用?C++ snd_pcm_hw_params_get_buffer_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_pcm_hw_params_get_buffer_size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: wodUpdatePlayedTotal
/**************************************************************************
* wodUpdatePlayedTotal [internal]
*
*/
static BOOL wodUpdatePlayedTotal(WINE_WAVEDEV* wwo, snd_pcm_status_t* ps)
{
snd_pcm_sframes_t delay;
snd_pcm_sframes_t avail;
snd_pcm_uframes_t buf_size = 0;
snd_pcm_state_t state;
state = snd_pcm_state(wwo->pcm);
avail = snd_pcm_avail_update(wwo->pcm);
snd_pcm_hw_params_get_buffer_size(wwo->hw_params, &buf_size);
delay = buf_size - avail;
if (state != SND_PCM_STATE_RUNNING && state != SND_PCM_STATE_PREPARED)
{
WARN("Unexpected state (%d) while updating Total Played, resetting\n", state);
wine_snd_pcm_recover(wwo->pcm, -EPIPE, 0);
delay=0;
}
/* A delay < 0 indicates an underrun; for our purposes that's 0. */
if (delay < 0)
{
WARN("Unexpected delay (%ld) while updating Total Played, resetting\n", delay);
delay=0;
}
InterlockedExchange((LONG*)&wwo->dwPlayedTotal, wwo->dwWrittenTotal - snd_pcm_frames_to_bytes(wwo->pcm, delay));
return TRUE;
}
开发者ID:mikekap,项目名称:wine,代码行数:33,代码来源:waveout.c
示例2: alsa_log
static void alsa_log(snd_pcm_hw_params_t* hw_params, snd_pcm_sw_params_t* sw_params)
{
unsigned period_time;
snd_pcm_uframes_t period_size;
unsigned period_count;
unsigned buffer_time;
snd_pcm_uframes_t buffer_size;
unsigned tick_time;
snd_pcm_uframes_t xfer_align;
snd_pcm_hw_params_get_period_time(hw_params, &period_time, 0);
snd_pcm_hw_params_get_period_size(hw_params, &period_size, 0);
snd_pcm_hw_params_get_periods(hw_params, &period_count, 0);
snd_pcm_hw_params_get_buffer_time(hw_params, &buffer_time, 0);
snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
snd_pcm_hw_params_get_tick_time(hw_params, &tick_time, 0);
log_std(("sound:alsa: hw period_time %g [us], period_size %d, periods %d, buffer_time %g [us], buffer_size %d, tick_time %g [us]\n",
(double)(period_time / 1000000.0), (unsigned)period_size, (unsigned)period_count, (double)(buffer_time / 1000000.0), (unsigned)buffer_size, (double)(tick_time / 1000000.0)
));
snd_pcm_sw_params_get_xfer_align(sw_params, &xfer_align);
log_std(("sound:alsa: sw xfer_align %d\n",
(unsigned)xfer_align
));
}
开发者ID:BirchJD,项目名称:advancemame-0.106.1-RPi,代码行数:27,代码来源:salsa.c
示例3: set_hwparams
static
int set_hwparams(snd_pcm_t *handle,
snd_pcm_hw_params_t *params,
snd_pcm_access_t access)
{
int err, dir;
/* choose all parameters */
err = snd_pcm_hw_params_any(handle,params);
if (err < 0) {
printf("Access type not available for playback: %s\n", snd_strerror(err));
return err;
}
/* set the sample format */
err = snd_pcm_hw_params_set_format(handle, params, alsa_format);
if (err < 0) {
printf("Sample format not available for playback: %s\n", snd_strerror(err));
return err;
}
/* set the count of channels */
err = snd_pcm_hw_params_set_channels(handle, params, channels);
if (err < 0) {
printf("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err));
return err;
}
/* set the stream rate */
err = snd_pcm_hw_params_set_rate_near(handle, params, rate, 0);
if (err < 0) {
printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err));
return err;
}
if (err != rate) {
printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
return -EINVAL;
}
/* set buffer time */
err = snd_pcm_hw_params_set_buffer_time_near(handle, params, buffer_time, &dir);
if (err < 0) {
printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err));
return err;
}
buffer_size = snd_pcm_hw_params_get_buffer_size(params);
/* set period time */
err = snd_pcm_hw_params_set_period_time_near(handle, params, period_time, &dir);
if (err < 0) {
printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err));
return err;
}
period_size = snd_pcm_hw_params_get_period_size(params, &dir);
/* write the parameters to device */
err = snd_pcm_hw_params(handle, params);
if (err < 0) {
printf("Unable to set hw params for playback: %s\n", snd_strerror(err));
return err;
}
return 0;
}
开发者ID:Jay-Jay-OPL,项目名称:ps2sdk-ports,代码行数:57,代码来源:audio_alsa.c
示例4: 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
示例5: alsa_print_info
void alsa_print_info(snd_pcm_t * handle, snd_pcm_hw_params_t * hwp) {
printf("device [%s] opened with\n",
snd_pcm_name(handle));
printf("\tstate=%s\n",
snd_pcm_state_name(snd_pcm_state(handle)));
unsigned int val, val2;
snd_pcm_hw_params_get_access(hwp,
(snd_pcm_access_t *) &val);
printf("\taccess_type=%s\n",
snd_pcm_access_name((snd_pcm_access_t)val));
snd_pcm_hw_params_get_format(hwp, (snd_pcm_format_t *) &val);
printf("\tformat=%s\n",
snd_pcm_format_name((snd_pcm_format_t) val)
);
snd_pcm_hw_params_get_channels(hwp, &val);
printf("\tchannels=%d\n", val);
snd_pcm_hw_params_get_rate(hwp, &val, (int *) &val2);
printf("\trate=%d fps\n", val);
snd_pcm_hw_params_get_period_time(hwp,
&val, (int *) &val2);
printf("\tperiod_time=%d us\n", val);
snd_pcm_uframes_t frames;
snd_pcm_hw_params_get_period_size(hwp,
&frames, (int *) &val2);
printf("\tperiod_size=%d frames\n", (int)frames);
snd_pcm_hw_params_get_buffer_size(hwp,
(snd_pcm_uframes_t *) &val);
printf("\tbuffer_size=%d frames\n", val);
snd_pcm_hw_params_get_periods(hwp, &val, (int *) &val2);
printf("\tperiods_per_buffer=%d periods\n", val);
}
开发者ID:northern-bites,项目名称:nbites,代码行数:38,代码来源:Sound.cpp
示例6: bg_alsa_open
//.........这里部分代码省略.........
format->channel_locations[0] = GAVL_CHID_FRONT_LEFT;
format->channel_locations[1] = GAVL_CHID_FRONT_RIGHT;
}
}
else
{
bg_log(BG_LOG_ERROR, LOG_DOMAIN,
"snd_pcm_hw_params_set_channels failed (Format has %d channels)",
format->num_channels);
goto fail;
}
}
/* Switch off driver side resampling */
#if SND_LIB_VERSION >= 0x010009
snd_pcm_hw_params_set_rate_resample(ret, hw_params, 0);
#endif
/* Samplerate */
i_tmp = format->samplerate;
if(snd_pcm_hw_params_set_rate_near(ret, hw_params,
&i_tmp,
0) < 0)
{
bg_log(BG_LOG_ERROR, LOG_DOMAIN, "snd_pcm_hw_params_set_rate_near failed");
goto fail;
}
if(format->samplerate != i_tmp)
{
bg_log(BG_LOG_INFO, LOG_DOMAIN,
"Samplerate %d not supported by device %s, using %d",
format->samplerate, card, i_tmp);
}
format->samplerate = i_tmp;
dir = 0;
/* Buffer size */
snd_pcm_hw_params_get_buffer_size_min(hw_params, &buffer_size_min);
snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size_max);
dir=0;
snd_pcm_hw_params_get_period_size_min(hw_params, &period_size_min,&dir);
dir=0;
snd_pcm_hw_params_get_period_size_max(hw_params, &period_size_max,&dir);
buffer_size = gavl_time_to_samples(format->samplerate, buffer_time);
if(buffer_size > buffer_size_max)
buffer_size = buffer_size_max;
if(buffer_size < buffer_size_min)
buffer_size = buffer_size_min;
period_size = buffer_size / 8;
buffer_size = period_size * 8;
dir = 0;
if(snd_pcm_hw_params_set_period_size_near(ret, hw_params, &period_size, &dir) < 0)
{
bg_log(BG_LOG_ERROR, LOG_DOMAIN, "snd_pcm_hw_params_set_period_size failed");
goto fail;
}
dir = 0;
snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir);
dir = 0;
if(snd_pcm_hw_params_set_buffer_size_near(ret, hw_params, &buffer_size) < 0)
{
bg_log(BG_LOG_ERROR, LOG_DOMAIN, "snd_pcm_hw_params_set_buffer_size failed");
goto fail;
}
snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
format->samples_per_frame = period_size;
/* Write params to card */
if(snd_pcm_hw_params (ret, hw_params) < 0)
{
bg_log(BG_LOG_ERROR, LOG_DOMAIN, "snd_pcm_hw_params failed");
goto fail;
}
snd_pcm_hw_params_free(hw_params);
gavl_set_channel_setup(format);
// gavl_audio_format_dump(format);
return ret;
fail:
bg_log(BG_LOG_ERROR, LOG_DOMAIN, "Alsa initialization failed");
if(ret)
snd_pcm_close(ret);
if(hw_params)
snd_pcm_hw_params_free(hw_params);
return NULL;
}
开发者ID:Jheengut,项目名称:gmerlin,代码行数:101,代码来源:alsa_common.c
示例7: calloc
static void *alsa_thread_init(const char *device,
unsigned rate, unsigned latency)
{
snd_pcm_uframes_t buffer_size;
snd_pcm_format_t format;
snd_pcm_hw_params_t *params = NULL;
snd_pcm_sw_params_t *sw_params = NULL;
const char *alsa_dev = device ? device : "default";
unsigned latency_usec = latency * 1000 / 2;
unsigned channels = 2;
unsigned periods = 4;
alsa_thread_t *alsa = (alsa_thread_t*)
calloc(1, sizeof(alsa_thread_t));
if (!alsa)
return NULL;
TRY_ALSA(snd_pcm_open(&alsa->pcm, alsa_dev, SND_PCM_STREAM_PLAYBACK, 0));
TRY_ALSA(snd_pcm_hw_params_malloc(¶ms));
alsa->has_float = alsathread_find_float_format(alsa->pcm, params);
format = alsa->has_float ? SND_PCM_FORMAT_FLOAT : SND_PCM_FORMAT_S16;
TRY_ALSA(snd_pcm_hw_params_any(alsa->pcm, params));
TRY_ALSA(snd_pcm_hw_params_set_access(
alsa->pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED));
TRY_ALSA(snd_pcm_hw_params_set_format(alsa->pcm, params, format));
TRY_ALSA(snd_pcm_hw_params_set_channels(alsa->pcm, params, channels));
TRY_ALSA(snd_pcm_hw_params_set_rate(alsa->pcm, params, rate, 0));
TRY_ALSA(snd_pcm_hw_params_set_buffer_time_near(
alsa->pcm, params, &latency_usec, NULL));
TRY_ALSA(snd_pcm_hw_params_set_periods_near(
alsa->pcm, params, &periods, NULL));
TRY_ALSA(snd_pcm_hw_params(alsa->pcm, params));
/* Shouldn't have to bother with this,
* but some drivers are apparently broken. */
if (snd_pcm_hw_params_get_period_size(params, &alsa->period_frames, NULL))
snd_pcm_hw_params_get_period_size_min(
params, &alsa->period_frames, NULL);
RARCH_LOG("ALSA: Period size: %d frames\n", (int)alsa->period_frames);
if (snd_pcm_hw_params_get_buffer_size(params, &buffer_size))
snd_pcm_hw_params_get_buffer_size_max(params, &buffer_size);
RARCH_LOG("ALSA: Buffer size: %d frames\n", (int)buffer_size);
alsa->buffer_size = snd_pcm_frames_to_bytes(alsa->pcm, buffer_size);
alsa->period_size = snd_pcm_frames_to_bytes(alsa->pcm, alsa->period_frames);
TRY_ALSA(snd_pcm_sw_params_malloc(&sw_params));
TRY_ALSA(snd_pcm_sw_params_current(alsa->pcm, sw_params));
TRY_ALSA(snd_pcm_sw_params_set_start_threshold(
alsa->pcm, sw_params, buffer_size / 2));
TRY_ALSA(snd_pcm_sw_params(alsa->pcm, sw_params));
snd_pcm_hw_params_free(params);
snd_pcm_sw_params_free(sw_params);
alsa->fifo_lock = slock_new();
alsa->cond_lock = slock_new();
alsa->cond = scond_new();
alsa->buffer = fifo_new(alsa->buffer_size);
if (!alsa->fifo_lock || !alsa->cond_lock || !alsa->cond || !alsa->buffer)
goto error;
alsa->worker_thread = sthread_create(alsa_worker_thread, alsa);
if (!alsa->worker_thread)
{
RARCH_ERR("error initializing worker thread");
goto error;
}
return alsa;
error:
RARCH_ERR("ALSA: Failed to initialize...\n");
if (params)
snd_pcm_hw_params_free(params);
if (sw_params)
snd_pcm_sw_params_free(sw_params);
alsa_thread_free(alsa);
return NULL;
}
开发者ID:Ezio-PS,项目名称:RetroArch,代码行数:87,代码来源:alsathread.c
示例8: set_params
static 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,代码来源:play.c
示例9: set_hwparams
//.........这里部分代码省略.........
goto retry;
}
GST_DEBUG_OBJECT (alsa, "buffer time %u", buffer_time);
}
if (period_time != -1 && !alsa->iec958) {
/* set the period time */
if ((err = snd_pcm_hw_params_set_period_time_near (alsa->handle, params,
&period_time, NULL)) < 0) {
GST_ELEMENT_WARNING (alsa, RESOURCE, SETTINGS, (NULL),
("Unable to set period time %i for playback: %s",
period_time, snd_strerror (err)));
/* disable period_time the next round */
period_time = -1;
goto retry;
}
GST_DEBUG_OBJECT (alsa, "period time %u", period_time);
}
/* Set buffer size and period size manually for SPDIF */
if (G_UNLIKELY (alsa->iec958)) {
snd_pcm_uframes_t buffer_size = SPDIF_BUFFER_SIZE;
snd_pcm_uframes_t period_size = SPDIF_PERIOD_SIZE;
CHECK (snd_pcm_hw_params_set_buffer_size_near (alsa->handle, params,
&buffer_size), buffer_size);
CHECK (snd_pcm_hw_params_set_period_size_near (alsa->handle, params,
&period_size, NULL), period_size);
}
/* write the parameters to device */
CHECK (snd_pcm_hw_params (alsa->handle, params), set_hw_params);
/* now get the configured values */
CHECK (snd_pcm_hw_params_get_buffer_size (params, &alsa->buffer_size),
buffer_size);
CHECK (snd_pcm_hw_params_get_period_size (params, &alsa->period_size, NULL),
period_size);
GST_DEBUG_OBJECT (alsa, "buffer size %lu, period size %lu", alsa->buffer_size,
alsa->period_size);
snd_pcm_hw_params_free (params);
return 0;
/* ERRORS */
no_config:
{
GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
("Broken configuration for playback: no configurations available: %s",
snd_strerror (err)));
snd_pcm_hw_params_free (params);
return err;
}
wrong_access:
{
GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
("Access type not available for playback: %s", snd_strerror (err)));
snd_pcm_hw_params_free (params);
return err;
}
no_sample_format:
{
GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
("Sample format not available for playback: %s", snd_strerror (err)));
snd_pcm_hw_params_free (params);
return err;
开发者ID:pli3,项目名称:gst-plugins-base,代码行数:67,代码来源:gstalsasink.c
示例10: ga_alsa_set_param
int
ga_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,代码来源:ga-alsa.cpp
示例11: fprintf
static snd_pcm_t *alsa_open(snd_pcm_t **pcm_handle, int stream_type,
snd_pcm_uframes_t *buffer_size) {
char *pcm_name = "chumix";
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
unsigned int buffer_time;
int status;
snd_pcm_uframes_t xfer_align;
// Open the device. Experimenting with duplex mode.
fprintf(stderr, "Opening PCM device\n");
status = snd_pcm_open(pcm_handle, pcm_name,
stream_type, 0);
if(status < 0) {
fprintf(stderr, "Unable to open audio device: %s\n",
snd_strerror(status));
goto error;
}
// Determine what the hardware can do.
fprintf(stderr, "Allocating hw params\n");
snd_pcm_hw_params_malloc(&hwparams);
status = snd_pcm_hw_params_any(*pcm_handle, hwparams);
if(status < 0) {
fprintf(stderr, "Unable to get hardware parameters: %s\n",
snd_strerror(status));
goto error;
}
// Set up interleaved audio.
fprintf(stderr, "Setting up interleaved audio\n");
status = snd_pcm_hw_params_set_access(*pcm_handle, hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED);
if(status < 0) {
fprintf(stderr, "Unable to set interleaved mode: %s\n",
snd_strerror(status));
goto error;
}
// Set the audio format.
fprintf(stderr, "Setting format\n");
status = snd_pcm_hw_params_set_format(*pcm_handle, hwparams,
SND_PCM_FORMAT_S16_LE);
if(status<0) {
fprintf(stderr, "Unable to set audio format: %s\n",
snd_strerror(status));
goto error;
}
// Set stereo audio.
fprintf(stderr, "Setting channels\n");
status = snd_pcm_hw_params_set_channels(*pcm_handle, hwparams, 2);
if(status<0) {
fprintf(stderr, "Unable to set stereo mode: %s\n",
snd_strerror(status));
goto error;
}
// Set sample rate.
fprintf(stderr, "Setting audio rate\n");
int rate = 44100;
status = snd_pcm_hw_params_set_rate_near(*pcm_handle, hwparams,
&rate, NULL);
if(status<0) {
fprintf(stderr, "Unable to set sample rate to 44100: %s\n",
snd_strerror(status));
goto error;
}
// Set buffer time to a reasonable value.
// Probably won't work for playback, as it's fixed in /etc/asound.conf
buffer_time = BUFFER_TIME;
status = snd_pcm_hw_params_set_buffer_time_near(*pcm_handle, hwparams,
&buffer_time, 0);
snd_pcm_hw_params_get_buffer_size(hwparams, buffer_size);
// Write the settings out to the audio card.
fprintf(stderr, "Setting hw params\n");
status = snd_pcm_hw_params(*pcm_handle, hwparams);
if(status<0) {
fprintf(stderr, "Unable to set audio parameters: %s\n",
snd_strerror(status));
goto error;
}
snd_pcm_hw_params_free(hwparams);
status = snd_pcm_prepare(*pcm_handle);
if(status<0) {
fprintf(stderr, "Unable to prepare audio device: %s\n",
snd_strerror(status));
goto error;
}
//.........这里部分代码省略.........
开发者ID:xobs,项目名称:chumbradiod,代码行数:101,代码来源:crad_interface.c
示例12: open
bool open()
{
// Open the Alsa playback device.
int err=-1,count=0;
unsigned int freakuency = frequency;
while((count < 5) && (err < 0)) {
err = snd_pcm_open
( &handle, ALSA_OUTPUT_NAME, SND_PCM_STREAM_PLAYBACK, 0 );
if(err < 0) {
count++;
qWarning()<<"QAudioOutput::open() err="<<err<<", count="<<count;
}
}
if (( err < 0)||(handle == 0)) {
qWarning( "QAudioOuput: snd_pcm_open: error %d", err );
return false;
}
snd_pcm_nonblock( handle, 0 );
// Set the desired HW parameters.
snd_pcm_hw_params_t *hwparams;
snd_pcm_hw_params_alloca( &hwparams );
err = snd_pcm_hw_params_any( handle, hwparams );
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_any: err %d", err);
return false;
}
err = snd_pcm_hw_params_set_access( handle, hwparams, access );
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_access: err %d", err);
return false;
}
err = snd_pcm_hw_params_set_format( handle, hwparams,
( bitsPerSample == 16 ? SND_PCM_FORMAT_S16
: SND_PCM_FORMAT_U8 ) );
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_format: err %d", err);
return false;
}
err = snd_pcm_hw_params_set_channels
( handle, hwparams, (unsigned int)channels );
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_channels: err %d", err);
return false;
}
err = snd_pcm_hw_params_set_rate_near
( handle, hwparams, &freakuency, 0 );
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_rate_near: err %d", err);
return false;
}
#ifndef ALSA_BUFFER_SIZE
err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0);
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err %d",err);
}
err = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size);
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_get_buffer_size: err %d",err);
}
#else
buffer_size = ALSA_BUFFER_SIZE;
err = snd_pcm_hw_params_set_buffer_size_near(handle, hwparams, &buffer_size);
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err %d",err);
}
#endif
#ifndef ALSA_PERIOD_SIZE
period_time = buffer_time/4;
err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0);
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_period_time_near: err %d",err);
}
#else
period_size = ALSA_PERIOD_SIZE;
err = snd_pcm_hw_params_set_period_size_near(handle, hwparams, &period_size, 0);
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params_set_period_size_near: err %d",err);
}
#endif
err = snd_pcm_hw_params(handle, hwparams);
if ( err < 0 ) {
qWarning( "QAudioOutput: snd_pcm_hw_params: err %d", err);
return false;
}
int dir;
unsigned int vval, vval2;
snd_pcm_access_t val;
snd_pcm_format_t fval;
//.........这里部分代码省略.........
开发者ID:Camelek,项目名称:qtmoko,代码行数:101,代码来源:qaudiooutput_alsa.cpp
示例13: set_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);
if (avail_min < 0)
n = chunk_size;
else
n = (double) rate * avail_min / 1000000;
err = snd_pcm_sw_params_set_avail_min(handle, swparams, n);
if (err < 0) {
error("Setting sw params failed\n");
}
/* round up to closest transfer boundary */
n = buffer_size;
if (start_delay <= 0) {
start_threshold = n + (double) rate * start_delay / 1000000;
} else
start_threshold = (double) rate * start_delay / 1000000;
if (start_threshold < 1)
start_threshold = 1;
if (start_threshold > n)
start_threshold = n;
err = snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold);
assert(err >= 0);
if (stop_delay <= 0)
stop_threshold = buffer_size + (double) rate * stop_delay / 1000000;
else
stop_threshold = (double) rate * stop_delay / 1000000;
err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold);
开发者ID:5hanth,项目名称:dhvani-tts,代码行数:67,代码来源:alsa_player.c
示例14: now
//.........这里部分代码省略.........
if ( !fatal ) {
err = snd_pcm_hw_params_set_access( handle, hwparams, access );
if ( err < 0 ) {
fatal = true;
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err);
}
}
if ( !fatal ) {
err = setFormat();
if ( err < 0 ) {
fatal = true;
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channelCount() );
if ( err < 0 ) {
fatal = true;
errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &sampleRate, 0 );
if ( err < 0 ) {
fatal = true;
errMessage = QString::fromLatin1("QAudioInput: 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("QAudioInput: 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("QAudioInput: 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("QAudioInput: 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("QAudioInput: snd_pcm_hw_params: err = %1").arg(err);
}
}
if( err < 0) {
qWarning()<<errMessage;
errorState = QAudio::OpenError;
deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
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
ringBuffer.resize(buffer_size);
snd_pcm_prepare( handle );
snd_pcm_start(handle);
// Step 5: Setup timer
bytesAvailable = checkBytesReady();
if(pullMode)
connect(audioSource,SIGNAL(readyRead()),this,SLOT(userFeed()));
// Step 6: Start audio processing
chunks = buffer_size/period_size;
timer->start(period_time*chunks/2000);
errorState = QAudio::NoError;
totalTimeValue = 0;
return true;
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:101,代码来源:qalsaaudioinput.cpp
示例15: set_snd_pcm_params
//.........这里部分代码省略.........
err = snd_pcm_hw_params_set_rate_near(sndpcm->handle,
params, &bat->rate,
0);
if (err < 0) {
loge(E_SETDEV S_SAMPLERATE, "%d %s: %s(%d)",
bat->rate,
device_name, snd_strerror(err), err);
goto fail_exit;
}
if ((float) rate * 1.05 < bat->rate
|| (float) rate * 0.95 > bat->rate) {
loge(E_PARAMS S_SAMPLERATE, "requested %dHz, got %dHz",
rate, bat->rate);
goto fail_exit;
}
if (snd_pcm_hw_params_get_buffer_time_max(params,
&buffer_time, 0) < 0) {
loge(E_GETDEV S_BUFFERTIME, "%d %s: %s(%d)",
buffer_time,
device_name, snd_strerror(err), err);
goto fail_exit;
}
if (buffer_time > 500000)
buffer_time = 500000;
/* Was 4, changed to 8 to remove reduce capture overrun */
period_time = buffer_time / 8;
/* Set buffer time and period time */
err = snd_pcm_hw_params_set_buffer_time_near(sndpcm->handle, params,
&buffer_time, 0);
if (err < 0) {
loge(E_SETDEV S_BUFFERTIME, "%d %s: %s(%d)",
buffer_time,
device_name, snd_strerror(err), err);
goto fail_exit;
}
err = snd_pcm_hw_params_set_period_time_near(sndpcm->handle, params,
&period_time, 0);
if (err < 0) {
loge(E_SETDEV S_PERIODTIME, "%d %s: %s(%d)",
period_time,
device_name, snd_strerror(err), err);
goto fail_exit;
}
/* Write the parameters to the driver */
if (snd_pcm_hw_params(sndpcm->handle, params) < 0) {
loge(E_SETDEV S_HWPARAMS, "%s: %s(%d)",
device_name, snd_strerror(err), err);
goto fail_exit;
}
err = snd_pcm_hw_params_get_period_size(params,
&sndpcm->period_size, 0);
if (err < 0) {
loge(E_GETDEV S_PERIODSIZE, "%zd %s: %s(%d)",
sndpcm->period_size,
device_name, snd_strerror(err), err);
goto fail_exit;
}
err = snd_pcm_hw_params_get_buffer_size(params, &sndpcm->buffer_size);
if (err < 0) {
loge(E_GETDEV S_BUFFERSIZE, "%zd %s: %s(%d)",
sndpcm->buffer_size,
device_name, snd_strerror(err), err);
goto fail_exit;
}
if (sndpcm->period_size == sndpcm->buffer_size) {
loge(E_PARAMS, "can't use period equal to buffer size (%zd)",
sndpcm->period_size);
goto fail_exit;
}
err = snd_pcm_format_physical_width(format);
if (err < 0) {
loge(E_PARAMS, "snd_pcm_format_physical_width: %d", err);
goto fail_exit;
}
sndpcm->sample_bits = err;
sndpcm->frame_bits = sndpcm->sample_bits * bat->channels;
/* Calculate the period bytes */
sndpcm->period_bytes = sndpcm->period_size * sndpcm->frame_bits / 8;
sndpcm->buffer = (char *) malloc(sndpcm->period_bytes);
if (sndpcm->buffer == NULL) {
loge(E_MALLOC, "size=%zd", sndpcm->period_bytes);
goto fail_exit;
}
return 0;
fail_exit:
return -1;
}
开发者ID:hanlui,项目名称:bat,代码行数:101,代码来源:wav_play_record.c
示例16: alloca
static snd_pcm_t *alsa_open(char *dev, int rate, int channels)
{
snd_pcm_hw_params_t *hwp;
snd_pcm_sw_params_t *swp;
snd_pcm_t *h;
int r;
int dir;
snd_pcm_uframes_t period_size_min;
snd_pcm_uframe
|
请发表评论