Home | History | Annotate | Download | only in libaudio-qsd8k
      1 /*
      2 ** Copyright 2008, The Android Open-Source Project
      3 **
      4 ** Licensed under the Apache License, Version 2.0 (the "License");
      5 ** you may not use this file except in compliance with the License.
      6 ** You may obtain a copy of the License at
      7 **
      8 **     http://www.apache.org/licenses/LICENSE-2.0
      9 **
     10 ** Unless required by applicable law or agreed to in writing, software
     11 ** distributed under the License is distributed on an "AS IS" BASIS,
     12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 ** See the License for the specific language governing permissions and
     14 ** limitations under the License.
     15 */
     16 
     17 #ifndef ANDROID_AUDIO_HARDWARE_H
     18 #define ANDROID_AUDIO_HARDWARE_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <utils/threads.h>
     24 #include <utils/SortedVector.h>
     25 
     26 #include <hardware_legacy/AudioHardwareBase.h>
     27 
     28 namespace android {
     29 
     30 // ----------------------------------------------------------------------------
     31 // Kernel driver interface
     32 //
     33 /* Source (TX) devices */
     34 #define ADSP_AUDIO_DEVICE_ID_HANDSET_MIC	0x107ac8d
     35 #define ADSP_AUDIO_DEVICE_ID_HEADSET_MIC	0x1081510
     36 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MIC	0x1081512
     37 #define ADSP_AUDIO_DEVICE_ID_BT_SCO_MIC		0x1081518
     38 #define ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_MIC	0x108151b
     39 #define ADSP_AUDIO_DEVICE_ID_I2S_MIC		0x1089bf3
     40 
     41 /* Special loopback pseudo device to be paired with an RX device */
     42 /* with usage ADSP_AUDIO_DEVICE_USAGE_MIXED_PCM_LOOPBACK */
     43 #define ADSP_AUDIO_DEVICE_ID_MIXED_PCM_LOOPBACK_TX	0x1089bf2
     44 
     45 /* Sink (RX) devices */
     46 #define ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR			0x107ac88
     47 #define ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_MONO			0x1081511
     48 #define ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO		0x107ac8a
     49 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO			0x1081513
     50 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_MONO_HEADSET     0x108c508
     51 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_STEREO_HEADSET   0x108c894
     52 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO			0x1081514
     53 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_MONO_HEADSET   0x108c895
     54 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_STEREO_HEADSET	0x108c509
     55 #define ADSP_AUDIO_DEVICE_ID_BT_SCO_SPKR			0x1081519
     56 #define ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_SPKR			0x108151c
     57 #define ADSP_AUDIO_DEVICE_ID_I2S_SPKR				0x1089bf4
     58 
     59 #define HANDSET_MIC                ADSP_AUDIO_DEVICE_ID_HANDSET_MIC
     60 #define HANDSET_SPKR               ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR
     61 #define HEADSET_MIC                ADSP_AUDIO_DEVICE_ID_HEADSET_MIC
     62 #define HEADSET_SPKR_MONO          ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_MONO
     63 #define HEADSET_SPKR_STEREO        ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO
     64 #define SPKR_PHONE_MIC             ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MIC
     65 #define SPKR_PHONE_MONO            ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO
     66 #define SPKR_PHONE_STEREO          ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO
     67 #define BT_A2DP_SPKR               ADSP_AUDIO_DEVICE_ID_BT_A2DP_SPKR
     68 #define BT_SCO_MIC                 ADSP_AUDIO_DEVICE_ID_BT_SCO_MIC
     69 #define BT_SCO_SPKR                ADSP_AUDIO_DEVICE_ID_BT_SCO_SPKR
     70 #define TTY_HEADSET_MIC            ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_MIC
     71 #define TTY_HEADSET_SPKR           ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_SPKR
     72 #define FM_HEADSET                 ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO
     73 #define FM_SPKR	                   ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO
     74 #define SPKR_PHONE_HEADSET_STEREO  ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_MONO_HEADSET
     75 
     76 #define ACDB_ID_HAC_HANDSET_MIC 107
     77 #define ACDB_ID_HAC_HANDSET_SPKR 207
     78 #define ACDB_ID_EXT_MIC_REC 307
     79 #define ACDB_ID_HEADSET_PLAYBACK 407
     80 #define ACDB_ID_HEADSET_RINGTONE_PLAYBACK 408
     81 #define ACDB_ID_INT_MIC_REC 507
     82 #define ACDB_ID_CAMCORDER   508
     83 #define ACDB_ID_INT_MIC_VR  509
     84 #define ACDB_ID_SPKR_PLAYBACK 607
     85 #define ACDB_ID_ALT_SPKR_PLAYBACK 609
     86 
     87 #define SAMP_RATE_INDX_8000	0
     88 #define SAMP_RATE_INDX_11025	1
     89 #define SAMP_RATE_INDX_12000	2
     90 #define SAMP_RATE_INDX_16000	3
     91 #define SAMP_RATE_INDX_22050	4
     92 #define SAMP_RATE_INDX_24000	5
     93 #define SAMP_RATE_INDX_32000	6
     94 #define SAMP_RATE_INDX_44100	7
     95 #define SAMP_RATE_INDX_48000	8
     96 
     97 #define EQ_MAX_BAND_NUM 12
     98 
     99 #define ADRC_ENABLE  0x0001
    100 #define ADRC_DISABLE 0x0000
    101 #define EQ_ENABLE    0x0002
    102 #define EQ_DISABLE   0x0000
    103 #define RX_IIR_ENABLE   0x0004
    104 #define RX_IIR_DISABLE  0x0000
    105 
    106 #define MOD_PLAY 1
    107 #define MOD_REC  2
    108 
    109 struct msm_bt_endpoint {
    110     int tx;
    111     int rx;
    112     char name[64];
    113 };
    114 
    115 struct eq_filter_type {
    116     int16_t gain;
    117     uint16_t freq;
    118     uint16_t type;
    119     uint16_t qf;
    120 };
    121 
    122 struct eqalizer {
    123     uint16_t bands;
    124     uint16_t params[132];
    125 };
    126 
    127 struct rx_iir_filter {
    128     uint16_t num_bands;
    129     uint16_t iir_params[48];
    130 };
    131 
    132 struct msm_audio_config {
    133     uint32_t buffer_size;
    134     uint32_t buffer_count;
    135     uint32_t channel_count;
    136     uint32_t sample_rate;
    137     uint32_t codec_type;
    138     uint32_t unused[3];
    139 };
    140 
    141 struct msm_mute_info {
    142     uint32_t mute;
    143     uint32_t path;
    144 };
    145 
    146 #define CODEC_TYPE_PCM 0
    147 #define PCM_FILL_BUFFER_COUNT 1
    148 #define AUDIO_HW_NUM_OUT_BUF 4  // Number of buffers in audio driver for output
    149 // TODO: determine actual audio DSP and hardware latency
    150 #define AUDIO_HW_OUT_LATENCY_MS 0  // Additionnal latency introduced by audio DSP and hardware in ms
    151 #define AUDIO_HW_OUT_SAMPLERATE 44100 // Default audio output sample rate
    152 #define AUDIO_HW_OUT_CHANNELS (AudioSystem::CHANNEL_OUT_STEREO) // Default audio output channel mask
    153 #define AUDIO_HW_OUT_FORMAT (AudioSystem::PCM_16_BIT)  // Default audio output sample format
    154 #define AUDIO_HW_OUT_BUFSZ 3072  // Default audio output buffer size
    155 
    156 #define AUDIO_HW_IN_SAMPLERATE 8000                 // Default audio input sample rate
    157 #define AUDIO_HW_IN_CHANNELS (AudioSystem::CHANNEL_IN_MONO) // Default audio input channel mask
    158 #define AUDIO_HW_IN_FORMAT (AudioSystem::PCM_16_BIT)  // Default audio input sample format
    159 #define AUDIO_HW_IN_BUFSZ 256  // Default audio input buffer size
    160 
    161 #define VOICE_VOLUME_MAX 5  // Maximum voice volume
    162 // ----------------------------------------------------------------------------
    163 
    164 
    165 class AudioHardware : public  AudioHardwareBase
    166 {
    167     class AudioStreamOutMSM72xx;
    168     class AudioStreamInMSM72xx;
    169 
    170 public:
    171                         AudioHardware();
    172     virtual             ~AudioHardware();
    173     virtual status_t    initCheck();
    174 
    175     virtual status_t    setVoiceVolume(float volume);
    176     virtual status_t    setMasterVolume(float volume);
    177 
    178     virtual status_t    setMode(int mode);
    179 
    180     // mic mute
    181     virtual status_t    setMicMute(bool state);
    182     virtual status_t    getMicMute(bool* state);
    183 
    184     virtual status_t    setParameters(const String8& keyValuePairs);
    185     virtual String8     getParameters(const String8& keys);
    186 
    187     // create I/O streams
    188     virtual AudioStreamOut* openOutputStream(
    189                                 uint32_t devices,
    190                                 int *format=0,
    191                                 uint32_t *channels=0,
    192                                 uint32_t *sampleRate=0,
    193                                 status_t *status=0);
    194 
    195     virtual AudioStreamIn* openInputStream(
    196 
    197                                 uint32_t devices,
    198                                 int *format,
    199                                 uint32_t *channels,
    200                                 uint32_t *sampleRate,
    201                                 status_t *status,
    202                                 AudioSystem::audio_in_acoustics acoustics);
    203 
    204     virtual    void        closeOutputStream(AudioStreamOut* out);
    205     virtual    void        closeInputStream(AudioStreamIn* in);
    206 
    207     virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount);
    208 
    209                void        clearCurDevice() { mCurSndDevice = -1; }
    210 
    211 protected:
    212     virtual status_t    dump(int fd, const Vector<String16>& args);
    213 
    214 private:
    215 
    216     status_t    doAudioRouteOrMute(uint32_t device);
    217     status_t    setMicMute_nosync(bool state);
    218     status_t    checkMicMute();
    219     status_t    dumpInternals(int fd, const Vector<String16>& args);
    220     uint32_t    getInputSampleRate(uint32_t sampleRate);
    221     bool        checkOutputStandby();
    222     status_t    get_mMode();
    223     status_t    get_mRoutes();
    224     status_t    set_mRecordState(bool onoff);
    225     status_t    doA1026_init();
    226     status_t    get_snd_dev();
    227     status_t    get_batt_temp(int *batt_temp);
    228     status_t    doAudience_A1026_Control(int Mode, bool Record, uint32_t Routes);
    229     status_t    doRouting();
    230     status_t    updateACDB();
    231     uint32_t    getACDB(int mode, int device);
    232     AudioStreamInMSM72xx*   getActiveInput_l();
    233     status_t    do_tpa2018_control(int mode);
    234     size_t      getBufferSize(uint32_t sampleRate, int channelCount);
    235 
    236     class AudioStreamOutMSM72xx : public AudioStreamOut {
    237     public:
    238                             AudioStreamOutMSM72xx();
    239         virtual             ~AudioStreamOutMSM72xx();
    240                 status_t    set(AudioHardware* mHardware,
    241                                 uint32_t devices,
    242                                 int *pFormat,
    243                                 uint32_t *pChannels,
    244                                 uint32_t *pRate);
    245         virtual uint32_t    sampleRate() const { return mSampleRate; }
    246         // must be 32-bit aligned
    247         virtual size_t      bufferSize() const { return mBufferSize; }
    248         virtual uint32_t    channels() const { return mChannels; }
    249         virtual int         format() const { return AUDIO_HW_OUT_FORMAT; }
    250         virtual uint32_t    latency() const { return (1000*AUDIO_HW_NUM_OUT_BUF*(bufferSize()/frameSize()))/sampleRate()+AUDIO_HW_OUT_LATENCY_MS; }
    251         virtual status_t    setVolume(float left, float right) { return INVALID_OPERATION; }
    252         virtual ssize_t     write(const void* buffer, size_t bytes);
    253         virtual status_t    standby();
    254         virtual status_t    dump(int fd, const Vector<String16>& args);
    255                 bool        checkStandby();
    256         virtual status_t    setParameters(const String8& keyValuePairs);
    257         virtual String8     getParameters(const String8& keys);
    258                 uint32_t    devices() { return mDevices; }
    259         virtual status_t    getRenderPosition(uint32_t *dspFrames);
    260 
    261     private:
    262                 AudioHardware* mHardware;
    263                 int         mFd;
    264                 int         mStartCount;
    265                 int         mRetryCount;
    266                 bool        mStandby;
    267                 uint32_t    mDevices;
    268                 uint32_t    mChannels;
    269                 uint32_t    mSampleRate;
    270                 size_t      mBufferSize;
    271     };
    272 
    273     class AudioStreamInMSM72xx : public AudioStreamIn {
    274     public:
    275                             AudioStreamInMSM72xx();
    276         virtual             ~AudioStreamInMSM72xx();
    277                 status_t    set(AudioHardware* mHardware,
    278                                 uint32_t devices,
    279                                 int *pFormat,
    280                                 uint32_t *pChannels,
    281                                 uint32_t *pRate,
    282                                 AudioSystem::audio_in_acoustics acoustics);
    283         virtual size_t      bufferSize() const { return mBufferSize; }
    284         virtual uint32_t    channels() const { return mChannels; }
    285         virtual int         format() const { return mFormat; }
    286         virtual uint32_t    sampleRate() const { return mSampleRate; }
    287         virtual status_t    setGain(float gain) { return INVALID_OPERATION; }
    288         virtual ssize_t     read(void* buffer, ssize_t bytes);
    289         virtual status_t    dump(int fd, const Vector<String16>& args);
    290         virtual status_t    standby();
    291         virtual status_t    setParameters(const String8& keyValuePairs);
    292         virtual String8     getParameters(const String8& keys);
    293         virtual unsigned int  getInputFramesLost() const { return 0; }
    294                 uint32_t    devices() { return mDevices; }
    295                 bool        checkStandby();
    296 
    297     private:
    298                 AudioHardware* mHardware;
    299                 int         mFd;
    300                 bool        mStandby;
    301                 int         mRetryCount;
    302                 int         mFormat;
    303                 uint32_t    mChannels;
    304                 uint32_t    mSampleRate;
    305                 size_t      mBufferSize;
    306                 AudioSystem::audio_in_acoustics mAcoustics;
    307                 uint32_t    mDevices;
    308     };
    309 
    310             enum tty_modes {
    311                 TTY_MODE_OFF,
    312                 TTY_MODE_FULL,
    313                 TTY_MODE_VCO,
    314                 TTY_MODE_HCO
    315             };
    316 
    317             static const uint32_t inputSamplingRates[];
    318     Mutex       mA1026Lock;
    319     bool        mA1026Init;
    320             bool        mRecordState;
    321             bool        mInit;
    322             bool        mMicMute;
    323             bool        mBluetoothNrec;
    324             bool        mHACSetting;
    325             uint32_t    mBluetoothIdTx;
    326             uint32_t    mBluetoothIdRx;
    327             AudioStreamOutMSM72xx*  mOutput;
    328             SortedVector <AudioStreamInMSM72xx*>   mInputs;
    329 
    330             msm_bt_endpoint *mBTEndpoints;
    331             int mNumBTEndpoints;
    332             int mCurSndDevice;
    333             int mNoiseSuppressionState;
    334             uint32_t mVoiceVolume;
    335 
    336      friend class AudioStreamInMSM72xx;
    337             Mutex       mLock;
    338             uint32_t        mRoutes[AudioSystem::NUM_MODES];
    339             int         mTTYMode;
    340 };
    341 
    342 // ----------------------------------------------------------------------------
    343 
    344 }; // namespace android
    345 
    346 #endif // ANDROID_AUDIO_HARDWARE_MSM72XX_H
    347