* Using alsa-lib for headsets: Invalid argument
@ 2009-05-18 10:21 Marcel
0 siblings, 0 replies; only message in thread
From: Marcel @ 2009-05-18 10:21 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 396 bytes --]
Hi,
I'm trying to use bluez and alsa to play sound through a headset (HSP/A2DP)
I have the following .asoundrc:
pcm.bluetoothraw {
type bluetooth
profile auto
}
pcm.bluetooth {
type plug
slave {
pcm bluetoothraw
}
}
If I use the attached method I get an "Error applying the params to
PCM device bluetooth : Invalid argument". Has anybody an idea why?
Greets,
Marcel
[-- Attachment #2: bluez-alsa.c --]
[-- Type: text/x-csrc, Size: 2497 bytes --]
snd_pcm_t* alsahandle;
snd_pcm_hw_params_t* alsaparams;
#define RATE 44100 //Sample rate
#define PERIODS 2 //Number of periods
#define PERIODSIZE 8192 //Periodsize (bytes)
#define ALSA_DEVICE "bluetooth"
int audio_open_pcm() {
printf("opening the PCM device %s\n", ALSA_DEVICE);
if (snd_pcm_open(&alsahandle, ALSA_DEVICE, SND_PCM_STREAM_PLAYBACK, 0) < 0) {
printf("Error opening PCM device %s\n", ALSA_DEVICE);
return -1;
}
printf("configuring the PCM device %s\n", ALSA_DEVICE);
snd_pcm_hw_params_alloca(&alsaparams);
if (snd_pcm_hw_params_any(alsahandle, alsaparams) < 0) {
printf("Error configuring PCM device %s\n", ALSA_DEVICE);
return -1;
}
if (snd_pcm_hw_params_set_access(alsahandle, alsaparams, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {
printf("Error setting the access for PCM device %s\n", ALSA_DEVICE);
return -1;
}
if (snd_pcm_hw_params_set_format(alsahandle, alsaparams, SND_PCM_FORMAT_S16_LE) < 0) {
printf("Error setting the format for PCM device %s\n", ALSA_DEVICE);
return -1;
}
int exact_rate = RATE;
if (snd_pcm_hw_params_set_rate_near(alsahandle, alsaparams, &exact_rate, 0) < 0) {
printf("Error setting the rate for PCM device %s\n", ALSA_DEVICE);
return -1;
}
if (RATE != exact_rate) {
printf("The rate %d Hz is not supported by your hardware, using %d Hz instead.\n", RATE, exact_rate);
}
if (snd_pcm_hw_params_set_channels(alsahandle, alsaparams, 2) < 0) {
printf("Error setting the channels for PCM device %s\n", ALSA_DEVICE);
return -1;
}
if (snd_pcm_hw_params_set_periods(alsahandle, alsaparams, PERIODS, 0) < 0) {
printf("Error setting the periods for PCM device %s\n", ALSA_DEVICE);
return -1;
}
snd_pcm_uframes_t buffersize = (PERIODSIZE * PERIODS) >> 2;
if (snd_pcm_hw_params_set_buffer_size_near(alsahandle, alsaparams, &buffersize) < 0) {
printf("Error setting the buffersize for PCM device %s\n", ALSA_DEVICE);
return -1;
}
if (buffersize != ((PERIODSIZE * PERIODS) >> 2)) {
printf("The buffersize %d is not supported by your hardware, using %d instead.\n", (PERIODSIZE * PERIODS) >> 2, buffersize);
}
int ret = snd_pcm_hw_params(alsahandle, alsaparams);
if (ret < 0) {
printf("Error applying the params to PCM device %s : %s\n", ALSA_DEVICE, snd_strerror(ret));
return -1;
}
return 0;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-05-18 10:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-18 10:21 Using alsa-lib for headsets: Invalid argument Marcel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox