本文整理汇总了C++中snd_pcm_hw_params_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_pcm_hw_params_malloc函数的具体用法?C++ snd_pcm_hw_params_malloc怎么用?C++ snd_pcm_hw_params_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_pcm_hw_params_malloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: BH_TRACE_INIT
void SoundPlayer::main()
{
BH_TRACE_INIT("SoundPlayer");
unsigned i;
for(i = 0; i < retries; ++i)
{
if(snd_pcm_open(&handle, "hw:0", SND_PCM_STREAM_PLAYBACK, 0) >= 0)
break;
Thread::sleep(retryDelay);
}
ASSERT(i < retries);
snd_pcm_hw_params_t* params;
VERIFY(!snd_pcm_hw_params_malloc(¶ms));
VERIFY(!snd_pcm_hw_params_any(handle, params));
VERIFY(!snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED));
VERIFY(!snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE));
VERIFY(!snd_pcm_hw_params_set_rate_near(handle, params, &sampleRate, 0));;
VERIFY(!snd_pcm_hw_params_set_channels(handle, params, 2));
VERIFY(!snd_pcm_hw_params(handle, params));
VERIFY(!snd_pcm_hw_params_get_period_size(params, &periodSize, 0));
snd_pcm_hw_params_free(params);
while(isRunning() && !closing)
{
flush();
VERIFY(sem.wait());
}
VERIFY(!snd_pcm_close(handle));
}
开发者ID:weilandetian,项目名称:Yoyo,代码行数:29,代码来源:SoundPlayer.cpp
示例2: snd_pcm_stream_t
AudioProvider::AudioProvider()
{
allChannels ? channels = 4 : channels = 2;
int brokenFirst = (theDamageConfigurationHead.audioChannelsDefect[0] ? 1 : 0) + (theDamageConfigurationHead.audioChannelsDefect[1] ? 1 : 0);
int brokenSecond = (theDamageConfigurationHead.audioChannelsDefect[2] ? 1 : 0) + (theDamageConfigurationHead.audioChannelsDefect[3] ? 1 : 0);
unsigned i;
for(i = 0; i < retries; ++i)
{
if(snd_pcm_open(&handle, allChannels ? "4channelsDeinterleaved" : brokenFirst > brokenSecond ? "hw:0,0,1" : "hw:0",
snd_pcm_stream_t(SND_PCM_STREAM_CAPTURE | SND_PCM_NONBLOCK), 0) >= 0)
break;
Thread::sleep(retryDelay);
}
ASSERT(i < retries);
snd_pcm_hw_params_t* params;
VERIFY(!snd_pcm_hw_params_malloc(¶ms));
VERIFY(!snd_pcm_hw_params_any(handle, params));
VERIFY(!snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED));
VERIFY(!snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE));
VERIFY(!snd_pcm_hw_params_set_rate_near(handle, params, &sampleRate, 0));
VERIFY(!snd_pcm_hw_params_set_channels(handle, params, channels));
VERIFY(!snd_pcm_hw_params(handle, params));
snd_pcm_hw_params_free(params);
VERIFY(!snd_pcm_prepare(handle));
ASSERT(channels <= 4);
short buf[4];
VERIFY(snd_pcm_readi(handle, buf, 1) >= 0);
}
开发者ID:weilandetian,项目名称:Yoyo,代码行数:31,代码来源:AudioProvider.cpp
示例3: 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
示例4: ASSERT
AudioProvider::AudioProvider()
{
unsigned i;
for(i = 0; i < retries; ++i)
{
if(snd_pcm_open(&handle, "hw:0", snd_pcm_stream_t(SND_PCM_STREAM_CAPTURE | SND_PCM_NONBLOCK), 0) >= 0)
break;
SystemCall::sleep(retryDelay);
}
ASSERT(i < retries);
snd_pcm_hw_params_t* params;
VERIFY(!snd_pcm_hw_params_malloc(¶ms));
VERIFY(!snd_pcm_hw_params_any(handle, params));
VERIFY(!snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED));
VERIFY(!snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE));
VERIFY(!snd_pcm_hw_params_set_rate_near(handle, params, &sampleRate, 0));
VERIFY(!snd_pcm_hw_params_set_channels(handle, params, channels));
VERIFY(!snd_pcm_hw_params(handle, params));
snd_pcm_hw_params_free(params);
VERIFY(!snd_pcm_prepare(handle));
ASSERT(channels <= 4);
short buf[4];
VERIFY(snd_pcm_readi(handle, buf, 1) >= 0);
}
开发者ID:Yanzqing,项目名称:BHumanCodeRelease,代码行数:27,代码来源:AudioProvider.cpp
示例5: alsa_format_supported
RD_BOOL
alsa_format_supported(RD_WAVEFORMATEX * pwfx)
{
#if 0
int err;
snd_pcm_hw_params_t *hwparams = NULL;
if ((err = snd_pcm_hw_params_malloc(&hwparams)) < 0)
{
error("snd_pcm_hw_params_malloc: %s\n", snd_strerror(err));
return False;
}
if ((err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0)
{
error("snd_pcm_hw_params_malloc: %s\n", snd_strerror(err));
return False;
}
snd_pcm_hw_params_free(hwparams);
#endif
if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
return False;
if ((pwfx->nChannels != 1) && (pwfx->nChannels != 2))
return False;
if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
return False;
if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050))
return False;
return True;
}
开发者ID:AmesianX,项目名称:rdesktop-fuzzer,代码行数:32,代码来源:rdpsnd_alsa.c
示例6: audin_alsa_set_params
static boolean audin_alsa_set_params(AudinALSADevice* alsa, snd_pcm_t* capture_handle)
{
int error;
snd_pcm_hw_params_t* hw_params;
if ((error = snd_pcm_hw_params_malloc(&hw_params)) < 0)
{
DEBUG_WARN("snd_pcm_hw_params_malloc (%s)",
snd_strerror(error));
return False;
}
snd_pcm_hw_params_any(capture_handle, hw_params);
snd_pcm_hw_params_set_access(capture_handle, hw_params,
SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(capture_handle, hw_params,
alsa->format);
snd_pcm_hw_params_set_rate_near(capture_handle, hw_params,
&alsa->actual_rate, NULL);
snd_pcm_hw_params_set_channels_near(capture_handle, hw_params,
&alsa->actual_channels);
snd_pcm_hw_params(capture_handle, hw_params);
snd_pcm_hw_params_free(hw_params);
snd_pcm_prepare(capture_handle);
if ((alsa->actual_rate != alsa->target_rate) ||
(alsa->actual_channels != alsa->target_channels))
{
DEBUG_DVC("actual rate %d / channel %d is "
"different from target rate %d / channel %d, resampling required.",
alsa->actual_rate, alsa->actual_channels,
alsa->target_rate, alsa->target_channels);
}
return True;
}
开发者ID:kidfolk,项目名称:FreeRDP,代码行数:34,代码来源:audin_alsa.c
示例7: ALSA
ALSA(unsigned channels, unsigned samplerate, const std::string& device = "default") : runnable(true), pcm(nullptr), params(nullptr), fps(samplerate)
{
int rc = snd_pcm_open(&pcm, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
if (rc < 0)
{
runnable = false;
throw DeviceException(General::join("Unable to open PCM device ", snd_strerror(rc)));
}
snd_pcm_format_t fmt = type_to_format(T());
if (snd_pcm_hw_params_malloc(¶ms) < 0)
{
runnable = false;
throw DeviceException("Failed to allocate memory.");
}
runnable = false;
if (
(snd_pcm_hw_params_any(pcm, params) < 0) ||
(snd_pcm_hw_params_set_access(pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) ||
(snd_pcm_hw_params_set_channels(pcm, params, channels) < 0) ||
(snd_pcm_hw_params_set_format(pcm, params, fmt) < 0) ||
(snd_pcm_hw_params_set_rate(pcm, params, samplerate, 0) < 0) ||
((rc = snd_pcm_hw_params(pcm, params)) < 0)
)
throw DeviceException(General::join("Unable to install HW params: ", snd_strerror(rc)));
runnable = true;
}
开发者ID:Themaister,项目名称:SLIMPlayer,代码行数:30,代码来源:alsa.hpp
示例8: configureInitialState
/*
* Set some stuff up.
*/
static int configureInitialState(const char* pathName, AudioState* audioState)
{
#if BUILD_SIM_WITHOUT_AUDIO
return 0;
#else
audioState->handle = NULL;
snd_pcm_open(&audioState->handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
if (audioState->handle) {
snd_pcm_hw_params_t *params;
snd_pcm_hw_params_malloc(¶ms);
snd_pcm_hw_params_any(audioState->handle, params);
snd_pcm_hw_params_set_access(audioState->handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(audioState->handle, params, SND_PCM_FORMAT_S16_LE);
unsigned int rate = 44100;
snd_pcm_hw_params_set_rate_near(audioState->handle, params, &rate, NULL);
snd_pcm_hw_params_set_channels(audioState->handle, params, 2);
snd_pcm_hw_params(audioState->handle, params);
snd_pcm_hw_params_free(params);
} else {
wsLog("Couldn't open audio hardware, faking it\n");
}
return 0;
#endif
}
开发者ID:Andproject,项目名称:platform_development,代码行数:30,代码来源:DevAudio.c
示例9: main
int main(int argc,char *argv[]){
int i = 0;
int err;
char buf[128];
snd_pcm_t *playback_handle;
int rate = 22025;
int channels = 2;
snd_pcm_hw_params_t *hw_params;
if((err = snd_pcm_open(&playback_handle,"default",SND_PCM_STREAM_PLAYBACK,0)) < 0){
fprintf(stderr,"can't open!%s(%s)\n","default",snd_strerror(err));
exit(1);
}
if((err = snd_pcm_hw_params_malloc(&hw_params) < 0)){
fprintf(stderr,"can't open!(%s)\n",snd_strerror(err));
exit(1);
}
if((err = snd_pcm_hw_params_any(playback_handle,hw_params)) < 0){
fprintf(stderr,"can't open(%s)\n",snd_strerror(err));
exit(1);
}
if((err = snd_pcm_hw_params_set_access(playback_handle,hw_params,SND_PCM_ACCESS_RW_INTERLEAVED)) < 0){
fprintf(stderr,"can't open(%s)\n",snd_strerror(err));
exit(1);
}
if((err = snd_pcm_hw_params_set_format(playback_handle,hw_params,SND_PCM_FORMAT_S16_LE)) < 0){
fprintf(stderr,"can't set(%s)\n",snd_strerror(err));
exit(1);
}
if((err = snd_pcm_hw_params_set_rate_near(playback_handle,hw_params,&rate,0)) < 0){
fprintf(stderr,"can't set(%s)\n",snd_strerror(err));
exit(1);
}
if((err = snd_pcm_hw_params_set_channels(playback_handle,hw_params,channels)) < 0){
fprintf(stderr,"can't set(%s)\n",snd_strerror(err));
exit(1);
}
if((err = snd_pcm_hw_params(playback_handle,hw_params)) < 0){
fprintf(stderr,"can't open(%s)\n",snd_strerror(err));
exit(1);
}
snd_pcm_hw_params_free(hw_params);
if((err = snd_pcm_prepare(playback_handle)) < 0){
fprintf(stderr,"can't prepare(%s)\n",snd_strerror(err));
exit(1);
}
i = 0;
while(i < 256){
memset(buf,i,128);
err = snd_pcm_writei(playback_handle,buf,32);
//fprintf(stderr,"write %d\n",err);
if(err < 0){
snd_pcm_prepare(playback_handle);
printf("a");
}
i++;
}
snd_pcm_close(playback_handle);
exit(0);
}
开发者ID:windleos,项目名称:sound-card,代码行数:59,代码来源:demo8.c
示例10: InitAudioCaptureDevice
static Int32 InitAudioCaptureDevice (Int32 channels, UInt32 sample_rate, Int32 driver_buf_size)
{
snd_pcm_hw_params_t *hw_params;
Int32 err;
if ((err = snd_pcm_open (&capture_handle, ALSA_CAPTURE_DEVICE, SND_PCM_STREAM_CAPTURE, 0)) < 0)
{
fprintf (stderr, "AUDIO >> cannot open audio device plughw:1,0 (%s)\n", snd_strerror (err));
return -1;
}
// printf ("AUDIO >> opened %s device\n", ALSA_CAPTURE_DEVICE);
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot allocate hardware parameter structure (%s)\n", err, capture_handle);
}
if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot initialize hardware parameter structure (%s)\n", err, capture_handle);
}
if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set access type (%s)\n", err, capture_handle);
}
if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set sample format (%s)\n", err, capture_handle);
}
if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &sample_rate, 0)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set sample rate (%s)\n", err, capture_handle);
}
if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, channels)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set channel count (%s)\n", err, capture_handle);
}
if ((err = snd_pcm_hw_params_set_buffer_size (capture_handle, hw_params, driver_buf_size)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set buffer size (%s)\n", err, capture_handle);
}
if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot set parameters (%s)\n", err, capture_handle);
}
snd_pcm_hw_params_free (hw_params);
if ((err = snd_pcm_prepare (capture_handle)) < 0)
{
AUD_DEVICE_PRINT_ERROR_AND_RETURN("cannot prepare audio interface for use (%s)\n", err, capture_handle);
}
return 0;
}
开发者ID:sdut10523,项目名称:dvr_rdk,代码行数:59,代码来源:audio_capture.c
示例11: 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
示例12: qPrintable
int AudioALSA::init_audio()
{
int err = 0, dir = 1;
unsigned int tmp_sampfreq = sampfreq;
std::cout << qPrintable(tr("initializing audio at ")) << qPrintable(dsp_devicename) << std::endl;
if ((err = snd_pcm_open(&capture_handle, dsp_devicename.toStdString().c_str(), SND_PCM_STREAM_CAPTURE, 0)) < 0) {
std::cerr << "cannot open audio device " << qPrintable(dsp_devicename) << " (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
std::cerr << "cannot allocate hardware parameter structure (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
if ((err = snd_pcm_hw_params_any(capture_handle, hw_params)) < 0) {
std::cerr << "cannot initialize hardware parameter structure (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
if ((err = snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
std::cerr << "cannot set access type (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
if ((err = snd_pcm_hw_params_set_format(capture_handle, hw_params, SND_PCM_FORMAT_U8)) < 0) {
std::cerr << "cannot set sample format (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
if ((err = snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &tmp_sampfreq, &dir)) < 0) {
std::cerr << "cannot set sample rate (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
sampfreq = tmp_sampfreq;
if ((err = snd_pcm_hw_params_set_channels(capture_handle, hw_params, 1)) < 0) {
std::cerr << "cannot set channel count (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
if ((err = snd_pcm_hw_params(capture_handle, hw_params)) < 0) {
std::cerr << "cannot set parameters (" << snd_strerror(err) << ")." << std::endl;
exit (1);
}
snd_pcm_hw_params_free(hw_params);
if ((err = snd_pcm_prepare(capture_handle)) < 0) {
std::cerr << "cannot prepare audio interface for use (" << snd_strerror(err) << std::endl;
exit (1);
}
blksize = 256;
return 1;
}
开发者ID:ycollet,项目名称:qtguitune,代码行数:58,代码来源:audio_alsa.cpp
示例13: malloc
AlsaDevice *alsa_device_sample( const char *device_name, unsigned int rate )
{
int err;
snd_pcm_hw_params_t *hw_params;
static snd_output_t *jcd_out;
AlsaDevice *dev = malloc( sizeof( *dev ) );
if ( !dev )
return NULL;
dev->device_name = malloc( 1 + strlen( device_name ) );
if ( !dev->device_name )
{
free(dev);
return NULL;
}
strcpy(dev->device_name, device_name);
err = snd_output_stdio_attach( &jcd_out, stdout, 0 );
if ( ( err = snd_pcm_open ( &dev->capture_handle, dev->device_name, SND_PCM_STREAM_CAPTURE, 0 ) ) < 0 )
{
rc = 0;
fprintf (stderr, "\033[0;31m[vokoscreen] alsa_device_sample() in alsadevice.c: cannot open audio device %s (%s)\033[0;0m\n", dev->device_name, snd_strerror (err) );
return NULL;
}
else
{
rc = 1;
// fprintf (stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: open audio device %s (%s)\n", dev->device_name, snd_strerror (err) );
}
if ( ( err = snd_pcm_hw_params_malloc ( &hw_params ) ) < 0 )
{
fprintf (stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: cannot allocate hardware parameter structure (%s)\n", snd_strerror( err ) );
}
if ( ( err = snd_pcm_hw_params_any( dev->capture_handle, hw_params ) ) < 0 )
{
fprintf (stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: cannot initialize hardware parameter structure (%s)\n", snd_strerror( err ) );
}
if ( ( err = snd_pcm_hw_params_set_rate_near (dev->capture_handle, hw_params, &rate, 0 ) ) < 0 )
{
fprintf( stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: cannot set sample rate (%s)\n", snd_strerror( err ) );
rc = 0;
}
else
{
rc = 1;
rcSampleRate = rate;
}
//fprintf ( stderr, "[vokoscreen] alsa_device_sample() in alsadevice.c: Samplerate = %d\n", rate );
snd_pcm_close( dev->capture_handle );
free( dev->device_name );
free( dev );
return dev;
}
开发者ID:TheDudeWithThreeHands,项目名称:CapScreen,代码行数:58,代码来源:alsa_device.c
示例14: AudioDevice
AudioAlsa::AudioAlsa( bool & _success_ful, Mixer* _mixer ) :
AudioDevice( tLimit<ch_cnt_t>(
ConfigManager::inst()->value( "audioalsa", "channels" ).toInt(),
DEFAULT_CHANNELS, SURROUND_CHANNELS ),
_mixer ),
m_handle( NULL ),
m_hwParams( NULL ),
m_swParams( NULL ),
m_convertEndian( false )
{
_success_ful = false;
int err;
if( ( err = snd_pcm_open( &m_handle,
probeDevice().toLatin1().constData(),
SND_PCM_STREAM_PLAYBACK,
0 ) ) < 0 )
{
printf( "Playback open error: %s\n", snd_strerror( err ) );
return;
}
snd_pcm_hw_params_malloc( &m_hwParams );
snd_pcm_sw_params_malloc( &m_swParams );
if( ( err = setHWParams( channels(),
SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 )
{
printf( "Setting of hwparams failed: %s\n",
snd_strerror( err ) );
return;
}
if( ( err = setSWParams() ) < 0 )
{
printf( "Setting of swparams failed: %s\n",
snd_strerror( err ) );
return;
}
// set FD_CLOEXEC flag for all file descriptors so forked processes
// do not inherit them
struct pollfd * ufds;
int count = snd_pcm_poll_descriptors_count( m_handle );
ufds = new pollfd[count];
snd_pcm_poll_descriptors( m_handle, ufds, count );
for( int i = 0; i < qMax( 3, count ); ++i )
{
const int fd = ( i >= count ) ? ufds[0].fd+i : ufds[i].fd;
int oldflags = fcntl( fd, F_GETFD, 0 );
if( oldflags < 0 )
continue;
oldflags |= FD_CLOEXEC;
fcntl( fd, F_SETFD, oldflags );
}
delete[] ufds;
_success_ful = true;
}
开发者ID:GNUMariano,项目名称:lmms,代码行数:58,代码来源:AudioAlsa.cpp
示例15: alsa_set_hw_params
static void alsa_set_hw_params(struct alsa_dev *dev, snd_pcm_t *handle,
unsigned int rate, int channels, int period)
{
int dir, ret;
snd_pcm_uframes_t period_size;
snd_pcm_uframes_t buffer_size;
snd_pcm_hw_params_t *hw_params;
ret = snd_pcm_hw_params_malloc(&hw_params);
if (ret < 0)
syslog_panic("Cannot allocate hardware parameters: %s\n",
snd_strerror(ret));
ret = snd_pcm_hw_params_any(handle, hw_params);
if (ret < 0)
syslog_panic("Cannot initialize hardware parameters: %s\n",
snd_strerror(ret));
ret = snd_pcm_hw_params_set_access(handle, hw_params,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (ret < 0)
syslog_panic("Cannot set access type: %s\n",
snd_strerror(ret));
ret = snd_pcm_hw_params_set_format(handle, hw_params,
SND_PCM_FORMAT_S16_LE);
if (ret < 0)
syslog_panic("Cannot set sample format: %s\n",
snd_strerror(ret));
ret = snd_pcm_hw_params_set_rate_near(handle, hw_params, &rate, 0);
if (ret < 0)
syslog_panic("Cannot set sample rate: %s\n",
snd_strerror(ret));
ret = snd_pcm_hw_params_set_channels(handle, hw_params, channels);
if (ret < 0)
syslog_panic("Cannot set channel number: %s\n",
snd_strerror(ret));
period_size = period;
dir = 0;
ret = snd_pcm_hw_params_set_period_size_near(handle, hw_params,
&period_size, &dir);
if (ret < 0)
syslog_panic("Cannot set period size: %s\n",
snd_strerror(ret));
ret = snd_pcm_hw_params_set_periods(handle, hw_params, PERIODS, 0);
if (ret < 0)
syslog_panic("Cannot set period number: %s\n",
snd_strerror(ret));
buffer_size = period_size * PERIODS;
dir = 0;
ret = snd_pcm_hw_params_set_buffer_size_near(handle, hw_params,
&buffer_size);
if (ret < 0)
syslog_panic("Cannot set buffer size: %s\n",
snd_strerror(ret));
ret = snd_pcm_hw_params(handle, hw_params);
if (ret < 0)
syslog_panic("Cannot set capture parameters: %s\n",
snd_strerror(ret));
snd_pcm_hw_params_free(hw_params);
}
开发者ID:ipoerner,项目名称:transsip,代码行数:58,代码来源:alsa.c
示例16: set_device
static int set_device(Instance *pi, const char *value)
{
ALSAio_private *priv = (ALSAio_private *)pi;
int rc = 0;
int i;
String_free(&priv->c.device);
priv->c.device = String_new(value);
if (priv->c.handle) {
snd_pcm_close(priv->c.handle);
}
/* Try matching by description first... */
Range available_alsa_devices = {};
get_device_range(pi, &available_alsa_devices);
for (i=0; i < available_alsa_devices.descriptions.count; i++) {
if (strstr(available_alsa_devices.descriptions.items[i]->bytes, value)) {
puts("found it!");
priv->c.device = String_new(available_alsa_devices.strings.items[i]->bytes);
break;
}
}
Range_clear(&available_alsa_devices);
if (String_is_none(priv->c.device)) {
/* Not found, try value as supplied. */
priv->c.device = String_new(value);
}
rc = snd_pcm_open(&priv->c.handle, s(priv->c.device), priv->c.mode, 0);
if (rc < 0) {
fprintf(stderr, "*** snd_pcm_open %s: %s\n", s(priv->c.device), snd_strerror(rc));
goto out;
}
fprintf(stderr, "ALSA device %s opened, handle=%p\n", s(priv->c.device), priv->c.handle);
/* Allocate hardware parameter structure, and call "any", and use
the resulting hwparams in subsequent calls. I had tried calling
_any() in each get/set function, but recording failed, so it
seems ALSA doesn't work that way. */
snd_pcm_hw_params_malloc(&priv->c.hwparams);
rc = snd_pcm_hw_params_any(priv->c.handle, priv->c.hwparams);
/* Might as well set interleaved here, too. */
rc = snd_pcm_hw_params_set_access(priv->c.handle, priv->c.hwparams,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (rc != 0) {
fprintf(stderr, "*** snd_pcm_hw_params_set_access %s: %s\n", s(priv->c.device), snd_strerror(rc));
}
out:
return rc;
}
开发者ID:jamieguinan,项目名称:cti,代码行数:56,代码来源:ALSACapRec.c
示例17: 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
示例18: fprintf
StackAudioDevice *stack_alsa_audio_device_create(const char *name, uint32_t channels, uint32_t sample_rate)
{
// Debug
fprintf(stderr, "stack_alsa_audio_device_create(\"%s\", %u, %u) called\n", name, channels, sample_rate);
// Allocate the new device
StackAlsaAudioDevice *device = new StackAlsaAudioDevice();
device->stream = NULL;
if (snd_pcm_open(&device->stream, name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) != 0)
{
fprintf(stderr, "stack_alsa_audio_device_create: snd_pcm_open() failed\n");
return NULL;
}
// Get some initial hardware parameters
snd_pcm_hw_params_t *hw_params = NULL;
snd_pcm_hw_params_malloc(&hw_params);
snd_pcm_hw_params_any(device->stream, hw_params);
// Choose the correct sample rate
if (snd_pcm_hw_params_set_rate(device->stream, hw_params, sample_rate, 0) < 0)
{
fprintf(stderr, "stack_alsa_audio_device_create: snd_pcm_hw_params_set_rate() failed\n");
}
// Set the correct number of channels
if (snd_pcm_hw_params_set_channels(device->stream, hw_params, channels) < 0)
{
fprintf(stderr, "stack_alsa_audio_device_create: snd_pcm_hw_params_set_channels() failed\n");
}
// Set the format to 32-bit floating point, which is what Stack
// uses internally
if (snd_pcm_hw_params_set_format(device->stream, hw_params, SND_PCM_FORMAT_FLOAT_LE) < 0)
{
fprintf(stderr, "stack_alsa_audio_device_create: snd_pcm_hw_params_set_format() failed\n");
}
// Apply the hardware parameters to the device
snd_pcm_hw_params(device->stream, hw_params);
// Set up superclass
STACK_AUDIO_DEVICE(device)->_class_name = "StackAlsaAudioDevice";
STACK_AUDIO_DEVICE(device)->channels = channels;
STACK_AUDIO_DEVICE(device)->sample_rate = sample_rate;
// Start the PCM stream
if (snd_pcm_start(device->stream) < 0)
{
fprintf(stderr, "stack_alsa_audio_device_create: snd_pcm_start() failed\n");
}
// Return the newly created device
return STACK_AUDIO_DEVICE(device);
}
开发者ID:claytonpeters,项目名称:stack,代码行数:55,代码来源:StackAlsaAudioDevice.cpp
示例19: AudioSource
AudioSourceNix::AudioSourceNix(int c, int r)
: AudioSource(c, r)
{
int err;
unsigned int ap_rate = rate;
unsigned int ap_chan = channels;
err = snd_pcm_open(&device, ADDR, SND_PCM_STREAM_CAPTURE, 0);
if (err < 0) { g2g = PR_FALSE; return; }
err = snd_pcm_hw_params_malloc(¶ms);
if (err < 0) { g2g = PR_FALSE; return; }
err = snd_pcm_hw_params_any(device, params);
if (err < 0) { g2g = PR_FALSE; return; }
err = snd_pcm_hw_params_set_access(
device, params, SND_PCM_ACCESS_RW_INTERLEAVED
);
if (err < 0) { g2g = PR_FALSE; return; }
err = snd_pcm_hw_params_set_format(
device, params, SND_PCM_FORMAT_S16_LE
);
if (err < 0) { g2g = PR_FALSE; return; }
/* For rate and channels if we don't get
* what we want, that's too bad */
err = snd_pcm_hw_params_set_rate_near(
device, params, &ap_rate, 0
);
if (err < 0) {
err = snd_pcm_hw_params_get_rate(
params, &ap_rate, 0
);
if (err < 0) { g2g = PR_FALSE; return; }
}
err = snd_pcm_hw_params_set_channels(
device, params, ap_chan
);
if (err < 0) {
err = snd_pcm_hw_params_get_channels(
params, &ap_chan
);
if (err < 0) { g2g = PR_FALSE; return; }
}
g2g = PR_TRUE;
rec = PR_FALSE;
rate = ap_rate;
channels = ap_chan;
snd_pcm_close(device);
}
开发者ID:1981khj,项目名称:rainbow,代码行数:54,代码来源:AudioSourceNix.cpp
示例20: gst_alsa_probe_supported_formats
GstCaps *
gst_alsa_probe_supported_formats (GstObject * obj, gchar * device,
snd_pcm_t * handle, const GstCaps * template_caps)
{
snd_pcm_hw_params_t *hw_params;
snd_pcm_stream_t stream_type;
GstCaps *caps;
gint err;
snd_pcm_hw_params_malloc (&hw_params);
if ((err = snd_pcm_hw_params_any (handle, hw_params)) < 0)
goto error;
stream_type = snd_pcm_stream (handle);
caps = gst_caps_copy (template_caps);
if (!(caps = gst_alsa_detect_formats (obj, hw_params, caps)))
goto subroutine_error;
if (!(caps = gst_alsa_detect_rates (obj, hw_params, caps)))
goto subroutine_error;
if (!(caps = gst_alsa_detect_channels (obj, hw_params, caps)))
goto subroutine_error;
/* Try opening IEC958 device to see if we can support that format (playback
* only for now but we could add SPDIF capture later) */
if (stream_type == SND_PCM_STREAM_PLAYBACK) {
snd_pcm_t *pcm = gst_alsa_open_iec958_pcm (obj, device);
if (G_LIKELY (pcm)) {
gst_caps_append (caps, gst_caps_from_string (PASSTHROUGH_CAPS));
snd_pcm_close (pcm);
}
}
snd_pcm_hw_params_free (hw_params);
return caps;
/* ERRORS */
error:
{
GST_ERROR_OBJECT (obj, "failed to query formats: %s", snd_strerror (err));
snd_pcm_hw_params_free (hw_params);
return NULL;
}
subroutine_error:
{
GST_ERROR_OBJECT (obj, "failed to query formats");
snd_pcm_hw_params_free (hw_params);
return NULL;
}
}
开发者ID:pli3,项目名称:gst-plugins-base,代码行数:54,代码来源:gstalsa.c
注:本文中的snd_pcm_hw_params_malloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论