Bluetooth stack, ALSA and Skype in Linux system

来源:互联网 发布:java天气预报接口api 编辑:程序博客网 时间:2024/06/05 15:14

06/28/2006 刚毕业时候写的,呵呵

 

 

Bluetooth stacks under Linux
============================
Bluetooth stacks for Linux I've known are listed here: OpenBT, BlueZ, BlueDrekar and Affix. 

    * OpenBT    First Linux Bluetooth stack, originally developed by Axis 
            Communications Inc. and now is a open source project hosted
            at SourceForge. 
        Project HomePage: http://developer.axis.com/software/bluetooth/
        Download: http://sourceforge.net/projects/openbt/

    * BlueZ        Originally developed by Qualcom and later made OpenSource,
            since version 2.6.4 it's included in the Linux kernel distribution.
        Project HomePage: http://bluez.sourceforge.net/
        Download: http://bluez.sourceforge.net/

    * BlueDrekar    A middleware project from IBM that includes a complete Bluetooth
            stack, only the transport driver is open source.     
        Project HomePage: http://www.alphaWorks.ibm.com/tech/bluedrekar
        Download: http://www.alphaWorks.ibm.com/tech/bluedrekar
    
    * Affix        Not included in Linux kernel distribution, hosted at SourceForge.
        Project HomePage: http://affix.sourceforge.net/
        DownLoad: http://affix.sourceforge.net/



BlueZ and Linux kernel configuration
====================================
1) From version 2.6.4 it is included in the Linux kernel distribution, you can use 
"rpm -qa |grep bluez" to attain the information.

    bluez-libs        Bluetooth libraries
    bluez-libs-devel    Development libraries for Bluetooth applications
    bluez-bluefw        Bluetooth firmware loader
    bluez-hcidump        Analyses Bluetooth HCI packets
    bluez-cups        Bluetooth printer driver for CUPS
    bluez-sdp
    bluez-pan        Bluetooth personal area network
    bluez-pin        Bluetooth PIN helper with D-BUS support
    bluez-utils        Bluetooth tools and daemons
        - hcitool
        - hciattach
        - hciconfig
        - hcid
        - l2ping
        - start scripts
        - pcmcia configuration files

   If you are using an older kernel version, just download some of them according to your
requirement, the essentials are "bluez-libs" and "bluez-utils". The "README" or "INSTALL"
file may show you exactly how to install it. "bluez-libs" should be installed first, then
others, generally are:
        
            ./configure
            make
            make install


2) Make your kernel Bluetooth supporting.
Supposed kernel path is "/usr/src/linux":

    2.6 version kernel:
        * cd /usr/src/linux
        * make menuconfig
            Device Drivers->Networking support-><M>Bluetooth subsystem support
            for convenience you can select all of them and then save the
            configuration.
        * make
        * make modules_install    

    2.4 version kernel:
        * cd /usr/src/linux
        * make menuconfig
            Bluetooth Support->
            for convenience you can select all of them and then save the
            configuration.
        * make dep
        * make bzImage
        * make modules
        * make modules_install


3) The configuration files for Bluetooth are under directory "/etc/bluetooth", you can use 
Bluetooth services quite well without modifying them.

    hcid.conf:
        # Local device class
        class 0x120114    # default
        class 0x200404    # audio/video Bluetooth device connection
        class 0xff0100    # all kinds of Bluetooth device connection

        # highly recommended
        security user
        auth disable
        encrypt disable

    rfcomm.conf:


4) Use Bluetooth utilities.
    
/etc/init.d/bluetooth start|stop|restart|status

    "command --help" or "command -h"
    "command arg --help" or "command arg -h"

    * hciconfig
        a) hciconfig
        b) hciconfig -a
        c) (Important)hciconfig hci0 revision

            . If it prints "SCO mapping: HCI" then your adapter should work

            . If it prints "SCO mapping: PCM" then you might permanently
            change the setting using a command line "pskey mapsco 0"

            . If it doesn't print either of those, you probably need a
            different bluetooth adapter(preferably "CSR" based)
        d) hciconfig dev
        ...

    * hcitool
        a) hcitool inq
        b) hcitool scan
        ...

    * sdptool
        # find out which communication channel is appropriate
        a) sdptool search --bdaddr <bdaddr> 0x1108 
        ...

Notes: In kernel 2.6 version, all commands work quite well; while in 2.4, may be due to 
improper configuration, there are no outputs when using "hciconfig -a" after plugging 
Broadcom based usb dongle; CSR dongle works better.



ALSA and Linux kernel configuration
===================================
The Advanced Linux Sound Architecture(ALSA) provides audio and MIDI functionality to the
Linux operation system. It supports for the older OSS API, providing binary compatibility
for most OSS programs. When you want to use it, the kernel version must be at least 2.2.x,
otherwise you should update the kernel.

1) First you should turn on sound support (soundcore module), it is default in kernel
distribution; also you should select the module:

    cd /usr/src/linux    
    make menuconfig
    version 2.6 kernel:
        (Important)Device Drivers->Sound-><M>Sound card support
            ->Advanced Linux Sound Architecture
            ->PCI devices
            -><M>Emu10K1 (SB Live!, Audigy, E-mu APS)
        make
        make modules_install

    version 2.4 kernel:
        (Important)Sound-><M>Sound Card Support
                -><M>Creative SBLive!(EMU10K1)
        make dep
        make bzImage
        make modules
        make modules_install


2) From version 2.6, ALSA has been integrated into kernel distribution.

     rpm -qa |grep alsa:
        alsa-lib    Include ALSA runtime libraries
        alsa-lib-devel    Include ALSA development libraries    
        alsa-utils    Contain command line utilities for ALSA
        balsa        A e-mail reader, part of the GNOME desktop environment

    For version 2.4, you can download "alsa-lib" and "alsa-utils":

        cd alsa-lib
        ./configure
        make
        make install

        cd alsa-utils
        ./configure
        make
        make install
    

3) You can download "alsa-driver" and "alsa-oss" from the site http://alsa-project.org/,
uncompress them and read "INSTALL" file carefully. Here is a quick reference:

    * alsa-oss:
        cd alsa-oss
        (Important)./configure --with-aoss=yes
        make
        make install
    * alsa-driver
        cd alsa-driver
        ./configure
        make
        make install
        ./snddevices
        alsaconf
        chkconfig (activate the script /etc/init.d/alsasound)
The sound card configuration file for version 2.6 is "/etc/modprobe.conf", and
"/etc/modules.conf" for version 2.4, there's no need altering it.


4) (Important)Make ALSA sound
Maybe you should restart your system first. All mixer channels are muted by default, you must use a native or OSS mixer program to unmute approriate channels. You can run
"alsamixer" or "alsamixer -c 0" to accomplish it.

    * Music
        . Master (on)
        . Master Mono
        . PCM (on)
        ...
        alsactl store    # save current alsa mixer setup to "/etc/asound.state"
    Now, start xmms to test it.    
    
    * Microphone
        . Mic (on) - turn microphone on, if you don't want to hear what you say,
            just set the value to zero
        . Mic as Center/LFE (off) - make sound transfer to remote
          Mic as Center/LFE (on)  - hear what yourself say, sound doesn't
            transfer to others, is different from "loopback"
        . Mic Boost (+20db) (off/on)
        ...
        alsactl strore

    *
        . arecord -f cd filename    # record from mic
        . aplay filename         # playback

    Next we can download a Skype client and make a free call.            



Use Skype and its public API in Linux system
============================================
1)
Skype forum: http://forum.skype.com/ -> Skype for Linux
Skype forum: http://forum.skype.com/ -> Skype Public API
Skype FAQ: http://forum.skype.com/faq.php
Skype Public API: http://share.skype.com/developer_zone/documentation/api_reference/


2) Download a suitable Skype version for your kernel
http://www.skype.com/download/


3) Full dumplex
Run "kcontrol" in shell
    
    Sound & Multimedia
        ->Sound System
            ->General
                select "Enable the sound system"
                select "Run with the highest possible priority"
            ->Hardware
                Select the audio device: Advanced Linux Sound Architecture
                (Important)select "Full duplex"
                select "Use custom sampling rate": 48000Hz
                       "Quality": 16 Bits (high)


4) Skype for Linux is developed based on Qt; it uses OSS (Open Sound System), using
/dev/dsp as its input and output device, it works fine also with ALSA and its OSS
emulation layer.


5) Problems

    * There may be a sound device problem when using Skype to make a call. Solving it,
    you can restart Skype client or use another version Skype.

    * Some times, after making a first Skype call successfully, you may encounter a
    sound device problem when restarting another call procedure; that's to say, normally you
    can only make a call one time after starting Skype; if another wanted, just restart
    Skype.

    * I've not found a proper way of setting audio devices: AUDIO_IN, AUDIO_OUT,
    RINGER in Skype Public API for Linux distribution, which performs quite well in
    Windows system. You can set the audio device "/dev/dsp1" mannually when
   using the new audio device