public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcel <wittemar@googlemail.com>
To: linux-bluetooth@vger.kernel.org
Subject: Using alsa-lib for headsets: Invalid argument
Date: Mon, 18 May 2009 12:21:06 +0200	[thread overview]
Message-ID: <bb7250380905180321v1f154d11xbb2ca3b60b10cf81@mail.gmail.com> (raw)

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

                 reply	other threads:[~2009-05-18 10:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bb7250380905180321v1f154d11xbb2ca3b60b10cf81@mail.gmail.com \
    --to=wittemar@googlemail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox