Using alsa-lib for headsets: Invalid argument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
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;
}

[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux