Merge korg/donut into korg/master
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index 7164b78..13e51ee 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -39,10 +39,15 @@
 {
 public:
 
-    enum stream_type {
+    // input sources values must always be defined in the range
+    // [AudioRecord::DEFAULT_INPUT, AudioRecord::NUM_INPUT_SOURCES[
+    enum input_source {
         DEFAULT_INPUT   =-1,
         MIC_INPUT       = 0,
-        NUM_STREAM_TYPES
+        VOICE_UPLINK_INPUT = 1,
+        VOICE_DOWNLINK_INPUT = 2,
+        VOICE_CALL_INPUT = 3,
+        NUM_INPUT_SOURCES
     };
 
     static const int DEFAULT_SAMPLE_RATE = 8000;
@@ -118,7 +123,7 @@
      *
      * Parameters:
      *
-     * streamType:         Select the audio input to record to (e.g. AudioRecord::MIC_INPUT).
+     * inputSource:        Select the audio input to record to (e.g. AudioRecord::MIC_INPUT).
      * sampleRate:         Track sampling rate in Hz.
      * format:             PCM sample format (e.g AudioSystem::PCM_16_BIT for signed
      *                     16 bits per sample).
@@ -140,7 +145,7 @@
          RECORD_IIR_ENABLE = AudioSystem::TX_IIR_ENABLE
      };
 
-                        AudioRecord(int streamType,
+                        AudioRecord(int inputSource,
                                     uint32_t sampleRate = 0,
                                     int format          = 0,
                                     int channelCount    = 0,
@@ -165,7 +170,7 @@
      *  - NO_INIT: audio server or audio hardware not initialized
      *  - PERMISSION_DENIED: recording is not allowed for the requesting process
      * */
-            status_t    set(int streamType      = 0,
+            status_t    set(int inputSource     = 0,
                             uint32_t sampleRate = 0,
                             int format          = 0,
                             int channelCount    = 0,
@@ -192,11 +197,11 @@
 
    /* getters, see constructor */
 
-            uint32_t    sampleRate() const;
             int         format() const;
             int         channelCount() const;
             uint32_t    frameCount() const;
             int         frameSize() const;
+            int         inputSource() const;
 
 
     /* After it's created the track is not active. Call start() to
@@ -211,7 +216,7 @@
             status_t    stop();
             bool        stopped() const;
 
-    /* get sample rate for this track
+    /* get sample rate for this record track
      */
             uint32_t    getSampleRate();
 
@@ -312,19 +317,18 @@
 
             bool processAudioBuffer(const sp<ClientRecordThread>& thread);
 
-    sp<IAudioFlinger>       mAudioFlinger;
     sp<IAudioRecord>        mAudioRecord;
     sp<IMemory>             mCblkMemory;
     sp<ClientRecordThread>  mClientRecordThread;
     Mutex                   mRecordThreadLock;
 
-    uint32_t                mSampleRate;
     uint32_t                mFrameCount;
 
     audio_track_cblk_t*     mCblk;
     uint8_t                 mFormat;
     uint8_t                 mChannelCount;
-    uint8_t                 mReserved[2];
+    uint8_t                 mInputSource;
+    uint8_t                 mReserved;
     status_t                mStatus;
     uint32_t                mLatency;
 
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 7645978..7c86a65 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -201,7 +201,6 @@
     /* getters, see constructor */
 
             int         streamType() const;
-            uint32_t    sampleRate() const;
             int         format() const;
             int         channelCount() const;
             uint32_t    frameCount() const;
@@ -246,7 +245,7 @@
 
     /* set sample rate for this track, mostly used for games' sound effects
      */
-            void        setSampleRate(int sampleRate);
+            status_t    setSampleRate(int sampleRate);
             uint32_t    getSampleRate();
 
     /* Enables looping and sets the start and end points of looping.
@@ -383,7 +382,6 @@
 
             bool processAudioBuffer(const sp<AudioTrackThread>& thread);
 
-    sp<IAudioFlinger>       mAudioFlinger;
     sp<IAudioTrack>         mAudioTrack;
     sp<IMemory>             mCblkMemory;
     sp<AudioTrackThread>    mAudioTrackThread;
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
index 6f13fe0..3e59d85 100644
--- a/include/media/IAudioFlinger.h
+++ b/include/media/IAudioFlinger.h
@@ -54,7 +54,7 @@
 
     virtual sp<IAudioRecord> openRecord(
                                 pid_t pid,
-                                int streamType,
+                                int inputSource,
                                 uint32_t sampleRate,
                                 int format,
                                 int channelCount,
diff --git a/include/media/IMediaPlayerService.h b/include/media/IMediaPlayerService.h
index 8125cc9..d1d96b1 100644
--- a/include/media/IMediaPlayerService.h
+++ b/include/media/IMediaPlayerService.h
@@ -34,7 +34,7 @@
 public:
     DECLARE_META_INTERFACE(MediaPlayerService);
 
-    virtual sp<IMediaRecorder>  createMediaRecorder(pid_t pid) = 0;  
+    virtual sp<IMediaRecorder>  createMediaRecorder(pid_t pid) = 0;
     virtual sp<IMediaMetadataRetriever> createMetadataRetriever(pid_t pid) = 0;
 
     virtual sp<IMediaPlayer>    create(pid_t pid, const sp<IMediaPlayerClient>& client, const char* url) = 0;
@@ -57,4 +57,3 @@
 }; // namespace android
 
 #endif // ANDROID_IMEDIAPLAYERSERVICE_H
-
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
index 7f0e7b3..7bf555a 100644
--- a/include/media/MediaPlayerInterface.h
+++ b/include/media/MediaPlayerInterface.h
@@ -123,4 +123,3 @@
 
 
 #endif // ANDROID_MEDIAPLAYERINTERFACE_H
-
diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h
index ec64e4d..eafa661 100644
--- a/include/media/ToneGenerator.h
+++ b/include/media/ToneGenerator.h
@@ -18,7 +18,7 @@
 #define ANDROID_TONEGENERATOR_H_
 
 #include <utils/RefBase.h>
-#include <utils/Vector.h>
+#include <utils/KeyedVector.h>
 #include <utils/threads.h>
 #include <media/AudioSystem.h>
 #include <media/AudioTrack.h>
@@ -49,21 +49,106 @@
         TONE_DTMF_C,  // C key: 1633Hz, 852Hz
         TONE_DTMF_D,  // D key: 1633Hz, 941Hz
         // Call supervisory tones:  3GPP TS 22.001 (CEPT)
-        TONE_SUP_DIAL,  // Dial tone: 425Hz, continuous
-        TONE_SUP_BUSY,  // Busy tone: 425Hz, 500ms ON, 500ms OFF...
-        TONE_SUP_CONGESTION,  // Congestion tone: 425Hz, 200ms ON, 200ms OFF...
-        TONE_SUP_RADIO_ACK,  // Radio path acknowlegment: 425Hz, 200ms ON
+        TONE_SUP_DIAL,  // Dial tone: CEPT: 425Hz, continuous
+        FIRST_SUP_TONE = TONE_SUP_DIAL,
+        TONE_SUP_BUSY,  // Busy tone, CEPT: 425Hz, 500ms ON, 500ms OFF...
+        TONE_SUP_CONGESTION,  // Congestion tone CEPT, JAPAN: 425Hz, 200ms ON, 200ms OFF...
+        TONE_SUP_RADIO_ACK,  // Radio path acknowlegment, CEPT, ANSI: 425Hz, 200ms ON
         TONE_SUP_RADIO_NOTAVAIL,  // Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts
         TONE_SUP_ERROR,  // Error/Special info:  950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF...
-        TONE_SUP_CALL_WAITING,  // Call Waiting:  425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF...
-        TONE_SUP_RINGTONE,  // Ring Tone:  425Hz, 1s ON, 4s OFF...
+        TONE_SUP_CALL_WAITING,  // Call Waiting CEPT,JAPAN:  425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF...
+        TONE_SUP_RINGTONE,  // Ring Tone CEPT, JAPAN:  425Hz, 1s ON, 4s OFF...
+        LAST_SUP_TONE = TONE_SUP_RINGTONE,
         // Proprietary tones:  3GPP TS 31.111
         TONE_PROP_BEEP,  // General beep: 400Hz+1200Hz, 35ms ON
         TONE_PROP_ACK,  // Positive Acknowlgement: 1200Hz, 100ms ON, 100ms OFF 2 bursts
-        TONE_PROP_NACK,  // Negative Acknowlgement: 300Hz+400Hz+500Hz, 400ms ON 
+        TONE_PROP_NACK,  // Negative Acknowlgement: 300Hz+400Hz+500Hz, 400ms ON
         TONE_PROP_PROMPT,  // Prompt tone: 400Hz+1200Hz, 200ms ON
         TONE_PROP_BEEP2,  // General double beep: 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms on
-        NUM_TONES
+        // Additional call supervisory tones: specified by IS-95 only
+        TONE_SUP_INTERCEPT, // Intercept tone: alternating 440 Hz and 620 Hz tones, each on for 250 ms.
+        TONE_SUP_INTERCEPT_ABBREV, // Abbreviated intercept: intercept tone limited to 4 seconds
+        TONE_SUP_CONGESTION_ABBREV, // Abbreviated congestion: congestion tone limited to 4 seconds
+        TONE_SUP_CONFIRM, // Confirm tone: a 350 Hz tone added to a 440 Hz tone repeated 3 times in a 100 ms on, 100 ms off cycle.
+        TONE_SUP_PIP, // Pip tone: four bursts of 480 Hz tone (0.1 s on, 0.1 s off).
+
+        // CDMA Tones
+        TONE_CDMA_DIAL_TONE_LITE,
+        TONE_CDMA_NETWORK_USA_RINGBACK,
+        TONE_CDMA_INTERCEPT,
+        TONE_CDMA_ABBR_INTERCEPT,
+        TONE_CDMA_REORDER,
+        TONE_CDMA_ABBR_REORDER,
+        TONE_CDMA_NETWORK_BUSY,
+        TONE_CDMA_CONFIRM,
+        TONE_CDMA_ANSWER,
+        TONE_CDMA_NETWORK_CALLWAITING,
+        TONE_CDMA_PIP,
+
+        // ISDN
+        TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL,  // ISDN Alert Normal
+        TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP, // ISDN Intergroup
+        TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI, // ISDN SP PRI
+        TONE_CDMA_CALL_SIGNAL_ISDN_PAT3,  // ISDN Alert PAT3
+        TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING, // ISDN Alert PING RING
+        TONE_CDMA_CALL_SIGNAL_ISDN_PAT5,  // ISDN Alert PAT5
+        TONE_CDMA_CALL_SIGNAL_ISDN_PAT6,  // ISDN Alert PAT6
+        TONE_CDMA_CALL_SIGNAL_ISDN_PAT7,  // ISDN Alert PAT7
+        // ISDN end
+
+        // IS54
+        TONE_CDMA_HIGH_L,  // IS54 High Pitch Long
+        TONE_CDMA_MED_L, // IS54 Med Pitch Long
+        TONE_CDMA_LOW_L, // IS54 Low Pitch Long
+        TONE_CDMA_HIGH_SS, // IS54 High Pitch Short Short
+        TONE_CDMA_MED_SS, // IS54 Medium Pitch Short Short
+        TONE_CDMA_LOW_SS, // IS54 Low Pitch Short Short
+        TONE_CDMA_HIGH_SSL, // IS54 High Pitch Short Short Long
+        TONE_CDMA_MED_SSL, // IS54 Medium  Pitch Short Short Long
+        TONE_CDMA_LOW_SSL, // IS54 Low  Pitch Short Short Long
+        TONE_CDMA_HIGH_SS_2, // IS54 High Pitch Short Short 2
+        TONE_CDMA_MED_SS_2, // IS54 Med Pitch Short Short 2
+        TONE_CDMA_LOW_SS_2, // IS54 Low  Pitch Short Short 2
+        TONE_CDMA_HIGH_SLS, // IS54 High Pitch Short Long Short
+        TONE_CDMA_MED_SLS, // IS54 Med Pitch Short Long Short
+        TONE_CDMA_LOW_SLS, // IS54 Low Pitch Short Long Short
+        TONE_CDMA_HIGH_S_X4, // IS54 High Pitch Short Short Short Short
+        TONE_CDMA_MED_S_X4, // IS54 Med Pitch Short Short Short Short
+        TONE_CDMA_LOW_S_X4, // IS54 Low Pitch Short Short Short Short
+        TONE_CDMA_HIGH_PBX_L, // PBX High Pitch Long
+        TONE_CDMA_MED_PBX_L, // PBX Med Pitch Long
+        TONE_CDMA_LOW_PBX_L, // PBX Low  Pitch Long
+        TONE_CDMA_HIGH_PBX_SS, // PBX High Short Short
+        TONE_CDMA_MED_PBX_SS, // PBX Med Short Short
+        TONE_CDMA_LOW_PBX_SS, // PBX Low  Short Short
+        TONE_CDMA_HIGH_PBX_SSL, // PBX High Short Short Long
+        TONE_CDMA_MED_PBX_SSL, // PBX Med Short Short Long
+        TONE_CDMA_LOW_PBX_SSL,  // PBX Low Short Short Long
+        TONE_CDMA_HIGH_PBX_SLS, // PBX High  SLS
+        TONE_CDMA_MED_PBX_SLS,  // PBX Med SLS
+        TONE_CDMA_LOW_PBX_SLS, // PBX Low SLS
+        TONE_CDMA_HIGH_PBX_S_X4, // PBX High SSSS
+        TONE_CDMA_MED_PBX_S_X4, // PBX Med SSSS
+        TONE_CDMA_LOW_PBX_S_X4, // PBX LOW SSSS
+        //IS54 end
+        // proprietary
+        TONE_CDMA_ALERT_NETWORK_LITE,
+        TONE_CDMA_ALERT_AUTOREDIAL_LITE,
+        TONE_CDMA_ONE_MIN_BEEP,
+        TONE_CDMA_KEYPAD_VOLUME_KEY_LITE,
+        TONE_CDMA_PRESSHOLDKEY_LITE,
+        TONE_CDMA_ALERT_INCALL_LITE,
+        TONE_CDMA_EMERGENCY_RINGBACK,
+        TONE_CDMA_ALERT_CALL_GUARD,
+        TONE_CDMA_SOFT_ERROR_LITE,
+        TONE_CDMA_CALLDROP_LITE,
+        // proprietary end
+        TONE_CDMA_NETWORK_BUSY_ONE_SHOT,
+        TONE_CDMA_ABBR_ALERT,
+        TONE_CDMA_SIGNAL_OFF,
+        //CDMA end
+        NUM_TONES,
+        NUM_SUP_TONES = LAST_SUP_TONE-FIRST_SUP_TONE+1
     };
 
     ToneGenerator(int streamType, float volume);
@@ -85,13 +170,45 @@
         TONE_RESTARTING  //
     };
 
-    static const unsigned int TONEGEN_MAX_WAVES = 3;
-    static const unsigned int TONEGEN_MAX_SEGMENTS = 4;  // Maximun number of elenemts in
+
+    // Region specific tones.
+    // These supervisory tones are different depending on the region (USA/CANADA, JAPAN, rest of the world).
+    // When a tone in the range [FIRST_SUP_TONE, LAST_SUP_TONE] is requested, the region is determined
+    // from system property gsm.operator.iso-country and the proper tone descriptor is selected with the
+    // help of sToneMappingTable[]
+    enum regional_tone_type {
+        // ANSI supervisory tones
+        TONE_ANSI_DIAL = NUM_TONES, // Dial tone: a continuous 350 Hz + 440 Hz tone.
+        TONE_ANSI_BUSY,             // Busy tone on:  a 480 Hz + 620 Hz tone repeated in a 500 ms on, 500 ms off cycle.
+        TONE_ANSI_CONGESTION,       // Network congestion (reorder) tone on:  a 480 Hz + 620 Hz tone repeated in a 250 ms on, 250 ms off cycle.
+        TONE_ANSI_CALL_WAITING,     // Call waiting tone on: 440 Hz, on for 300 ms, 9,7 s off followed by
+                                    // (440 Hz, on for 100 ms off for 100 ms, on for 100 ms, 9,7s off and repeated as necessary).
+        TONE_ANSI_RINGTONE,         // Ring Tone:  a 440 Hz + 480 Hz tone repeated in a 2 s on, 4 s off pattern.
+        // JAPAN Supervisory tones
+        TONE_JAPAN_DIAL,            // Dial tone: 400Hz, continuous
+        TONE_JAPAN_BUSY,            // Busy tone: 400Hz, 500ms ON, 500ms OFF...
+        TONE_JAPAN_RADIO_ACK,       // Radio path acknowlegment: 400Hz, 1s ON, 2s OFF...
+        NUM_ALTERNATE_TONES
+    };
+
+    enum region {
+        ANSI,
+        JAPAN,
+        CEPT,
+        NUM_REGIONS
+    };
+
+    static const unsigned char sToneMappingTable[NUM_REGIONS-1][NUM_SUP_TONES];
+
+    static const unsigned int TONEGEN_MAX_WAVES = 3;     // Maximun number of sine waves in a tone segment
+    static const unsigned int TONEGEN_MAX_SEGMENTS = 12;  // Maximun number of segments in a tone descriptor
     static const unsigned int TONEGEN_INF = 0xFFFFFFFF;  // Represents infinite time duration
     static const float TONEGEN_GAIN = 0.9;  // Default gain passed to  WaveGenerator().
 
     // ToneDescriptor class contains all parameters needed to generate a tone:
-    //    - The array waveFreq[] contains the frequencies of all individual waves making the multi-tone.
+    //    - The array waveFreq[]:
+    //         1 for static tone descriptors: contains the frequencies of all individual waves making the multi-tone.
+    //         2 for active tone descritors: contains the indexes of the WaveGenerator objects in mWaveGens
     //        The number of sine waves varies from 1 to TONEGEN_MAX_WAVES.
     //        The first null value indicates that no more waves are needed.
     //    - The array segments[] is used to generate the tone pulses. A segment is a period of time
@@ -99,18 +216,30 @@
     //        correspond to tone ON state and segments with odd index to OFF state.
     //        The data stored in segments[] is the duration of the corresponding period in ms.
     //        The first segment encountered with a 0 duration    indicates that no more segment follows.
+    //    - loopCnt - Number of times to repeat a sequence of seqments after playing this
+    //    - loopIndx - The segment index to go back and play is loopcnt > 0
     //    - repeatCnt indicates the number of times the sequence described by segments[] array must be repeated.
-    //        When the tone generator    encounters the first 0 duration segment, it will compare repeatCnt to mCurCount.
-    //        If mCurCount > repeatCnt, the tone is stopped automatically.
+    //        When the tone generator encounters the first 0 duration segment, it will compare repeatCnt to mCurCount.
+    //        If mCurCount > repeatCnt, the tone is stopped automatically. Otherwise, tone sequence will be
+    //        restarted from segment repeatSegment.
+    //    - repeatSegment number of the first repeated segment when repeatCnt is not null
+
+    class ToneSegment {
+    public:
+        unsigned int duration;
+        unsigned short waveFreq[TONEGEN_MAX_WAVES+1];
+        unsigned short loopCnt;
+        unsigned short loopIndx;
+    };
 
     class ToneDescriptor {
     public:
-        unsigned short waveFreq[TONEGEN_MAX_WAVES+1];
-        unsigned long segments[TONEGEN_MAX_SEGMENTS+1];
+        ToneSegment segments[TONEGEN_MAX_SEGMENTS+1];
         unsigned long repeatCnt;
+        unsigned long repeatSegment;
     };
 
-    static const ToneDescriptor toneDescriptors[NUM_TONES];
+    static const ToneDescriptor sToneDescriptors[];
 
     unsigned int mTotalSmp;  // Total number of audio samples played (gives current time)
     unsigned int mNextSegSmp;  // Position of next segment transition expressed in samples
@@ -121,9 +250,12 @@
     unsigned short mCurSegment;  // Current segment index in ToneDescriptor segments[]
     unsigned short mCurCount;  // Current sequence repeat count
     volatile unsigned short mState;  // ToneGenerator state (tone_state)
+    unsigned short mRegion;
     const ToneDescriptor *mpToneDesc;  // pointer to active tone descriptor
     const ToneDescriptor *mpNewToneDesc;  // pointer to next active tone descriptor
 
+    unsigned short mLoopCounter; // Current tone loopback count
+
     int mSamplingRate;  // AudioFlinger Sampling rate
     AudioTrack *mpAudioTrack;  // Pointer to audio track used for playback
     Mutex mLock;  // Mutex to control concurent access to ToneGenerator object from audio callback and application API
@@ -136,8 +268,9 @@
     bool initAudioTrack();
     static void audioCallback(int event, void* user, void *info);
     bool prepareWave();
-    unsigned int numWaves();
+    unsigned int numWaves(unsigned int segmentIdx);
     void clearWaveGens();
+    int getToneForRegion(int toneType);
 
     // WaveGenerator generates a single sine wave
     class WaveGenerator {
@@ -167,7 +300,7 @@
         short mAmplitude_Q15;  // Q15 amplitude
     };
 
-    Vector<WaveGenerator *> mWaveGens;  // list of active wave generators.
+    KeyedVector<unsigned short, WaveGenerator *> mWaveGens;  // list of active wave generators.
 };
 
 }
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
index 255a67b..513ffe1 100644
--- a/include/media/mediaplayer.h
+++ b/include/media/mediaplayer.h
@@ -82,7 +82,7 @@
 //   0xx: Reserved
 //   7xx: Android Player info/warning (e.g player lagging behind.)
 //   8xx: Media info/warning (e.g media badly interleaved.)
-// 
+//
 enum media_info_type {
     // 0xx
     MEDIA_INFO_UNKNOWN = 1,
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
index b9ea0c6..9b54ca9 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -30,30 +30,55 @@
 typedef void (*media_completion_f)(status_t status, void *cookie);
 
 /* Do not change these values without updating their counterparts
- * in java/android/android/media/MediaRecorder.java!
+ * in media/java/android/media/MediaRecorder.java!
  */
 enum audio_source {
     AUDIO_SOURCE_DEFAULT = 0,
     AUDIO_SOURCE_MIC = 1,
+    AUDIO_SOURCE_VOICE_UPLINK = 2,
+    AUDIO_SOURCE_VOICE_DOWNLINK = 3,
+    AUDIO_SOURCE_VOICE_CALL = 4,
+    AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_CALL,
+
+    AUDIO_SOURCE_LIST_END  // must be last - used to validate audio source type
 };
 
 enum video_source {
     VIDEO_SOURCE_DEFAULT = 0,
     VIDEO_SOURCE_CAMERA = 1,
+
+    VIDEO_SOURCE_LIST_END  // must be last - used to validate audio source type
 };
 
-//Please update java/android/android/media/MediaRecorder.java if the following is updated.
+//Please update media/java/android/media/MediaRecorder.java if the following is updated.
 enum output_format {
     OUTPUT_FORMAT_DEFAULT = 0,
-    OUTPUT_FORMAT_THREE_GPP,
-    OUTPUT_FORMAT_MPEG_4,
-    OUTPUT_FORMAT_RAW_AMR,
+    OUTPUT_FORMAT_THREE_GPP = 1,
+    OUTPUT_FORMAT_MPEG_4 = 2,
+
+
+    OUTPUT_FORMAT_AUDIO_ONLY_START = 3, // Used in validating the output format.  Should be the
+                                        //  at the start of the audio only output formats.
+
+    /* These are audio only file formats */
+    OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible
+    OUTPUT_FORMAT_AMR_NB = 3,
+    OUTPUT_FORMAT_AMR_WB = 4,
+    OUTPUT_FORMAT_AAC_ADIF = 5,
+    OUTPUT_FORMAT_AAC_ADTS = 6,
+
     OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
 };
 
 enum audio_encoder {
     AUDIO_ENCODER_DEFAULT = 0,
     AUDIO_ENCODER_AMR_NB = 1,
+    AUDIO_ENCODER_AMR_WB = 2,
+    AUDIO_ENCODER_AAC = 3,
+    AUDIO_ENCODER_AAC_PLUS = 4,
+    AUDIO_ENCODER_EAAC_PLUS = 5,
+
+    AUDIO_ENCODER_LIST_END // must be the last - used to validate the audio encoder type
 };
 
 enum video_encoder {
@@ -61,8 +86,11 @@
     VIDEO_ENCODER_H263 = 1,
     VIDEO_ENCODER_H264 = 2,
     VIDEO_ENCODER_MPEG_4_SP = 3,
+
+    VIDEO_ENCODER_LIST_END // must be the last - used to validate the video encoder type
 };
 
+
 // Maximum frames per second is 24
 #define MEDIA_RECORDER_MAX_FRAME_RATE         24
 
@@ -101,7 +129,7 @@
 // The codes are distributed as follow:
 //   0xx: Reserved
 //   8xx: General info/warning
-// 
+//
 enum media_recorder_info_type {
     MEDIA_RECORDER_INFO_UNKNOWN                   = 1,
     MEDIA_RECORDER_INFO_MAX_DURATION_REACHED      = 800,
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index bda969c..496a739 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -26,7 +26,6 @@
 
 // ----------------------------------------------------------------------------
 
-#define MAX_SAMPLE_RATE     65535
 #define THREAD_PRIORITY_AUDIO_CLIENT (ANDROID_PRIORITY_AUDIO)
 // Maximum cumulated timeout milliseconds before restarting audioflinger thread
 #define MAX_STARTUP_TIMEOUT_MS  3000    // Longer timeout period at startup to cope with A2DP init time
@@ -55,9 +54,9 @@
                     uint16_t    volume[2];
                     uint32_t    volumeLR;
                 };
-                uint16_t    sampleRate;
-                uint16_t    channels;
-                int16_t     flowControlFlag; // underrun (out) or overrrun (in) indication
+                uint32_t    sampleRate;
+                uint8_t     channels;
+                uint8_t     flowControlFlag; // underrun (out) or overrrun (in) indication
                 uint8_t     out;        // out equals 1 for AudioTrack and 0 for AudioRecord
                 uint8_t     forceReady; 
                 uint16_t    bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
diff --git a/include/private/opengles/gl_context.h b/include/private/opengles/gl_context.h
index 0c7ad46..a85f275 100644
--- a/include/private/opengles/gl_context.h
+++ b/include/private/opengles/gl_context.h
@@ -456,7 +456,7 @@
     void validate();
     matrixf_t& top() { return stack[depth]; }
     const matrixf_t& top() const { return stack[depth]; }
-    const uint32_t top_ops() const { return ops[depth]; }
+    uint32_t top_ops() const { return ops[depth]; }
     inline bool isRigidBody() const {
         return !(ops[depth] & ~(OP_TRANSLATE|OP_UNIFORM_SCALE|OP_ROTATE));
     }
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 986f88e..e56efbb 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -50,7 +50,7 @@
 }
 
 AudioRecord::AudioRecord(
-        int streamType,
+        int inputSource,
         uint32_t sampleRate,
         int format,
         int channelCount,
@@ -61,7 +61,7 @@
         int notificationFrames)
     : mStatus(NO_INIT)
 {
-    mStatus = set(streamType, sampleRate, format, channelCount,
+    mStatus = set(inputSource, sampleRate, format, channelCount,
             frameCount, flags, cbf, user, notificationFrames);
 }
 
@@ -73,7 +73,6 @@
         // Otherwise the callback thread will never exit.
         stop();
         if (mClientRecordThread != 0) {
-            mCblk->cv.signal();
             mClientRecordThread->requestExitAndWait();
             mClientRecordThread.clear();
         }
@@ -83,7 +82,7 @@
 }
 
 status_t AudioRecord::set(
-        int streamType,
+        int inputSource,
         uint32_t sampleRate,
         int format,
         int channelCount,
@@ -96,7 +95,7 @@
 {
 
     LOGV("set(): sampleRate %d, channelCount %d, frameCount %d",sampleRate, channelCount, frameCount);
-    if (mAudioFlinger != 0) {
+    if (mAudioRecord != 0) {
         return INVALID_OPERATION;
     }
 
@@ -105,8 +104,8 @@
         return NO_INIT;
     }
 
-    if (streamType == DEFAULT_INPUT) {
-        streamType = MIC_INPUT;
+    if (inputSource == DEFAULT_INPUT) {
+        inputSource = MIC_INPUT;
     }
 
     if (sampleRate == 0) {
@@ -158,7 +157,7 @@
 
     // open record channel
     status_t status;
-    sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), streamType,
+    sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), inputSource,
                                                        sampleRate, format,
                                                        channelCount,
                                                        frameCount,
@@ -181,13 +180,11 @@
 
     mStatus = NO_ERROR;
 
-    mAudioFlinger = audioFlinger;
     mAudioRecord = record;
     mCblkMemory = cblk;
     mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
     mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t);
     mCblk->out = 0;
-    mSampleRate = sampleRate;
     mFormat = format;
     // Update buffer size in case it has been limited by AudioFlinger during track creation
     mFrameCount = mCblk->frameCount;
@@ -198,11 +195,12 @@
     mRemainingFrames = notificationFrames;
     mUserData = user;
     // TODO: add audio hardware input latency here
-    mLatency = (1000*mFrameCount) / mSampleRate;
+    mLatency = (1000*mFrameCount) / sampleRate;
     mMarkerPosition = 0;
     mMarkerReached = false;
     mNewPosition = 0;
     mUpdatePeriod = 0;
+    mInputSource = (uint8_t)inputSource;
 
     return NO_ERROR;
 }
@@ -219,11 +217,6 @@
     return mLatency;
 }
 
-uint32_t AudioRecord::sampleRate() const
-{
-    return mSampleRate;
-}
-
 int AudioRecord::format() const
 {
     return mFormat;
@@ -244,6 +237,11 @@
     return channelCount()*((format() == AudioSystem::PCM_8_BIT) ? sizeof(uint8_t) : sizeof(int16_t));
 }
 
+int AudioRecord::inputSource() const
+{
+    return (int)mInputSource;
+}
+
 // -------------------------------------------------------------------------
 
 status_t AudioRecord::start()
@@ -293,6 +291,7 @@
      }
 
     if (android_atomic_and(~1, &mActive) == 1) {
+        mCblk->cv.signal();
         mAudioRecord->stop();
         // the record head position will reset to 0, so if a marker is set, we need
         // to activate it again
@@ -316,6 +315,11 @@
     return !mActive;
 }
 
+uint32_t AudioRecord::getSampleRate()
+{
+    return mCblk->sampleRate;
+}
+
 status_t AudioRecord::setMarkerPosition(uint32_t marker)
 {
     if (mCbf == 0) return INVALID_OPERATION;
@@ -375,6 +379,7 @@
     status_t result;
     audio_track_cblk_t* cblk = mCblk;
     uint32_t framesReq = audioBuffer->frameCount;
+    uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;
 
     audioBuffer->frameCount  = 0;
     audioBuffer->size        = 0;
@@ -391,9 +396,9 @@
             if (UNLIKELY(!waitCount))
                 return WOULD_BLOCK;
             timeout = 0;
-            result = cblk->cv.waitRelative(cblk->lock, milliseconds(WAIT_PERIOD_MS));
+            result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
             if (__builtin_expect(result!=NO_ERROR, false)) {
-                cblk->waitTimeMs += WAIT_PERIOD_MS;
+                cblk->waitTimeMs += waitTimeMs;
                 if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
                     LOGW(   "obtainBuffer timed out (is the CPU pegged?) "
                             "user=%08x, server=%08x", cblk->user, cblk->server);
@@ -520,7 +525,7 @@
         status_t err = obtainBuffer(&audioBuffer, 1);
         if (err < NO_ERROR) {
             if (err != TIMED_OUT) {
-                LOGE("Error obtaining an audio buffer, giving up.");
+                LOGE_IF(err != status_t(NO_MORE_BUFFERS), "Error obtaining an audio buffer, giving up.");
                 return false;
             }
             break;
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 24f7281..b2c067b 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -92,7 +92,6 @@
         // Otherwise the callback thread will never exit.
         stop();
         if (mAudioTrackThread != 0) {
-            mCblk->cv.signal();
             mAudioTrackThread->requestExitAndWait();
             mAudioTrackThread.clear();
         }
@@ -117,7 +116,7 @@
 
     LOGV_IF(sharedBuffer != 0, "sharedBuffer: %p, size: %d", sharedBuffer->pointer(), sharedBuffer->size());
 
-    if (mAudioFlinger != 0) {
+    if (mAudioTrack != 0) {
         LOGE("Track already in use");
         return INVALID_OPERATION;
     }
@@ -228,7 +227,6 @@
 
     mStatus = NO_ERROR;
 
-    mAudioFlinger = audioFlinger;
     mAudioTrack = track;
     mCblkMemory = cblk;
     mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
@@ -245,7 +243,6 @@
     mCblk->volume[0] = mCblk->volume[1] = 0x1000;
     mVolume[LEFT] = 1.0f;
     mVolume[RIGHT] = 1.0f;
-    mSampleRate = sampleRate;
     mStreamType = streamType;
     mFormat = format;
     mChannelCount = channelCount;
@@ -256,7 +253,7 @@
     mNotificationFrames = notificationFrames;
     mRemainingFrames = notificationFrames;
     mUserData = user;
-    mLatency = afLatency + (1000*mFrameCount) / mSampleRate;
+    mLatency = afLatency + (1000*mFrameCount) / sampleRate;
     mLoopCount = 0;
     mMarkerPosition = 0;
     mMarkerReached = false;
@@ -283,11 +280,6 @@
     return mStreamType;
 }
 
-uint32_t AudioTrack::sampleRate() const
-{
-    return mSampleRate;
-}
-
 int AudioTrack::format() const
 {
     return mFormat;
@@ -357,6 +349,7 @@
     }
 
     if (android_atomic_and(~1, &mActive) == 1) {
+        mCblk->cv.signal();
         mAudioTrack->stop();
         // Cancel loops (If we are in the middle of a loop, playback
         // would not stop until loopCount reaches 0).
@@ -439,24 +432,23 @@
     *right = mVolume[RIGHT];
 }
 
-void AudioTrack::setSampleRate(int rate)
+status_t AudioTrack::setSampleRate(int rate)
 {
     int afSamplingRate;
 
     if (AudioSystem::getOutputSamplingRate(&afSamplingRate, mStreamType) != NO_ERROR) {
-        return;
+        return NO_INIT;
     }
     // Resampler implementation limits input sampling rate to 2 x output sampling rate.
-    if (rate <= 0) rate = 1;
-    if (rate > afSamplingRate*2) rate = afSamplingRate*2;
-    if (rate > MAX_SAMPLE_RATE) rate = MAX_SAMPLE_RATE;
+    if (rate <= 0 || rate > afSamplingRate*2 ) return BAD_VALUE;
 
-    mCblk->sampleRate = (uint16_t)rate;
+    mCblk->sampleRate = rate;
+    return NO_ERROR;
 }
 
 uint32_t AudioTrack::getSampleRate()
 {
-    return uint32_t(mCblk->sampleRate);
+    return mCblk->sampleRate;
 }
 
 status_t AudioTrack::setLoop(uint32_t loopStart, uint32_t loopEnd, int loopCount)
@@ -596,6 +588,7 @@
     status_t result;
     audio_track_cblk_t* cblk = mCblk;
     uint32_t framesReq = audioBuffer->frameCount;
+    uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;
 
     audioBuffer->frameCount  = 0;
     audioBuffer->size = 0;
@@ -614,9 +607,9 @@
             if (UNLIKELY(!waitCount))
                 return WOULD_BLOCK;
             timeout = 0;
-            result = cblk->cv.waitRelative(cblk->lock, milliseconds(WAIT_PERIOD_MS));
+            result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
             if (__builtin_expect(result!=NO_ERROR, false)) { 
-                cblk->waitTimeMs += WAIT_PERIOD_MS;
+                cblk->waitTimeMs += waitTimeMs;
                 if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
                     // timing out when a loop has been set and we have already written upto loop end
                     // is a normal condition: no need to wake AudioFlinger up.
@@ -798,7 +791,7 @@
         status_t err = obtainBuffer(&audioBuffer, 1);
         if (err < NO_ERROR) {
             if (err != TIMED_OUT) {
-                LOGE("Error obtaining an audio buffer, giving up.");
+                LOGE_IF(err != status_t(NO_MORE_BUFFERS), "Error obtaining an audio buffer, giving up.");
                 return false;
             }
             break;
@@ -866,7 +859,7 @@
     result.append(buffer);
     snprintf(buffer, 255, "  format(%d), channel count(%d), frame count(%d)\n", mFormat, mChannelCount, mFrameCount);
     result.append(buffer);
-    snprintf(buffer, 255, "  sample rate(%d), status(%d), muted(%d)\n", mSampleRate, mStatus, mMuted);
+    snprintf(buffer, 255, "  sample rate(%d), status(%d), muted(%d)\n", (mCblk == 0) ? 0 : mCblk->sampleRate, mStatus, mMuted);
     result.append(buffer);
     snprintf(buffer, 255, "  active(%d), latency (%d)\n", mActive, mLatency);
     result.append(buffer);
diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp
index 5cbb25c..eeaa54f 100644
--- a/media/libmedia/IAudioFlinger.cpp
+++ b/media/libmedia/IAudioFlinger.cpp
@@ -99,7 +99,7 @@
 
     virtual sp<IAudioRecord> openRecord(
                                 pid_t pid,
-                                int streamType,
+                                int inputSource,
                                 uint32_t sampleRate,
                                 int format,
                                 int channelCount,
@@ -110,7 +110,7 @@
         Parcel data, reply;
         data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
         data.writeInt32(pid);
-        data.writeInt32(streamType);
+        data.writeInt32(inputSource);
         data.writeInt32(sampleRate);
         data.writeInt32(format);
         data.writeInt32(channelCount);
@@ -336,7 +336,7 @@
     {
         Parcel data, reply;
         data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
-        remote()->transact(WAKE_UP, data, &reply);
+        remote()->transact(WAKE_UP, data, &reply, IBinder::FLAG_ONEWAY);
         return;
     }
 
@@ -384,14 +384,14 @@
         case OPEN_RECORD: {
             CHECK_INTERFACE(IAudioFlinger, data, reply);
             pid_t pid = data.readInt32();
-            int streamType = data.readInt32();
+            int inputSource = data.readInt32();
             uint32_t sampleRate = data.readInt32();
             int format = data.readInt32();
             int channelCount = data.readInt32();
             size_t bufferCount = data.readInt32();
             uint32_t flags = data.readInt32();
             status_t status;
-            sp<IAudioRecord> record = openRecord(pid, streamType,
+            sp<IAudioRecord> record = openRecord(pid, inputSource,
                     sampleRate, format, channelCount, bufferCount, flags, &status);
             reply->writeInt32(status);
             reply->writeStrongBinder(record->asBinder());
diff --git a/media/libmedia/IAudioFlingerClient.cpp b/media/libmedia/IAudioFlingerClient.cpp
index 5feb11f..9d00aef 100644
--- a/media/libmedia/IAudioFlingerClient.cpp
+++ b/media/libmedia/IAudioFlingerClient.cpp
@@ -43,7 +43,7 @@
         Parcel data, reply;
         data.writeInterfaceToken(IAudioFlingerClient::getInterfaceDescriptor());
         data.writeInt32((int)enabled);
-        remote()->transact(AUDIO_OUTPUT_CHANGED, data, &reply);
+        remote()->transact(AUDIO_OUTPUT_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
     }
 };
 
diff --git a/media/libmedia/IMediaPlayer.cpp b/media/libmedia/IMediaPlayer.cpp
index f37519f..f18765a 100644
--- a/media/libmedia/IMediaPlayer.cpp
+++ b/media/libmedia/IMediaPlayer.cpp
@@ -164,6 +164,7 @@
     status_t setVolume(float leftVolume, float rightVolume)
     {
         Parcel data, reply;
+        data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
         data.writeFloat(leftVolume);
         data.writeFloat(rightVolume);
         remote()->transact(SET_VOLUME, data, &reply);
@@ -261,6 +262,7 @@
             return NO_ERROR;
         } break;
         case SET_VOLUME: {
+            CHECK_INTERFACE(IMediaPlayer, data, reply);
             reply->writeInt32(setVolume(data.readFloat(), data.readFloat()));
             return NO_ERROR;
         } break;
diff --git a/media/libmedia/IMediaPlayerService.cpp b/media/libmedia/IMediaPlayerService.cpp
index 370e3fb..01cdb6c 100644
--- a/media/libmedia/IMediaPlayerService.cpp
+++ b/media/libmedia/IMediaPlayerService.cpp
@@ -195,4 +195,3 @@
 // ----------------------------------------------------------------------------
 
 }; // namespace android
-
diff --git a/media/libmedia/ToneGenerator.cpp b/media/libmedia/ToneGenerator.cpp
index 8560593..c22cd53 100644
--- a/media/libmedia/ToneGenerator.cpp
+++ b/media/libmedia/ToneGenerator.cpp
@@ -24,44 +24,756 @@
 #include <sys/resource.h>
 #include <utils/RefBase.h>
 #include <utils/Timers.h>
+#include <cutils/properties.h>
 #include "media/ToneGenerator.h"
 
+
 namespace android {
 
+
 // Descriptors for all available tones (See ToneGenerator::ToneDescriptor class declaration for details)
-const ToneGenerator::ToneDescriptor
-    ToneGenerator::toneDescriptors[NUM_TONES] = {
-    // waveFreq[]                     segments[]                         repeatCnt
-        { { 1336, 941, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_0
-        { { 1209, 697, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_1
-        { { 1336, 697, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_2
-        { { 1477, 697, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_3
-        { { 1209, 770, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_4
-        { { 1336, 770, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_5
-        { { 1477, 770, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_6
-        { { 1209, 852, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_7
-        { { 1336, 852, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_8
-        { { 1477, 852, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_9
-        { { 1209, 941, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_S
-        { { 1477, 941, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_P
-        { { 1633, 697, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_A
-        { { 1633, 770, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_B
-        { { 1633, 852, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_C
-        { { 1633, 941, 0 },       { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_DTMF_D
-        { { 425, 0 },             { ToneGenerator::TONEGEN_INF, 0 }, ToneGenerator::TONEGEN_INF },  // TONE_SUP_DIAL
-        { { 425, 0 },             { 500, 500, 0 },                   ToneGenerator::TONEGEN_INF },  // TONE_SUP_BUSY
-        { { 425, 0 },             { 200, 200, 0 },                   ToneGenerator::TONEGEN_INF },  // TONE_SUP_CONGESTION
-        { { 425, 0 },             { 200, 0 },                        0 },                           // TONE_SUP_RADIO_ACK
-        { { 425, 0 },             { 200, 200, 0 },                   2 },                           // TONE_SUP_RADIO_NOTAVAIL
-        { { 950, 1400, 1800, 0 }, { 330, 1000, 0 },                  ToneGenerator::TONEGEN_INF },  // TONE_SUP_ERROR
-        { { 425, 0 },             { 200, 600, 200, 3000, 0 },        ToneGenerator::TONEGEN_INF },  // TONE_SUP_CALL_WAITING
-        { { 425, 0 },             { 1000, 4000, 0 },                 ToneGenerator::TONEGEN_INF },  // TONE_SUP_RINGTONE
-        { { 400, 1200, 0 },       { 40, 0 },                         0 },                           // TONE_PROP_BEEP
-        { { 1200, 0 },            { 100, 100, 0 },                   1 },                           // TONE_PROP_ACK
-        { { 300, 400, 500, 0 },   { 400, 0 },                        0 },                           // TONE_PROP_NACK
-        { { 400, 1200, 0 },       { 200, 0 },                        0 },                           // TONE_PROP_PROMPT
-        { { 400, 1200, 0 },       { 40, 200, 40, 0 },                0 }                            // TONE_PROP_BEEP2
-    };
+const ToneGenerator::ToneDescriptor ToneGenerator::sToneDescriptors[] = {
+        { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 941, 0 }, 0, 0},
+                     { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_0
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 697, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_1
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 697, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_2
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 697, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_3
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 770, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_4
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 770, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_5
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 770, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_6
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 852, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_7
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 852, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_8
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 852, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_9
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 941, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_S
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 941, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_P
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 697, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_A
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 770, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                             // TONE_DTMF_B
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 852, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_C
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1633, 941, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_DTMF_D
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_SUP_DIAL
+        { segments: { { duration: 500 , waveFreq: { 425, 0 }, 0, 0},
+                      { duration: 500, waveFreq: { 0 }, 0, 0},
+                         { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_SUP_BUSY
+        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_SUP_CONGESTION
+        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 0,
+          repeatSegment: 0 },                              // TONE_SUP_RADIO_ACK
+        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0},
+                      { duration: 200, waveFreq: { 0 }, 0, 0},
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 2,
+          repeatSegment: 0 },                              // TONE_SUP_RADIO_NOTAVAIL
+        { segments: { { duration: 330, waveFreq: { 950, 1400, 1800, 0 }, 0, 0},
+                      { duration: 1000, waveFreq: { 0 }, 0, 0},
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_SUP_ERROR
+        { segments: { { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
+                      { duration: 600, waveFreq: { 0 }, 0, 0 },
+                      { duration: 200, waveFreq: { 425, 0 }, 0, 0 },
+                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_SUP_CALL_WAITING
+        { segments: { { duration: 1000, waveFreq: { 425, 0 }, 0, 0 },
+                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_SUP_RINGTONE
+        { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 0,
+          repeatSegment: 0 },                              // TONE_PROP_BEEP
+        { segments: { { duration: 100, waveFreq: { 1200, 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 0 }, 0, 0  },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 1,
+          repeatSegment: 0 },                              // TONE_PROP_ACK
+        { segments: { { duration: 400, waveFreq: { 300, 400, 500, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 0,
+          repeatSegment: 0 },                              // TONE_PROP_NACK
+        { segments: { { duration: 200, waveFreq: { 400, 1200, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 0,
+          repeatSegment: 0 },                              // TONE_PROP_PROMPT
+        { segments: { { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 40, waveFreq: { 400, 1200, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 0,
+          repeatSegment: 0 },                             // TONE_PROP_BEEP2
+        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_SUP_INTERCEPT
+        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 7,
+          repeatSegment: 0 },                             // TONE_SUP_INTERCEPT_ABBREV
+        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 7,
+          repeatSegment: 0 },                             // TONE_SUP_CONGESTION_ABBREV
+        { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 2,
+          repeatSegment: 0 },                             // TONE_SUP_CONFIRM
+        { segments: { { duration: 100, waveFreq: { 480, 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 3,
+          repeatSegment: 0 },                              // TONE_SUP_PIP
+        { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 425, 0 }, 0, 0},
+                     { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_CDMA_DIAL_TONE_LITE
+        { segments: { { duration: 2000, waveFreq: { 440, 480, 0 }, 0, 0 },
+                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_CDMA_NETWORK_USA_RINGBACK
+        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt:  ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                             // TONE_CDMA_INTERCEPT
+        { segments: { { duration: 250, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 620, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt:  0,
+          repeatSegment: 0 },                             // TONE_CDMA_ABBR_INTERCEPT
+        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_CDMA_REORDER
+        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 7,
+          repeatSegment: 0 },                              // TONE_CDMA_ABBR_REORDER
+        { segments: { { duration: 500, waveFreq: { 480, 620, 0 }, 0, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_CDMA_NETWORK_BUSY
+        { segments: { { duration: 100, waveFreq: { 350, 440, 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 2,
+          repeatSegment: 0 },                              // TONE_CDMA_CONFIRM
+        { segments: { { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: 0,
+          repeatSegment: 0 },                              // TONE_CDMA_ANSWER
+        { segments: { { duration: 300, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 0,
+          repeatSegment: 0 },                              // TONE_CDMA_NETWORK_CALLWAITING
+        { segments: { { duration: 100, waveFreq: { 480, 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 3,
+          repeatSegment: 0 },                              // TONE_CDMA_PIP
+
+        { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 64, waveFreq: { 2556, 0}, 19, 0},
+                      { duration: 32, waveFreq: { 2091, 0}, 0, 0},
+                      { duration: 48, waveFreq: { 2556, 0}, 0, 0},
+                      { duration: 4000, waveFreq: { 0 }, 0, 0},
+                      { duration: 0,  waveFreq: { 0 }, 0, 0}},
+          repeatCnt: 0,
+          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL
+        { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 64, waveFreq: { 2556, 0}, 7, 0 },
+                      { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 400, waveFreq: { 0 }, 0, 0 },
+                      { duration: 32,  waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 64,  waveFreq: { 2556, 0}, 7, 4 },
+                      { duration: 32,  waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0,    waveFreq: { 0 }, 0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                              // TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP
+        { segments: { { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 64, waveFreq: { 2556, 0}, 3, 0 },
+                      { duration: 16, waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 200, waveFreq: { 0 },     0, 0 },
+                      { duration: 32, waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 64, waveFreq: { 2556, 0}, 3, 4 },
+                      { duration: 16, waveFreq: { 2091, 0}, 0, 0 },
+                      { duration: 200, waveFreq: { 0 },     0, 0 },
+                      { duration: 0,   waveFreq: { 0 },     0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI
+        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
+           repeatCnt: 0,
+           repeatSegment: 0 },                            // TONE_CDMA_CALL_SIGNAL_ISDN_PAT3
+        { segments: { { duration: 32, waveFreq: { 2091, 0 }, 0, 0 },
+                      { duration: 64, waveFreq: { 2556, 0 }, 4, 0 },
+                      { duration: 20, waveFreq: { 2091, 0 }, 0, 0 },
+                      { duration: 0,  waveFreq: { 0 }      , 0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING
+        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
+          repeatCnt: 0,
+          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT5
+        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
+          repeatCnt: 0,
+          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT6
+        { segments: { { duration: 0,  waveFreq: { 0 }, 0, 0} },
+          repeatCnt: 0,
+          repeatSegment: 0 },                             // TONE_CDMA_CALL_SIGNAL_ISDN_PAT7
+
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 39, 0 },
+                      { duration: 4000, waveFreq: { 0 },     0, 0 },
+                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_L
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 39, 0 },
+                      { duration: 4000, waveFreq: { 0 },     0, 0 },
+                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_L
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 39, 0 },
+                      { duration: 4000, waveFreq: { 0 },     0, 0 },
+                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_L
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 15, 0 },
+                      { duration: 400, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 } },
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SS
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 15, 0 },
+                      { duration: 400, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_SS
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 15, 0 },
+                      { duration: 400, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_SS
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 15, 6 },
+                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SSL
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 15, 6 },
+                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_SSL
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 15, 6 },
+                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_SSL
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 19, 0 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 19, 3 },
+                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SS_2
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 19, 0 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 19, 3 },
+                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_SS_2
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 19, 0 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 19, 3 },
+                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_SS_2
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 9, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 19, 3 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 9, 6 },
+                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_SLS
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 9, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 19, 3 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 9, 6 },
+                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_SLS
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 9, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 19, 3 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 9, 6 },
+                      { duration: 3000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_SLS
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 9, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 9, 3 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 9, 6 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 9, 9 },
+                      { duration: 2500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_S_X4
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 9, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 9, 3 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 9, 6 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 9, 9 },
+                      { duration: 2500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_S_X4
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 9, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 9, 3 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 9, 6 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 9, 9 },
+                      { duration: 2500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_S_X4
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 19, 0 },
+                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_L
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 19, 0 },
+                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_L
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 19, 0 },
+                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_L
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
+                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_SS
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
+                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_SS
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
+                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_SS
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 15, 6 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_SSL
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 15, 6 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_SSL
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 15, 6 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_SSL
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 15, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 6 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_SLS
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 15, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 6 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_SLS
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 15, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 6 },
+                      { duration: 1000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_SLS
+        { segments: { { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 6 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 3700, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 4000, 0 }, 7, 9 },
+                      { duration: 800, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_HIGH_PBX_S_X4
+        { segments: { { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 6 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2600, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 2900, 0 }, 7, 9 },
+                      { duration: 800, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_MED_PBX_S_X4
+        { segments: { { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 0 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 3 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 6 },
+                      { duration: 200, waveFreq: { 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1300, 0 }, 0, 0 },
+                      { duration: 25, waveFreq: { 1450, 0 }, 7, 9 },
+                      { duration: 800, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                           // TONE_CDMA_LOW_PBX_S_X4
+
+        { segments: { { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 784, 0 },  0, 0 },
+                      { duration: 62, waveFreq: { 740, 0 },  0, 0 },
+                      { duration: 62, waveFreq: { 622, 0 },  0, 0 },
+                      { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
+                      { duration: 0,  waveFreq: { 0 },       0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_ALERT_NETWORK_LITE
+        { segments: { { duration: 62, waveFreq: { 1245, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 659, 0 },  2, 0 },
+                      { duration: 62, waveFreq: { 1245, 0 }, 0, 0 },
+                      { duration: 0,  waveFreq: { 0 },       0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_ALERT_AUTOREDIAL_LITE
+        { segments: { { duration: 400, waveFreq: { 1150, 770, 0 }, 0, 0 },
+                      { duration: 0,   waveFreq: { 0 },            0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_ONE_MIN_BEEP
+        { segments: { { duration: 120, waveFreq: { 941, 1477, 0 }, 0, 0 },
+                      { duration: 0,   waveFreq: { 0 },            0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_KEYPAD_VOLUME_KEY_LITE
+        { segments: { { duration: 375, waveFreq: { 587, 0 }, 0, 0 },
+                      { duration: 125, waveFreq: { 1175, 0 }, 0, 0 },
+                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_PRESSHOLDKEY_LITE
+        { segments: { { duration: 62, waveFreq: { 587, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 831, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 1109, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 831, 0 }, 0, 0 },
+                      { duration: 62, waveFreq: { 784, 0 }, 0, 0 },
+                      { duration: 0,  waveFreq: { 0 },      0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                             // TONE_CDMA_ALERT_INCALL_LITE
+        { segments: { { duration: 125, waveFreq: { 941, 0 }, 0, 0 },
+                      { duration: 10,  waveFreq: { 0 },      2, 0 },
+                      { duration: 4990, waveFreq: { 0 },     0, 0 },
+                      { duration: 0,    waveFreq: { 0 },     0, 0 } },
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                            // TONE_CDMA_EMERGENCY_RINGBACK
+        { segments: { { duration: 125, waveFreq: { 1319, 0 }, 0, 0 },
+                      { duration: 125, waveFreq: { 0 },       0, 0 },
+                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
+          repeatCnt: 2,
+          repeatSegment: 0 },                            // TONE_CDMA_ALERT_CALL_GUARD
+        { segments: { { duration: 125, waveFreq: { 1047, 0 }, 0, 0 },
+                      { duration: 125, waveFreq: { 370,  0 }, 0, 0 },
+                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_SOFT_ERROR_LITE
+        { segments: { { duration: 125, waveFreq: { 1480, 0 }, 0, 0 },
+                      { duration: 125, waveFreq: { 1397, 0 }, 0, 0 },
+                      { duration: 125, waveFreq: { 784, 0 },  0, 0 },
+                      { duration: 0,   waveFreq: { 0 },       0, 0 } },
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_CALLDROP_LITE
+
+        { segments: { { duration: 500, waveFreq: { 425, 0 }, 0, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: 0,
+          repeatSegment: 0 },                           // TONE_CDMA_NETWORK_BUSY_ONE_SHOT
+        { segments: { { duration: 400, waveFreq: { 1150, 770 }, 0, 0 },
+                      { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: 0,
+          repeatSegment: 0 },                           // TONE_CDMA_ABBR_ALERT
+          { segments: { { duration: 0, waveFreq: { 0 }, 0, 0 }},
+          repeatCnt: 0,
+          repeatSegment: 0 },                            // TONE_CDMA_SIGNAL_OFF
+
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 350, 440, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_ANSI_DIAL
+        { segments: { { duration: 500, waveFreq: { 480, 620, 0 }, 0, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_ANSI_BUSY
+        { segments: { { duration: 250, waveFreq: { 480, 620, 0 }, 0, 0 },
+                      { duration: 250, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_ANSI_CONGESTION
+        { segments: { { duration: 300, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 9700, waveFreq: { 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 0 }, 0, 0 },
+                      { duration: 100, waveFreq: { 440, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 1 },                              // TONE_ANSI_CALL_WAITING
+        { segments: { { duration: 2000, waveFreq: { 440, 480, 0 }, 0, 0 },
+                      { duration: 4000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_ANSI_RINGTONE
+        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 400, 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_JAPAN_DIAL
+        { segments: { { duration: 500, waveFreq: { 400, 0 }, 0, 0 },
+                      { duration: 500, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_JAPAN_BUSY
+        { segments: { { duration: 1000, waveFreq: { 400, 0 }, 0, 0 },
+                      { duration: 2000, waveFreq: { 0 }, 0, 0 },
+                      { duration: 0 , waveFreq: { 0 }, 0, 0}},
+          repeatCnt: ToneGenerator::TONEGEN_INF,
+          repeatSegment: 0 },                              // TONE_JAPAN_RADIO_ACK
+
+
+
+};
+
+// Used by ToneGenerator::getToneForRegion() to convert user specified supervisory tone type
+// to actual tone for current region.
+const unsigned char ToneGenerator::sToneMappingTable[NUM_REGIONS-1][NUM_SUP_TONES] = {
+        {   // ANSI
+            TONE_ANSI_DIAL,             // TONE_SUP_DIAL
+            TONE_ANSI_BUSY,             // TONE_SUP_BUSY
+            TONE_ANSI_CONGESTION,       // TONE_SUP_CONGESTION
+            TONE_SUP_RADIO_ACK,         // TONE_SUP_RADIO_ACK
+            TONE_SUP_RADIO_NOTAVAIL,    // TONE_SUP_RADIO_NOTAVAIL
+            TONE_SUP_ERROR,             // TONE_SUP_ERROR
+            TONE_ANSI_CALL_WAITING,     // TONE_SUP_CALL_WAITING
+            TONE_ANSI_RINGTONE          // TONE_SUP_RINGTONE
+        },
+        {   // JAPAN
+            TONE_JAPAN_DIAL,             // TONE_SUP_DIAL
+            TONE_JAPAN_BUSY,             // TONE_SUP_BUSY
+            TONE_SUP_CONGESTION,         // TONE_SUP_CONGESTION
+            TONE_JAPAN_RADIO_ACK,        // TONE_SUP_RADIO_ACK
+            TONE_SUP_RADIO_NOTAVAIL,     // TONE_SUP_RADIO_NOTAVAIL
+            TONE_SUP_ERROR,              // TONE_SUP_ERROR
+            TONE_SUP_CALL_WAITING,       // TONE_SUP_CALL_WAITING
+            TONE_SUP_RINGTONE            // TONE_SUP_RINGTONE
+        }
+};
+
 
 ////////////////////////////////////////////////////////////////////////////////
 //                           ToneGenerator class Implementation
@@ -105,6 +817,17 @@
     // Generate tone by chunks of 20 ms to keep cadencing precision
     mProcessSize = (mSamplingRate * 20) / 1000;
 
+    char value[PROPERTY_VALUE_MAX];
+    property_get("gsm.operator.iso-country", value, "");
+    if (strcmp(value,"us") == 0 ||
+        strcmp(value,"ca") == 0) {
+        mRegion = ANSI;
+    } else if (strcmp(value,"jp") == 0) {
+        mRegion = JAPAN;
+    } else {
+        mRegion = CEPT;
+    }
+
     if (initAudioTrack()) {
         LOGV("ToneGenerator INIT OK, time: %d\n", (unsigned int)(systemTime()/1000000));
     } else {
@@ -155,7 +878,7 @@
 bool ToneGenerator::startTone(int toneType) {
     bool lResult = false;
 
-    if (toneType >= NUM_TONES)
+    if ((toneType < 0) || (toneType >= NUM_TONES))
         return lResult;
 
     if (mState == TONE_IDLE) {
@@ -170,7 +893,8 @@
     mLock.lock();
 
     // Get descriptor for requested tone
-    mpNewToneDesc = &toneDescriptors[toneType];
+    toneType = getToneForRegion(toneType);
+    mpNewToneDesc = &sToneDescriptors[toneType];
 
     if (mState == TONE_INIT) {
         if (prepareWave()) {
@@ -326,13 +1050,14 @@
 //
 ////////////////////////////////////////////////////////////////////////////////
 void ToneGenerator::audioCallback(int event, void* user, void *info) {
-    
+
     if (event != AudioTrack::EVENT_MORE_DATA) return;
-    
+
     const AudioTrack::Buffer *buffer = static_cast<const AudioTrack::Buffer *>(info);
     ToneGenerator *lpToneGen = static_cast<ToneGenerator *>(user);
     short *lpOut = buffer->i16;
     unsigned int lNumSmp = buffer->size/sizeof(short);
+    const ToneDescriptor *lpToneDesc = lpToneGen->mpToneDesc;
 
     if (buffer->size == 0) return;
 
@@ -345,12 +1070,12 @@
         unsigned int lGenSmp;
         unsigned int lWaveCmd = WaveGenerator::WAVEGEN_CONT;
         bool lSignal = false;
- 
+
         lpToneGen->mLock.lock();
 
         // Update pcm frame count and end time (current time at the end of this process)
         lpToneGen->mTotalSmp += lReqSmp;
-    
+
         // Update tone gen state machine and select wave gen command
         switch (lpToneGen->mState) {
         case TONE_PLAYING:
@@ -358,13 +1083,13 @@
             break;
         case TONE_STARTING:
             LOGV("Starting Cbk");
-    
+
             lWaveCmd = WaveGenerator::WAVEGEN_START;
             break;
         case TONE_STOPPING:
         case TONE_RESTARTING:
             LOGV("Stop/restart Cbk");
-    
+
             lWaveCmd = WaveGenerator::WAVEGEN_STOP;
             lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
             break;
@@ -374,89 +1099,127 @@
             lNumSmp = 0;
             goto audioCallback_EndLoop;
         }
-        
-    
+
+
         // Exit if tone sequence is over
-        if (lpToneGen->mpToneDesc->segments[lpToneGen->mCurSegment] == 0) {
+        if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
             if (lpToneGen->mState == TONE_PLAYING) {
-                lpToneGen->mState = TONE_STOPPING;            
+                lpToneGen->mState = TONE_STOPPING;
             }
             goto audioCallback_EndLoop;
         }
-    
+
         if (lpToneGen->mTotalSmp > lpToneGen->mNextSegSmp) {
             // Time to go to next sequence segment
-    
+
             LOGV("End Segment, time: %d\n", (unsigned int)(systemTime()/1000000));
-    
+
             lGenSmp = lReqSmp;
-    
-            if (lpToneGen->mCurSegment & 0x0001) {
-                // If odd segment,  OFF -> ON transition : reset wave generator
-                lWaveCmd = WaveGenerator::WAVEGEN_START;
-    
-                LOGV("OFF->ON, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
-            } else {
-                // If even segment,  ON -> OFF transition : ramp volume down
+
+            // If segment,  ON -> OFF transition : ramp volume down
+            if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
                 lWaveCmd = WaveGenerator::WAVEGEN_STOP;
-    
+                unsigned int lFreqIdx = 0;
+                unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
+
+                while (lFrequency != 0) {
+                    WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
+                    lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
+                    lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
+                }
                 LOGV("ON->OFF, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
             }
-    
-            // Pre increment segment index and handle loop if last segment reached
-            if (lpToneGen->mpToneDesc->segments[++lpToneGen->mCurSegment] == 0) {
+
+            // check if we need to loop and loop for the reqd times
+            if (lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
+                if (lpToneGen->mLoopCounter < lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt) {
+                    LOGV ("in if loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
+                          lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
+                          lpToneGen->mLoopCounter,
+                          lpToneGen->mCurSegment);
+                    lpToneGen->mCurSegment = lpToneDesc->segments[lpToneGen->mCurSegment].loopIndx;
+                    ++lpToneGen->mLoopCounter;
+                } else {
+                    // completed loop. go to next segment
+                    lpToneGen->mLoopCounter = 0;
+                    lpToneGen->mCurSegment++;
+                    LOGV ("in else loop loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
+                          lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
+                          lpToneGen->mLoopCounter,
+                          lpToneGen->mCurSegment);
+                }
+            } else {
+                lpToneGen->mCurSegment++;
+                LOGV ("Goto next seg loopCnt(%d) loopctr(%d), CurSeg(%d) \n",
+                      lpToneDesc->segments[lpToneGen->mCurSegment].loopCnt,
+                      lpToneGen->mLoopCounter,
+                      lpToneGen->mCurSegment);
+
+            }
+
+            // Handle loop if last segment reached
+            if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
                 LOGV("Last Seg: %d\n", lpToneGen->mCurSegment);
-    
+
                 // Pre increment loop count and restart if total count not reached. Stop sequence otherwise
-                if (++lpToneGen->mCurCount <= lpToneGen->mpToneDesc->repeatCnt) {
+                if (++lpToneGen->mCurCount <= lpToneDesc->repeatCnt) {
                     LOGV("Repeating Count: %d\n", lpToneGen->mCurCount);
-    
-                    lpToneGen->mCurSegment = 0;
-    
+
+                    lpToneGen->mCurSegment = lpToneDesc->repeatSegment;
+                    if (lpToneDesc->segments[lpToneDesc->repeatSegment].waveFreq[0] != 0) {
+                        lWaveCmd = WaveGenerator::WAVEGEN_START;
+                    }
+
                     LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
                             (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
-    
+
                 } else {
+                    lGenSmp = 0;
                     LOGV("End repeat, time: %d\n", (unsigned int)(systemTime()/1000000));
-    
-                    // Cancel OFF->ON transition in case previous segment tone state was OFF
-                    if (!(lpToneGen->mCurSegment & 0x0001)) {
-                        lGenSmp = 0;
-                    }
                 }
             } else {
                 LOGV("New segment %d, Next Time: %d\n", lpToneGen->mCurSegment,
                         (lpToneGen->mNextSegSmp*1000)/lpToneGen->mSamplingRate);
+                if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] != 0) {
+                    // If next segment is not silent,  OFF -> ON transition : reset wave generator
+                    lWaveCmd = WaveGenerator::WAVEGEN_START;
+
+                    LOGV("OFF->ON, lGenSmp: %d, lReqSmp: %d\n", lGenSmp, lReqSmp);
+                } else {
+                    lGenSmp = 0;
+                }
             }
-    
+
             // Update next segment transition position. No harm to do it also for last segment as lpToneGen->mNextSegSmp won't be used any more
             lpToneGen->mNextSegSmp
-                    += (lpToneGen->mpToneDesc->segments[lpToneGen->mCurSegment] * lpToneGen->mSamplingRate) / 1000;
-    
+                    += (lpToneDesc->segments[lpToneGen->mCurSegment].duration * lpToneGen->mSamplingRate) / 1000;
+
         } else {
             // Inside a segment keep tone ON or OFF
-            if (lpToneGen->mCurSegment & 0x0001) {
+            if (lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[0] == 0) {
                 lGenSmp = 0;  // If odd segment, tone is currently OFF
             } else {
                 lGenSmp = lReqSmp;  // If event segment, tone is currently ON
             }
         }
-    
+
         if (lGenSmp) {
             // If samples must be generated, call all active wave generators and acumulate waves in lpOut
-            unsigned int lWaveIdx;
-    
-            for (lWaveIdx = 0; lWaveIdx < (unsigned int)lpToneGen->mWaveGens.size(); lWaveIdx++) {
-                WaveGenerator *lpWaveGen = lpToneGen->mWaveGens[lWaveIdx];
+            unsigned int lFreqIdx = 0;
+            unsigned short lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[lFreqIdx];
+
+            while (lFrequency != 0) {
+                WaveGenerator *lpWaveGen = lpToneGen->mWaveGens.valueFor(lFrequency);
                 lpWaveGen->getSamples(lpOut, lGenSmp, lWaveCmd);
+                lFrequency = lpToneDesc->segments[lpToneGen->mCurSegment].waveFreq[++lFreqIdx];
             }
         }
-        
+
         lNumSmp -= lReqSmp;
         lpOut += lReqSmp;
-    
+
 audioCallback_EndLoop:
-    
+
         switch (lpToneGen->mState) {
         case TONE_RESTARTING:
             LOGV("Cbk restarting track\n");
@@ -476,7 +1239,7 @@
             LOGV("Cbk Stopping track\n");
             lSignal = true;
             lpToneGen->mpAudioTrack->stop();
-            
+
             // Force loop exit
             lNumSmp = 0;
             break;
@@ -501,7 +1264,7 @@
 //    Method:        ToneGenerator::prepareWave()
 //
 //    Description:    Prepare wave generators and reset tone sequencer state machine.
-//      mpNewToneDesc must have been initialized befoire calling this function.
+//      mpNewToneDesc must have been initialized before calling this function.
 //    Input:
 //        none
 //
@@ -510,40 +1273,49 @@
 //
 ////////////////////////////////////////////////////////////////////////////////
 bool ToneGenerator::prepareWave() {
-    unsigned int lCnt = 0;
-    unsigned int lNumWaves;
+    unsigned int segmentIdx = 0;
 
     if (!mpNewToneDesc) {
         return false;
     }
+
     // Remove existing wave generators if any
     clearWaveGens();
 
     mpToneDesc = mpNewToneDesc;
 
-    // Get total number of sine waves: needed to adapt sine wave gain.
-    lNumWaves = numWaves();
-
-    // Instantiate as many wave generators as listed in descriptor
-    while (lCnt < lNumWaves) {
-        ToneGenerator::WaveGenerator *lpWaveGen =
-                new ToneGenerator::WaveGenerator((unsigned short)mSamplingRate,
-                        mpToneDesc->waveFreq[lCnt],
-                        TONEGEN_GAIN/lNumWaves);
-        if (lpWaveGen == 0) {
-            goto prepareWave_exit;
+    while (mpToneDesc->segments[segmentIdx].duration) {
+        // Get total number of sine waves: needed to adapt sine wave gain.
+        unsigned int lNumWaves = numWaves(segmentIdx);
+        unsigned int freqIdx = 0;
+        unsigned int frequency = mpToneDesc->segments[segmentIdx].waveFreq[freqIdx];
+        while (frequency) {
+            // Instantiate a wave generator if  ot already done for this frequency
+            if (mWaveGens.indexOfKey(frequency) == NAME_NOT_FOUND) {
+                ToneGenerator::WaveGenerator *lpWaveGen =
+                        new ToneGenerator::WaveGenerator((unsigned short)mSamplingRate,
+                                frequency,
+                                TONEGEN_GAIN/lNumWaves);
+                if (lpWaveGen == 0) {
+                    goto prepareWave_exit;
+                }
+                mWaveGens.add(frequency, lpWaveGen);
+            }
+            frequency = mpNewToneDesc->segments[segmentIdx].waveFreq[++freqIdx];
         }
-
-        mWaveGens.push(lpWaveGen);
-        LOGV("Create sine: %d\n", mpToneDesc->waveFreq[lCnt]);
-        lCnt++;
+        segmentIdx++;
     }
 
     // Initialize tone sequencer
     mTotalSmp = 0;
     mCurSegment = 0;
     mCurCount = 0;
-    mNextSegSmp = (mpToneDesc->segments[0] * mSamplingRate) / 1000;
+    mLoopCounter = 0;
+    if (mpToneDesc->segments[0].duration == TONEGEN_INF) {
+        mNextSegSmp = TONEGEN_INF;
+    } else{
+        mNextSegSmp = (mpToneDesc->segments[0].duration * mSamplingRate) / 1000;
+    }
 
     return true;
 
@@ -559,19 +1331,22 @@
 //
 //    Method:        ToneGenerator::numWaves()
 //
-//    Description:    Count number of sine waves needed to generate tone (e.g 2 for DTMF).
+//    Description:    Count number of sine waves needed to generate a tone segment (e.g 2 for DTMF).
 //
 //    Input:
-//        none
+//        segmentIdx        tone segment index
 //
 //    Output:
 //        returned value:    nummber of sine waves
 //
 ////////////////////////////////////////////////////////////////////////////////
-unsigned int ToneGenerator::numWaves() {
+unsigned int ToneGenerator::numWaves(unsigned int segmentIdx) {
     unsigned int lCnt = 0;
 
-    while (mpToneDesc->waveFreq[lCnt]) {
+    if (mpToneDesc->segments[segmentIdx].duration) {
+        while (mpToneDesc->segments[segmentIdx].waveFreq[lCnt]) {
+            lCnt++;
+        }
         lCnt++;
     }
 
@@ -595,10 +1370,38 @@
 void ToneGenerator::clearWaveGens() {
     LOGV("Clearing mWaveGens:");
 
-    while (!mWaveGens.isEmpty()) {
-        delete mWaveGens.top();
-        mWaveGens.pop();
+    for (size_t lIdx = 0; lIdx < mWaveGens.size(); lIdx++) {
+        delete mWaveGens.valueAt(lIdx);
     }
+    mWaveGens.clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+//    Method:       ToneGenerator::getToneForRegion()
+//
+//    Description:  Get correct ringtone type according to current region.
+//      The corrected ring tone type is the tone descriptor index in sToneDescriptors[].
+//
+//    Input:
+//        none
+//
+//    Output:
+//        none
+//
+////////////////////////////////////////////////////////////////////////////////
+int ToneGenerator::getToneForRegion(int toneType) {
+    int regionTone;
+
+    if (mRegion == CEPT || toneType < FIRST_SUP_TONE || toneType > LAST_SUP_TONE) {
+        regionTone = toneType;
+    } else {
+        regionTone = sToneMappingTable[mRegion][toneType - FIRST_SUP_TONE];
+    }
+
+    LOGV("getToneForRegion, tone %d, region %d, regionTone %d", toneType, mRegion, regionTone);
+
+    return regionTone;
 }
 
 
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index 809316a..24e3e6f 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -503,7 +503,7 @@
     // TODO: In the future, we might be on the same thread if the app is
     // running in the same process as the media server. In that case,
     // this will deadlock.
-    // 
+    //
     // The threadId hack below works around this for the care of prepare
     // and seekTo within the same process.
     // FIXME: Remember, this is a hack, it's not even a hack that is applied
@@ -511,7 +511,7 @@
      if (mLockThreadId != getThreadId()) {
         mLock.lock();
         locked = true;
-    } 
+    }
 
     if (mPlayer == 0) {
         LOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2);
diff --git a/media/libmedia/mediarecorder.cpp b/media/libmedia/mediarecorder.cpp
index 6b26faf..5093f0e 100644
--- a/media/libmedia/mediarecorder.cpp
+++ b/media/libmedia/mediarecorder.cpp
@@ -180,7 +180,7 @@
         LOGE("setOutputFormat called in an invalid state: %d", mCurrentState);
         return INVALID_OPERATION;
     }
-    if (mIsVideoSourceSet && of >= OUTPUT_FORMAT_RAW_AMR) {
+    if (mIsVideoSourceSet && of >= OUTPUT_FORMAT_AUDIO_ONLY_START) { //first non-video output format
         LOGE("output format (%d) is meant for audio recording only and incompatible with video recording", of);
         return INVALID_OPERATION;
     }
@@ -345,7 +345,7 @@
     }
     if (!mIsVideoSourceSet) {
         LOGE("try to set video frame rate without setting video source first");
-        return INVALID_OPERATION; 
+        return INVALID_OPERATION;
     }
 
     status_t ret = mMediaRecorder->setVideoFrameRate(frames_per_second);
@@ -475,7 +475,7 @@
         mCurrentState = MEDIA_RECORDER_ERROR;
         return ret;
     }
- 
+
     // FIXME:
     // stop and reset are semantically different.
     // We treat them the same for now, and will change this in the future.
@@ -492,7 +492,7 @@
         LOGE("media recorder is not initialized yet");
         return INVALID_OPERATION;
     }
-    
+
     doCleanUp();
     status_t ret = UNKNOWN_ERROR;
     switch(mCurrentState) {
diff --git a/media/libmediaplayerservice/Android.mk b/media/libmediaplayerservice/Android.mk
index c45eb3d..99f222b 100644
--- a/media/libmediaplayerservice/Android.mk
+++ b/media/libmediaplayerservice/Android.mk
@@ -7,27 +7,25 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:=               \
-	MediaPlayerService.cpp \
-	MetadataRetrieverClient.cpp \
-	VorbisPlayer.cpp \
-	MidiFile.cpp
-
-ifneq ($(BUILD_WITHOUT_PV),true)
-LOCAL_SRC_FILES+=               \
-	MediaRecorderClient.cpp
-endif
+    MediaRecorderClient.cpp \
+    MediaPlayerService.cpp \
+    MetadataRetrieverClient.cpp \
+    VorbisPlayer.cpp \
+    MidiFile.cpp
 
 ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true)
 LOCAL_LDLIBS += -ldl -lpthread
 endif
 
 LOCAL_SHARED_LIBRARIES := \
-	libcutils \
-	libutils \
-	libvorbisidec \
-	libsonivox \
-	libmedia \
-	libandroid_runtime
+    libcutils \
+    libutils \
+    libvorbisidec \
+    libsonivox \
+    libopencore_player \
+    libopencore_author \
+    libmedia \
+    libandroid_runtime
 
 ifneq ($(BUILD_WITHOUT_PV),true)
 LOCAL_SHARED_LIBRARIES += \
@@ -36,7 +34,7 @@
 endif
 
 LOCAL_C_INCLUDES := external/tremor/Tremor \
-	$(call include-path-for, graphics corecg)
+    $(call include-path-for, graphics corecg)
 
 ifeq ($(BUILD_WITHOUT_PV),true)
 LOCAL_CFLAGS := -DNO_OPENCORE
diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp
index e0d2947..8bc410c 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.cpp
+++ b/media/libmediaplayerservice/MediaRecorderClient.cpp
@@ -37,6 +37,7 @@
 namespace android {
 
 const char* cameraPermission = "android.permission.CAMERA";
+const char* recordAudioPermission = "android.permission.RECORD_AUDIO";
 
 static bool checkPermission(const char* permissionString) {
 #ifndef HAVE_ANDROID_OS
@@ -86,6 +87,9 @@
 status_t MediaRecorderClient::setAudioSource(int as)
 {
     LOGV("setAudioSource(%d)", as);
+    if (!checkPermission(recordAudioPermission)) {
+        return PERMISSION_DENIED;
+    }
     Mutex::Autolock lock(mLock);
     if (mRecorder == NULL)  {
         LOGE("recorder is not initialized");
diff --git a/media/libmediaplayerservice/MidiFile.cpp b/media/libmediaplayerservice/MidiFile.cpp
index d03caa5..e9cbb97 100644
--- a/media/libmediaplayerservice/MidiFile.cpp
+++ b/media/libmediaplayerservice/MidiFile.cpp
@@ -89,7 +89,7 @@
     // create playback thread
     {
         Mutex::Autolock l(mMutex);
-        createThreadEtc(renderThread, this, "midithread");
+        createThreadEtc(renderThread, this, "midithread", ANDROID_PRIORITY_AUDIO);
         mCondition.wait(mMutex);
         LOGV("thread started");
     }
diff --git a/media/libmediaplayerservice/VorbisPlayer.cpp b/media/libmediaplayerservice/VorbisPlayer.cpp
index 0ad335f..7f0ef21 100644
--- a/media/libmediaplayerservice/VorbisPlayer.cpp
+++ b/media/libmediaplayerservice/VorbisPlayer.cpp
@@ -67,7 +67,7 @@
     LOGV("onFirstRef");
     // create playback thread
     Mutex::Autolock l(mMutex);
-    createThreadEtc(renderThread, this, "vorbis decoder");
+    createThreadEtc(renderThread, this, "vorbis decoder", ANDROID_PRIORITY_AUDIO);
     mCondition.wait(mMutex);
     if (mRenderTid > 0) {
         LOGV("render thread(%d) started", mRenderTid);
@@ -345,9 +345,6 @@
 {
     LOGV("reset\n");
     Mutex::Autolock l(mMutex);
-    if (mState != STATE_OPEN) {
-        return NO_ERROR;
-    }
     return reset_nosync();
 }
 
@@ -355,10 +352,13 @@
 status_t VorbisPlayer::reset_nosync()
 {
     // close file
-    ov_clear(&mVorbisFile); // this also closes the FILE
     if (mFile != NULL) {
-        LOGV("OOPS! Vorbis didn't close the file");
-        fclose(mFile);
+        ov_clear(&mVorbisFile); // this also closes the FILE
+        if (mFile != NULL) {
+            LOGV("OOPS! Vorbis didn't close the file");
+            fclose(mFile);
+            mFile = NULL;
+        }
     }
     mState = STATE_ERROR;