本文整理汇总了C++中snd_strerror函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_strerror函数的具体用法?C++ snd_strerror怎么用?C++ snd_strerror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_strerror函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wodPlayer_ProcessMessages
/**************************************************************************
* wodPlayer_ProcessMessages [internal]
*/
static void wodPlayer_ProcessMessages(WINE_WAVEDEV* wwo)
{
LPWAVEHDR lpWaveHdr;
enum win_wm_message msg;
DWORD_PTR param;
HANDLE ev;
int err;
while (ALSA_RetrieveRingMessage(&wwo->msgRing, &msg, ¶m, &ev)) {
TRACE("Received %s %lx\n", ALSA_getCmdString(msg), param);
switch (msg) {
case WINE_WM_PAUSING:
if ( snd_pcm_state(wwo->pcm) == SND_PCM_STATE_RUNNING )
{
if ( snd_pcm_hw_params_can_pause(wwo->hw_params) )
{
err = snd_pcm_pause(wwo->pcm, 1);
if ( err < 0 )
ERR("pcm_pause failed: %s\n", snd_strerror(err));
wwo->state = WINE_WS_PAUSED;
}
else
{
wodPlayer_Reset(wwo,FALSE);
}
}
SetEvent(ev);
break;
case WINE_WM_RESTARTING:
if (wwo->state == WINE_WS_PAUSED)
{
if ( snd_pcm_state(wwo->pcm) == SND_PCM_STATE_PAUSED )
{
err = snd_pcm_pause(wwo->pcm, 0);
if ( err < 0 )
ERR("pcm_pause failed: %s\n", snd_strerror(err));
}
wwo->state = WINE_WS_PLAYING;
}
SetEvent(ev);
break;
case WINE_WM_HEADER:
lpWaveHdr = (LPWAVEHDR)param;
/* insert buffer at the end of queue */
{
LPWAVEHDR* wh;
for (wh = &(wwo->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
*wh = lpWaveHdr;
}
if (!wwo->lpPlayPtr)
wodPlayer_BeginWaveHdr(wwo,lpWaveHdr);
if (wwo->state == WINE_WS_STOPPED)
wwo->state = WINE_WS_PLAYING;
break;
case WINE_WM_RESETTING:
wodPlayer_Reset(wwo,TRUE);
SetEvent(ev);
break;
case WINE_WM_BREAKLOOP:
if (wwo->state == WINE_WS_PLAYING && wwo->lpLoopPtr != NULL) {
/* ensure exit at end of current loop */
wwo->dwLoops = 1;
}
SetEvent(ev);
break;
case WINE_WM_CLOSING:
/* sanity check: this should not happen since the device must have been reset before */
if (wwo->lpQueuePtr || wwo->lpPlayPtr) ERR("out of sync\n");
wwo->hThread = 0;
wwo->state = WINE_WS_CLOSED;
SetEvent(ev);
ExitThread(0);
/* shouldn't go here */
default:
FIXME("unknown message %d\n", msg);
break;
}
}
}
示例2: alsa_setup
/**
* Set up the snd_pcm_t object which was opened by the caller. Set up
* the configured settings and the audio format.
*/
static bool
alsa_setup(struct alsa_data *ad, struct audio_format *audio_format,
GError **error)
{
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
unsigned int sample_rate = audio_format->sample_rate;
unsigned int channels = audio_format->channels;
snd_pcm_uframes_t alsa_buffer_size;
snd_pcm_uframes_t alsa_period_size;
int err;
const char *cmd = NULL;
int retry = MPD_ALSA_RETRY_NR;
unsigned int period_time, period_time_ro;
unsigned int buffer_time;
period_time_ro = period_time = ad->period_time;
configure_hw:
/* configure HW params */
snd_pcm_hw_params_alloca(&hwparams);
cmd = "snd_pcm_hw_params_any";
err = snd_pcm_hw_params_any(ad->pcm, hwparams);
if (err < 0)
goto error;
if (ad->use_mmap) {
err = snd_pcm_hw_params_set_access(ad->pcm, hwparams,
SND_PCM_ACCESS_MMAP_INTERLEAVED);
if (err < 0) {
g_warning("Cannot set mmap'ed mode on ALSA device \"%s\": %s\n",
alsa_device(ad), snd_strerror(-err));
g_warning("Falling back to direct write mode\n");
ad->use_mmap = false;
} else
ad->writei = snd_pcm_mmap_writei;
}
if (!ad->use_mmap) {
cmd = "snd_pcm_hw_params_set_access";
err = snd_pcm_hw_params_set_access(ad->pcm, hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0)
goto error;
ad->writei = snd_pcm_writei;
}
err = alsa_output_setup_format(ad->pcm, hwparams, audio_format);
if (err < 0) {
g_set_error(error, alsa_output_quark(), err,
"ALSA device \"%s\" does not support format %s: %s",
alsa_device(ad),
sample_format_to_string(audio_format->format),
snd_strerror(-err));
return false;
}
err = snd_pcm_hw_params_set_channels_near(ad->pcm, hwparams,
&channels);
if (err < 0) {
g_set_error(error, alsa_output_quark(), err,
"ALSA device \"%s\" does not support %i channels: %s",
alsa_device(ad), (int)audio_format->channels,
snd_strerror(-err));
return false;
}
audio_format->channels = (int8_t)channels;
err = snd_pcm_hw_params_set_rate_near(ad->pcm, hwparams,
&sample_rate, NULL);
if (err < 0 || sample_rate == 0) {
g_set_error(error, alsa_output_quark(), err,
"ALSA device \"%s\" does not support %u Hz audio",
alsa_device(ad), audio_format->sample_rate);
return false;
}
audio_format->sample_rate = sample_rate;
snd_pcm_uframes_t buffer_size_min, buffer_size_max;
snd_pcm_hw_params_get_buffer_size_min(hwparams, &buffer_size_min);
snd_pcm_hw_params_get_buffer_size_max(hwparams, &buffer_size_max);
unsigned buffer_time_min, buffer_time_max;
snd_pcm_hw_params_get_buffer_time_min(hwparams, &buffer_time_min, 0);
snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time_max, 0);
g_debug("buffer: size=%u..%u time=%u..%u",
(unsigned)buffer_size_min, (unsigned)buffer_size_max,
buffer_time_min, buffer_time_max);
snd_pcm_uframes_t period_size_min, period_size_max;
snd_pcm_hw_params_get_period_size_min(hwparams, &period_size_min, 0);
snd_pcm_hw_params_get_period_size_max(hwparams, &period_size_max, 0);
unsigned period_time_min, period_time_max;
snd_pcm_hw_params_get_period_time_min(hwparams, &period_time_min, 0);
snd_pcm_hw_params_get_period_time_max(hwparams, &period_time_max, 0);
g_debug("period: size=%u..%u time=%u..%u",
(unsigned)period_size_min, (unsigned)period_size_max,
period_time_min, period_time_max);
//.........这里部分代码省略.........
示例3: DAUDIO_Open
void* DAUDIO_Open(INT32 mixerIndex, INT32 deviceID, int isSource,
int encoding, float sampleRate, int sampleSizeInBits,
int frameSize, int channels,
int isSigned, int isBigEndian, int bufferSizeInBytes) {
snd_pcm_format_mask_t* formatMask;
snd_pcm_format_t format;
int dir;
int ret = 0;
AlsaPcmInfo* info = NULL;
/* snd_pcm_uframes_t is 64 bit on 64-bit systems */
snd_pcm_uframes_t alsaPeriodSize = 0;
snd_pcm_uframes_t alsaBufferSizeInFrames = 0;
TRACE0("> DAUDIO_Open\n");
#ifdef USE_TRACE
// for using ALSA debug dump methods
if (ALSA_OUTPUT == NULL) {
snd_output_stdio_attach(&ALSA_OUTPUT, stdout, 0);
}
#endif
info = (AlsaPcmInfo*) malloc(sizeof(AlsaPcmInfo));
if (!info) {
ERROR0("Out of memory\n");
return NULL;
}
memset(info, 0, sizeof(AlsaPcmInfo));
ret = openPCMfromDeviceID(deviceID, &(info->handle), isSource, FALSE /* do open device*/);
if (ret == 0) {
// set to blocking mode
snd_pcm_nonblock(info->handle, 0);
ret = snd_pcm_hw_params_malloc(&(info->hwParams));
if (ret != 0) {
ERROR1(" snd_pcm_hw_params_malloc returned error %d\n", ret);
} else {
ret = -1;
if (getAlsaFormatFromFormat(&format, frameSize / channels, sampleSizeInBits,
isSigned, isBigEndian, encoding)) {
if (setHWParams(info,
sampleRate,
channels,
bufferSizeInBytes / frameSize,
format)) {
info->frameSize = frameSize;
#ifdef ALSA_PCM_NEW_HW_PARAMS_API
ret = snd_pcm_hw_params_get_period_size(info->hwParams, &alsaPeriodSize, &dir);
info->periodSize = (int) alsaPeriodSize;
if (ret < 0) {
ERROR1("ERROR: snd_pcm_hw_params_get_period: %s\n", snd_strerror(ret));
}
snd_pcm_hw_params_get_periods(info->hwParams, &(info->periods), &dir);
snd_pcm_hw_params_get_buffer_size(info->hwParams, &alsaBufferSizeInFrames);
info->bufferSizeInBytes = (int) alsaBufferSizeInFrames * frameSize;
#else
info->periodSize = snd_pcm_hw_params_get_period_size(info->hwParams, &dir);
info->periods = snd_pcm_hw_params_get_periods(info->hwParams, &dir);
info->bufferSizeInBytes = snd_pcm_hw_params_get_buffer_size(info->hwParams) * frameSize;
ret = 0;
#endif
TRACE3(" DAUDIO_Open: period size = %d frames, periods = %d. Buffer size: %d bytes.\n",
(int) info->periodSize, info->periods, info->bufferSizeInBytes);
}
}
}
if (ret == 0) {
// set software parameters
ret = snd_pcm_sw_params_malloc(&(info->swParams));
if (ret != 0) {
ERROR1("snd_pcm_hw_params_malloc returned error %d\n", ret);
} else {
if (!setSWParams(info)) {
ret = -1;
}
}
}
if (ret == 0) {
// prepare device
ret = snd_pcm_prepare(info->handle);
if (ret < 0) {
ERROR1("ERROR: snd_pcm_prepare: %s\n", snd_strerror(ret));
}
}
#ifdef GET_POSITION_METHOD2
if (ret == 0) {
ret = snd_pcm_status_malloc(&(info->positionStatus));
if (ret != 0) {
ERROR1("ERROR in snd_pcm_status_malloc: %s\n", snd_strerror(ret));
}
}
#endif
}
if (ret != 0) {
DAUDIO_Close((void*) info, isSource);
info = NULL;
} else {
// set to non-blocking mode
snd_pcm_nonblock(info->handle, 1);
//.........这里部分代码省略.........
示例4: capture_audio_thread
//音频采集线程
void * capture_audio_thread(void *para)
{
int fdsound = 0;
int readbyte = 0;
#if RECORD_CAPTURE_PCM
FILE *fp = fopen("capture.pcm", "wb");
#endif
#if SILK_AUDIO_CODEC
SKP_uint8 encode[MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES];
#endif
#if SILK_AUDIO_CODEC
init_silk_encoder();//初始化silk codec
printf("end of init silk encoder\n");
#endif
#if (SOUND_INTERFACE == SOUND_OSS)
fdsound = open("/dev/dsp", O_RDONLY);
if(fdsound<0)
{
perror("以只写方式打开音频设备");
//return;
}
printf("设置读音频设备参数 setup capture audio device parament\n");
ioctl(fdsound, SNDCTL_DSP_SPEED, &Frequency);//采样频率
ioctl(fdsound, SNDCTL_DSP_SETFMT, &format);//音频设备位宽
ioctl(fdsound, SNDCTL_DSP_CHANNELS, &channels);//音频设备通道
ioctl(fdsound, SNDCTL_DSP_SETFRAGMENT, &setting);//采样缓冲区
while(flag_capture_audio)
{
if((readbyte=read(fdsound, pWriteHeader->buffer_capture, SAMPLERATE/1000*READMSFORONCE*sizeof(short))) < 0)
{
perror("读声卡数据");
}
else
{
//printf("readbyte=%d\n", readbyte);
#if RECORD_CAPTURE_PCM
fwrite(pWriteHeader->buffer_capture, SAMPLERATE/1000*READMSFORONCE*sizeof(short), 1, fp);
#endif
traceprintf("发送信号量 sem_capture\n");
pWriteHeader->FrameNO = FrameNO++;
time(&(pWriteHeader->time));
//printf("cNO:%d, readbyte=%d,压缩后大小%d,pWriteHeader->vad=%d\n", pWriteHeader->FrameNO, readbyte, pWriteHeader->count_encode, pWriteHeader->vad);
pthread_mutex_lock(&mutex_lock);
n++;
pWriteHeader->Valid = 1;
pthread_mutex_unlock(&mutex_lock);
pWriteHeader = pWriteHeader->pNext;
sem_post(&sem_capture);
}
}
close(fdsound);
#elif (SOUND_INTERFACE == SOUND_ALSA)
printf("alsa xxxxxxxxxxxxxxx\n");
struct timeval tv;
struct timezone tz;
/* Open PCM device for recording (capture). */
rc = snd_pcm_open(&handle, "plughw:0,0", SND_PCM_STREAM_CAPTURE, 0);
if (rc < 0)
{
fprintf(stderr, "unable to open pcm device: %s\n", snd_strerror(rc));
exit(1);
}
snd_pcm_hw_params_alloca(¶ms);/* Allocate a hardware parameters object. */
snd_pcm_hw_params_any(handle, params);/* Fill it in with default values. */
/* Set the desired hardware parameters. */
snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);/* Interleaved mode */
snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);/* Signed 16-bit little-endian format */
snd_pcm_hw_params_set_channels(handle, params, CHANNELS);/* Two channels (stereo), On for mono */
val = SAMPLERATE;
snd_pcm_hw_params_set_rate_near(handle, params, &val, &dir);/* SAMPLERATE bits/second sampling rate */
frames = SAMPLERATE/1000*READMSFORONCE;
snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir);/* Set period size to SAMPLES_FOR_EACH_TIME frames. */
/* Write the parameters to the driver */
rc = snd_pcm_hw_params(handle, params);
if (rc < 0)
//.........这里部分代码省略.........
示例5: alsa_hook_hw_params
int alsa_hook_hw_params(alsa_hook_t alsa_hook, snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
{
struct alsa_hook_stream_s *stream;
snd_pcm_format_t format;
snd_pcm_uframes_t period_size;
snd_pcm_access_t access;
int dir, ret;
alsa_hook_get_stream(alsa_hook, pcm, &stream);
if (unlikely((ret = alsa_hook_lock_write(alsa_hook, stream))))
return ret;
glc_log(alsa_hook->glc, GLC_DEBUG, "alsa_hook",
"%p: creating/updating configuration for stream %d",
stream->pcm, stream->id);
/* extract information */
if (unlikely((ret = snd_pcm_hw_params_get_format(params, &format)) < 0))
goto err;
stream->flags = 0; /* zero flags */
stream->format = pcm_fmt_to_glc_fmt(format);
if (unlikely(!stream->format)) {
glc_log(alsa_hook->glc, GLC_ERROR, "alsa_hook",
"%p: unsupported audio format 0x%02x", stream->pcm, format);
ret = ENOTSUP;
goto err;
}
if (unlikely((ret = snd_pcm_hw_params_get_rate(params, &stream->rate, &dir)) < 0))
goto err;
if (unlikely((ret = snd_pcm_hw_params_get_channels(params, &stream->channels)) < 0))
goto err;
if (unlikely((ret = snd_pcm_hw_params_get_period_size(params, &period_size, NULL)) < 0))
goto err;
if (unlikely((ret = snd_pcm_hw_params_get_access(params, &access)) < 0))
goto err;
if ((access == SND_PCM_ACCESS_RW_INTERLEAVED) ||
(access == SND_PCM_ACCESS_MMAP_INTERLEAVED))
stream->flags |= GLC_AUDIO_INTERLEAVED;
else if (access == SND_PCM_ACCESS_MMAP_COMPLEX) {
stream->flags |= GLC_AUDIO_INTERLEAVED; /* convert to interleaved */
stream->complex = 1; /* do conversion */
} else {
glc_log(alsa_hook->glc, GLC_ERROR, "alsa_hook",
"%p: unsupported access mode 0x%02x", stream->pcm, access);
ret = ENOTSUP;
goto err;
}
glc_log(alsa_hook->glc, GLC_DEBUG, "alsa_hook",
"%p: %d channels, rate %d, flags 0x%02x",
stream->pcm, stream->channels, stream->rate, stream->flags);
stream->fmt = 1;
if (alsa_hook->started) {
if (unlikely((ret = alsa_hook_stream_init(alsa_hook, stream))))
goto err;
}
alsa_hook_unlock_write(alsa_hook, stream);
return 0;
err:
glc_log(alsa_hook->glc, GLC_ERROR, "alsa_hook",
"%p: can't extract hardware configuration: %s (%d)",
stream->pcm, snd_strerror(ret), ret);
alsa_hook_unlock_write(alsa_hook, stream);
return ret;
}
示例6: set_hwparams
int set_hwparams(snd_pcm_t *handle,
snd_pcm_hw_params_t *params,
snd_pcm_access_t access)
{
unsigned int rrate;
int err, dir;
printf("set_hwparams\n");
/* choose all parameters */
err = snd_pcm_hw_params_any(handle, params);
if (err < 0) {
printf("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err));
return err;
}
/* set the interleaved read/write format */
err = snd_pcm_hw_params_set_access(handle, params, access);
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, 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 */
rrate = rate;
err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0);
if (err < 0) {
printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err));
return err;
}
if (rrate != rate) {
printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
return -EINVAL;
}
dir = 0;
err = snd_pcm_hw_params_set_period_size_near(handle, params, &period_size, &dir);
if (err < 0) {
printf("Unable to set period size %i for playback: %s\n", (int)period_size, snd_strerror(err));
return err;
}
err = snd_pcm_hw_params_set_periods(handle, params, periods, 0);
if (err < 0) {
printf("Unable to set periods %i for playback: %s\n", periods, snd_strerror(err));
return err;
}
/* 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;
}
err = snd_pcm_hw_params_get_periods(params, &periods, &dir);
if (err < 0) {
printf("Unable to get periods for playback: %s\n", snd_strerror(err));
return err;
}
err = snd_pcm_hw_params_get_period_size(params, &period_size, &dir);
if (err < 0) {
printf("Unable to get period size for playback: %s\n", snd_strerror(err));
return err;
}
return 0;
}
示例7: app_alsa_capture_loopback_open
/*******************************************************************************
**
** Function app_alsa_capture_loopback_open
**
** Description Open ALSA Capture channel (from loopback driver)
**
** Parameters p_open: Capture parameters
**
** Returns status
**
*******************************************************************************/
int app_alsa_capture_loopback_open(tAPP_ALSA_CAPTURE_OPEN *p_open)
{
int mode = 0; /* Default is blocking */
unsigned int nb_channels;
int rv;
snd_pcm_format_t format;
snd_pcm_access_t access;
APP_DEBUG0("Opening ALSA/Asound audio driver Capture");
/* Sanity check if already opened */
if (app_alsa_cb.p_capture_handle != NULL)
{
APP_DEBUG0("Capture was already opened");
}
/* check PCM Format parameter */
format = app_alsa_get_pcm_format(p_open->format);
if (format == SND_PCM_FORMAT_UNKNOWN)
{
return -1;
}
/* Check PCM access parameter */
if (p_open->access == APP_ALSA_PCM_ACCESS_RW_INTERLEAVED)
{
access = SND_PCM_ACCESS_RW_INTERLEAVED;
}
else
{
APP_ERROR1("Unsupported PCM access:%d", p_open->access);
return -1;
}
/* Check Blocking parameter */
if (p_open->blocking == FALSE)
{
mode = SND_PCM_NONBLOCK;
}
/* check Stereo parameter */
if (p_open->stereo)
{
nb_channels = 2;
}
else
{
nb_channels = 1;
}
/* Save the Capture open parameters */
memcpy(&app_alsa_cb.capture_param, p_open, sizeof(app_alsa_cb.capture_param));
/* Open ALSA driver */
rv = snd_pcm_open(&app_alsa_cb.p_capture_handle, alsa_device_loopback,
SND_PCM_STREAM_CAPTURE, mode);
if (rv < 0)
{
APP_ERROR1("unable to open ALSA loopback device in Capture mode:%s", snd_strerror(rv));
return rv;
}
APP_DEBUG0("ALSA loopback driver opened in Capture mode");
/* Configure ALSA driver with PCM parameters */
rv = snd_pcm_set_params(app_alsa_cb.p_capture_handle,
format,
access,
nb_channels,
p_open->sample_rate,
1, /* SW resample */
p_open->latency);
if (rv)
{
APP_ERROR1("Unable to config ALSA device:%s", snd_strerror(rv));
snd_pcm_close(app_alsa_cb.p_capture_handle);
app_alsa_cb.p_capture_handle = NULL;
return rv;
}
return 0;
}
示例8: main
int main(int argc, char **argv)
{
register int err;
int cardNum;
// Start with first card
cardNum = -1;
for (;;)
{
snd_ctl_t *cardHandle;
// Get next sound card's card number. When "cardNum" == -1, then ALSA
// fetches the first card
if ((err = snd_card_next(&cardNum)) < 0)
{
printf("Can't get the next card number: %s\n", snd_strerror(err));
break;
}
// No more cards? ALSA sets "cardNum" to -1 if so
if (cardNum < 0) break;
// Open this card's control interface. We specify only the card number -- not
// any device nor sub-device too
{
char str[64];
sprintf(str, "hw:%i", cardNum);
if ((err = snd_ctl_open(&cardHandle, str, 0)) < 0)
{
printf("Can't open card %i: %s\n", cardNum, snd_strerror(err));
continue;
}
}
{
int devNum, totalDevices;
// No waveform devices found yet
totalDevices = 0;
// Start with the first wave device on this card
devNum = -1;
for (;;)
{
// Get the number of the next wave device on this card
if ((err = snd_ctl_pcm_next_device(cardHandle, &devNum)) < 0)
{
printf("Can't get next wave device number: %s\n", snd_strerror(err));
break;
}
// No more wave devices on this card? ALSA sets "devNum" to -1 if so.
// NOTE: It's possible that this sound card may have no wave devices on it
// at all, for example if it's only a MIDI card
if (devNum < 0) break;
// Another wave device found on this card, so bump the count
++totalDevices;
}
printf("Found %i digital audio devices on card %i\n", totalDevices, cardNum);
}
// Close the card's control interface after we're done with it
snd_ctl_close(cardHandle);
}
// ALSA allocates some mem to load its config file when we call some of the
// above functions. Now that we're done getting the info, let's tell ALSA
// to unload the info and free up that mem
snd_config_update_free_global();
}
示例9: mixer_open
static int
mixer_open(void)
{
snd_mixer_elem_t *elem;
snd_mixer_elem_t *master;
snd_mixer_elem_t *pcm;
snd_mixer_elem_t *custom;
snd_mixer_selem_id_t *sid;
int ret;
ret = snd_mixer_open(&mixer_hdl, 0);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Failed to open mixer: %s\n", snd_strerror(ret));
mixer_hdl = NULL;
return -1;
}
ret = snd_mixer_attach(mixer_hdl, card_name);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Failed to attach mixer: %s\n", snd_strerror(ret));
goto out_close;
}
ret = snd_mixer_selem_register(mixer_hdl, NULL, NULL);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Failed to register mixer: %s\n", snd_strerror(ret));
goto out_detach;
}
ret = snd_mixer_load(mixer_hdl);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Failed to load mixer: %s\n", snd_strerror(ret));
goto out_detach;
}
/* Grab interesting elements */
snd_mixer_selem_id_alloca(&sid);
pcm = NULL;
master = NULL;
custom = NULL;
for (elem = snd_mixer_first_elem(mixer_hdl); elem; elem = snd_mixer_elem_next(elem))
{
snd_mixer_selem_get_id(elem, sid);
if (mixer_name && (strcmp(snd_mixer_selem_id_get_name(sid), mixer_name) == 0))
{
custom = elem;
break;
}
else if (strcmp(snd_mixer_selem_id_get_name(sid), "PCM") == 0)
pcm = elem;
else if (strcmp(snd_mixer_selem_id_get_name(sid), "Master") == 0)
master = elem;
}
if (mixer_name)
{
if (custom)
vol_elem = custom;
else
{
DPRINTF(E_LOG, L_LAUDIO, "Failed to open configured mixer element '%s'\n", mixer_name);
goto out_detach;
}
}
else if (pcm)
vol_elem = pcm;
else if (master)
vol_elem = master;
else
{
DPRINTF(E_LOG, L_LAUDIO, "Failed to open PCM or Master mixer element\n");
goto out_detach;
}
/* Get min & max volume */
snd_mixer_selem_get_playback_volume_range(vol_elem, &vol_min, &vol_max);
return 0;
out_detach:
snd_mixer_detach(mixer_hdl, card_name);
out_close:
snd_mixer_close(mixer_hdl);
mixer_hdl = NULL;
vol_elem = NULL;
return -1;
}
示例10: laudio_alsa_open
static int
laudio_alsa_open(void)
{
snd_pcm_hw_params_t *hw_params;
snd_pcm_uframes_t bufsize;
snd_pcm_uframes_t period_size;
int ret;
hw_params = NULL;
ret = snd_pcm_open(&hdl, card_name, SND_PCM_STREAM_PLAYBACK, 0);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not open playback device: %s\n", snd_strerror(ret));
return -1;
}
/* HW params */
ret = snd_pcm_hw_params_malloc(&hw_params);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not allocate hw params: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_hw_params_any(hdl, hw_params);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not retrieve hw params: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_hw_params_set_access(hdl, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set access method: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_hw_params_set_format(hdl, hw_params, SND_PCM_FORMAT_S16_LE);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set S16LE format: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_hw_params_set_channels(hdl, hw_params, 2);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set stereo output: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_hw_params_set_rate(hdl, hw_params, 44100, 0);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Hardware doesn't support 44.1 kHz: %s\n", snd_strerror(ret));
goto out_fail;
}
ret = snd_pcm_hw_params_get_buffer_size_max(hw_params, &bufsize);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not get max buffer size: %s\n", snd_strerror(ret));
goto out_fail;
}
DPRINTF(E_DBG, L_LAUDIO, "Max buffer size is %lu samples\n", bufsize);
ret = snd_pcm_hw_params_set_buffer_size_max(hdl, hw_params, &bufsize);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set buffer size to max: %s\n", snd_strerror(ret));
goto out_fail;
}
// With a small period size we seem to get underruns because the period time
// passes before we manage to feed with samples (if the player is slightly
// behind - especially critical during startup when the buffer is low)
// Internet suggests period_size should be /2 bufsize, but default seems to be
// much lower, so compromise on /4 (but not more than 65536 frames = almost 2 sec).
period_size = bufsize / 4;
if (period_size > 65536)
period_size = 65536;
ret = snd_pcm_hw_params_set_period_size_near(hdl, hw_params, &period_size, NULL);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set period size: %s\n", snd_strerror(ret));
goto out_fail;
//.........这里部分代码省略.........
示例11: laudio_alsa_start
static int
laudio_alsa_start(uint64_t cur_pos, uint64_t next_pkt)
{
snd_output_t *output;
char *debug_pcm_cfg;
int ret;
ret = snd_pcm_prepare(hdl);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not prepare PCM device: %s\n", snd_strerror(ret));
return -1;
}
DPRINTF(E_DBG, L_LAUDIO, "Start local audio curpos %" PRIu64 ", next_pkt %" PRIu64 "\n", cur_pos, next_pkt);
/* Make pcm_pos the rtptime of the packet containing cur_pos */
pcm_pos = next_pkt;
while (pcm_pos > cur_pos)
pcm_pos -= AIRTUNES_V2_PACKET_SAMPLES;
pcm_start_pos = next_pkt + pcm_period_size;
/* Compensate period size, otherwise get_pos won't be correct */
pcm_pos += pcm_period_size;
DPRINTF(E_DBG, L_LAUDIO, "PCM pos %" PRIu64 ", start pos %" PRIu64 "\n", pcm_pos, pcm_start_pos);
pcm_pkt_head = NULL;
pcm_pkt_tail = NULL;
pcm_last_error = 0;
pcm_recovery = 0;
// alsa doesn't actually seem to wait for this threshold?
ret = laudio_alsa_set_start_threshold(pcm_buf_threshold);
if (ret < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "Could not set PCM start threshold for local audio start\n");
return -1;
}
// Dump PCM config data for E_DBG logging
ret = snd_output_buffer_open(&output);
if (ret == 0)
{
if (snd_pcm_dump_setup(hdl, output) == 0)
{
snd_output_buffer_string(output, &debug_pcm_cfg);
DPRINTF(E_DBG, L_LAUDIO, "Dump of sound device config:\n%s\n", debug_pcm_cfg);
}
snd_output_close(output);
}
update_status(LAUDIO_STARTED);
return 0;
}
示例12: laudio_alsa_write
static void
laudio_alsa_write(uint8_t *buf, uint64_t rtptime)
{
struct pcm_packet *pkt;
snd_pcm_sframes_t nsamp;
int ret;
pkt = (struct pcm_packet *)malloc(sizeof(struct pcm_packet));
if (!pkt)
{
DPRINTF(E_LOG, L_LAUDIO, "Out of memory for PCM pkt\n");
update_status(LAUDIO_FAILED);
return;
}
memcpy(pkt->samples, buf, sizeof(pkt->samples));
pkt->rtptime = rtptime;
pkt->offset = 0;
pkt->next = NULL;
if (pcm_pkt_tail)
{
pcm_pkt_tail->next = pkt;
pcm_pkt_tail = pkt;
}
else
{
pcm_pkt_head = pkt;
pcm_pkt_tail = pkt;
}
if (pcm_pos < pcm_pkt_head->rtptime)
{
pcm_pos += AIRTUNES_V2_PACKET_SAMPLES;
return;
}
else if ((pcm_status != LAUDIO_RUNNING) && (pcm_pos >= pcm_start_pos))
{
update_status(LAUDIO_RUNNING);
}
pkt = pcm_pkt_head;
while (pkt)
{
if (pcm_recovery)
{
ret = laudio_alsa_xrun_recover(0);
if ((ret == 2) && (pcm_recovery < 10))
return;
else
{
if (ret == 2)
DPRINTF(E_LOG, L_LAUDIO, "Couldn't recover PCM device after 10 tries, aborting\n");
update_status(LAUDIO_FAILED);
return;
}
}
nsamp = snd_pcm_writei(hdl, pkt->samples + pkt->offset, BTOS(sizeof(pkt->samples) - pkt->offset));
if ((nsamp == -EPIPE) || (nsamp == -ESTRPIPE))
{
ret = laudio_alsa_xrun_recover(nsamp);
if ((ret < 0) || (ret == 1))
{
if (ret < 0)
DPRINTF(E_LOG, L_LAUDIO, "PCM write error: %s\n", snd_strerror(ret));
update_status(LAUDIO_FAILED);
return;
}
else if (ret != 0)
return;
continue;
}
else if (nsamp < 0)
{
DPRINTF(E_LOG, L_LAUDIO, "PCM write error: %s\n", snd_strerror(nsamp));
update_status(LAUDIO_FAILED);
return;
}
pcm_last_error = 0;
pcm_pos += nsamp;
pkt->offset += STOB(nsamp);
if (pkt->offset == sizeof(pkt->samples))
{
pcm_pkt_head = pkt->next;
if (pkt == pcm_pkt_tail)
pcm_pkt_tail = NULL;
free(pkt);
//.........这里部分代码省略.........
示例13: wodOpen
/**************************************************************************
* wodOpen [internal]
*/
static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
{
WINE_WAVEDEV* wwo;
snd_pcm_t * pcm = NULL;
snd_hctl_t * hctl = NULL;
snd_pcm_hw_params_t * hw_params = NULL;
snd_pcm_sw_params_t * sw_params;
snd_pcm_access_t access;
snd_pcm_format_t format = -1;
unsigned int rate;
unsigned int buffer_time = 120000;
unsigned int period_time = 22000;
snd_pcm_uframes_t buffer_size;
snd_pcm_uframes_t period_size;
int flags;
int err=0;
int dir=0;
DWORD retcode = 0;
TRACE("(%u, %p, %08X);\n", wDevID, lpDesc, dwFlags);
if (lpDesc == NULL) {
WARN("Invalid Parameter !\n");
return MMSYSERR_INVALPARAM;
}
if (wDevID >= ALSA_WodNumDevs) {
TRACE("Asked for device %d, but only %d known!\n", wDevID, ALSA_WodNumDevs);
return MMSYSERR_BADDEVICEID;
}
/* only PCM format is supported so far... */
if (!ALSA_supportedFormat(lpDesc->lpFormat)) {
WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%d !\n",
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
lpDesc->lpFormat->nSamplesPerSec);
return WAVERR_BADFORMAT;
}
if (dwFlags & WAVE_FORMAT_QUERY) {
TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%d !\n",
lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
lpDesc->lpFormat->nSamplesPerSec);
return MMSYSERR_NOERROR;
}
wwo = &WOutDev[wDevID];
if (wwo->pcm != NULL) {
WARN("%d already allocated\n", wDevID);
return MMSYSERR_ALLOCATED;
}
if (dwFlags & WAVE_DIRECTSOUND)
FIXME("Why are we called with DirectSound flag? It doesn't use MMSYSTEM any more\n");
/* not supported, ignore it */
dwFlags &= ~WAVE_DIRECTSOUND;
flags = SND_PCM_NONBLOCK;
if ( (err = snd_pcm_open(&pcm, wwo->pcmname, SND_PCM_STREAM_PLAYBACK, flags)) < 0)
{
ERR("Error open: %s\n", snd_strerror(err));
return MMSYSERR_NOTENABLED;
}
if (wwo->ctlname)
{
err = snd_hctl_open(&hctl, wwo->ctlname, 0);
if (err >= 0)
{
snd_hctl_load(hctl);
}
else
{
WARN("Could not open hctl for [%s]: %s\n", wwo->ctlname, snd_strerror(err));
hctl = NULL;
}
}
wwo->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
wwo->waveDesc = *lpDesc;
ALSA_copyFormat(lpDesc->lpFormat, &wwo->format);
TRACE("Requested this format: %dx%dx%d %s\n",
wwo->format.Format.nSamplesPerSec,
wwo->format.Format.wBitsPerSample,
wwo->format.Format.nChannels,
ALSA_getFormat(wwo->format.Format.wFormatTag));
if (wwo->format.Format.wBitsPerSample == 0) {
WARN("Resetting zeroed wBitsPerSample\n");
wwo->format.Format.wBitsPerSample = 8 *
(wwo->format.Format.nAvgBytesPerSec /
wwo->format.Format.nSamplesPerSec) /
wwo->format.Format.nChannels;
}
//.........这里部分代码省略.........
示例14: init
//.........这里部分代码省略.........
break;
case 2:
alsa_fragcount = 8;
chunk_size = 1024;
mp_msg(MSGT_AO,MSGL_V,"alsa-init: buffersize set manually to 8192\n");
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set manually to 1024\n");
break;
case 3:
alsa_fragcount = 32;
chunk_size = 512;
mp_msg(MSGT_AO,MSGL_V,"alsa-init: buffersize set manually to 16384\n");
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set manually to 512\n");
break;
case 4:
alsa_fragcount = 16;
chunk_size = 1024;
mp_msg(MSGT_AO,MSGL_V,"alsa-init: buffersize set manually to 16384\n");
mp_msg(MSGT_AO,MSGL_V,"alsa-init: chunksize set manually to 1024\n");
break;
default:
alsa_fragcount = 16;
chunk_size = 1024;
break;
}
}
if (!alsa_handler) {
//modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC
if ((err = try_open_device(alsa_device, open_mode, format == AF_FORMAT_AC3)) < 0)
{
if (err != -EBUSY && ao_noblock) {
mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_OpenInNonblockModeFailed);
if ((err = try_open_device(alsa_device, 0, format == AF_FORMAT_AC3)) < 0) {
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PlaybackOpenError, snd_strerror(err));
return(0);
}
} else {
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PlaybackOpenError, snd_strerror(err));
return(0);
}
}
if ((err = snd_pcm_nonblock(alsa_handler, 0)) < 0) {
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_ErrorSetBlockMode, snd_strerror(err));
} else {
mp_msg(MSGT_AO,MSGL_V,"alsa-init: pcm opened in blocking mode\n");
}
snd_pcm_hw_params_alloca(&alsa_hwparams);
snd_pcm_sw_params_alloca(&alsa_swparams);
// setting hw-parameters
if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToGetInitialParameters,
snd_strerror(err));
return(0);
}
err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) {
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToSetAccessType,
snd_strerror(err));
return (0);
}
示例15: config_get_ptr
static void *alsa_qsa_init(const char *device,
unsigned rate, unsigned latency)
{
int err, card, dev, i;
snd_pcm_channel_params_t params = {0};
snd_pcm_channel_info_t pi;
snd_pcm_channel_setup_t setup = {0};
settings_t *settings = config_get_ptr();
alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t));
if (!alsa)
return NULL;
(void)device;
(void)rate;
(void)latency;
if ((err = snd_pcm_open_preferred(&alsa->pcm, &card, &dev,
SND_PCM_OPEN_PLAYBACK)) < 0)
{
RARCH_ERR("[ALSA QSA]: Audio open error: %s\n",
snd_strerror(err));
goto error;
}
if((err = snd_pcm_nonblock_mode(alsa->pcm, 1)) < 0)
{
RARCH_ERR("[ALSA QSA]: Can't set blocking mode: %s\n",
snd_strerror(err));
goto error;
}
memset(&pi, 0, sizeof(pi));
pi.channel = SND_PCM_CHANNEL_PLAYBACK;
if ((err = snd_pcm_channel_info(alsa->pcm, &pi)) < 0)
{
RARCH_ERR("[ALSA QSA]: snd_pcm_channel_info failed: %s\n",
snd_strerror(err));
goto error;
}
memset(¶ms, 0, sizeof(params));
params.channel = SND_PCM_CHANNEL_PLAYBACK;
params.mode = SND_PCM_MODE_BLOCK;
params.format.interleave = 1;
params.format.format = SND_PCM_SFMT_S16_LE;
params.format.rate = DEFAULT_RATE;
params.format.voices = 2;
params.start_mode = SND_PCM_START_FULL;
params.stop_mode = SND_PCM_STOP_STOP;
params.buf.block.frag_size = pi.max_fragment_size;
params.buf.block.frags_min = 2;
params.buf.block.frags_max = 8;
RARCH_LOG("Fragment size: %d\n", params.buf.block.frag_size);
RARCH_LOG("Min Fragment size: %d\n", params.buf.block.frags_min);
RARCH_LOG("Max Fragment size: %d\n", params.buf.block.frags_max);
if ((err = snd_pcm_channel_params(alsa->pcm, ¶ms)) < 0)
{
RARCH_ERR("[ALSA QSA]: Channel Parameter Error: %s\n",
snd_strerror(err));
goto error;
}
setup.channel = SND_PCM_CHANNEL_PLAYBACK;
if ((err = snd_pcm_channel_setup(alsa->pcm, &setup)) < 0)
{
RARCH_ERR("[ALSA QSA]: Channel Parameter Read Back Error: %s\n",
snd_strerror(err));
goto error;
}
if (settings->audio.block_frames)
alsa->buf_size = settings->audio.block_frames * 4;
else
alsa->buf_size = next_pow2(32 * latency);
RARCH_LOG("[ALSA QSA]: buffer size: %u bytes\n", alsa->buf_size);
alsa->buf_count = (latency * 4 * rate + 500) / 1000;
alsa->buf_count = (alsa->buf_count + alsa->buf_size / 2) / alsa->buf_size;
if ((err = snd_pcm_channel_prepare(alsa->pcm,
SND_PCM_CHANNEL_PLAYBACK)) < 0)
{
RARCH_ERR("[ALSA QSA]: Channel Prepare Error: %s\n",
snd_strerror(err));
goto error;
}
alsa->buffer = (uint8_t**)calloc(sizeof(uint8_t*), alsa->buf_count);
if (!alsa->buffer)
goto error;
alsa->buffer_chunk = (uint8_t*)calloc(alsa->buf_count, alsa->buf_size);
//.........这里部分代码省略.........