am 621fbe1d: Merge "Remove unused fm and hybrid midi synths"

* commit '621fbe1ddeef9b13662f58aa7bf1e7dd29ce383c':
  Remove unused fm and hybrid midi synths
diff --git a/arm-wt-22k/lib_src/eas_math.h b/arm-wt-22k/lib_src/eas_math.h
index f240b51..1f9b96e 100644
--- a/arm-wt-22k/lib_src/eas_math.h
+++ b/arm-wt-22k/lib_src/eas_math.h
@@ -31,6 +31,7 @@
 #ifndef _EAS_MATH_H
 #define _EAS_MATH_H
 
+#include <stdint.h>
 
 /** coefs for pan, generates sin, cos */
 #define COEFF_PAN_G2    -27146      /* -0.82842712474619 = 2 - 4/sqrt(2) */
@@ -67,22 +68,22 @@
 /* Fixed point multiply 0.15 x 0.15 = 0.15 returned as 32-bits */
 #define FMUL_15x15(a,b) \
     /*lint -e(704) <avoid multiply for performance>*/ \
-    (((EAS_I32)(a) * (EAS_I32)(b)) >> 15)
+    (((int32_t)(a) * (int32_t)(b)) >> 15)
 
 /* Fixed point multiply 0.7 x 0.7 = 0.15 returned as 32-bits */
 #define FMUL_7x7(a,b) \
     /*lint -e(704) <avoid multiply for performance>*/ \
-    (((EAS_I32)(a) * (EAS_I32)(b) ) << 1)
+    (((int32_t)(a) * (int32_t)(b) ) << 1)
 
 /* Fixed point multiply 0.8 x 0.8 = 0.15 returned as 32-bits */
 #define FMUL_8x8(a,b) \
     /*lint -e(704) <avoid multiply for performance>*/ \
-    (((EAS_I32)(a) * (EAS_I32)(b) ) >> 1)
+    (((int32_t)(a) * (int32_t)(b) ) >> 1)
 
 /* Fixed point multiply 0.8 x 1.15 = 0.15 returned as 32-bits */
 #define FMUL_8x15(a,b) \
     /*lint -e(704) <avoid divide for performance>*/ \
-    (((EAS_I32)((a) << 7) * (EAS_I32)(b)) >> 15)
+    (((int32_t)((a) << 7) * (int32_t)(b)) >> 15)
 
 /* macros for fractional phase accumulator */
 /*
@@ -95,10 +96,10 @@
 #define NUM_PHASE_INT_BITS      1
 #define NUM_PHASE_FRAC_BITS     15
 
-#define PHASE_FRAC_MASK         (EAS_U32) ((0x1L << NUM_PHASE_FRAC_BITS) -1)
+#define PHASE_FRAC_MASK         (uint32_t) ((0x1L << NUM_PHASE_FRAC_BITS) -1)
 
-#define GET_PHASE_INT_PART(x)   (EAS_U32)((EAS_U32)(x) >> NUM_PHASE_FRAC_BITS)
-#define GET_PHASE_FRAC_PART(x)  (EAS_U32)((EAS_U32)(x) & PHASE_FRAC_MASK)
+#define GET_PHASE_INT_PART(x)   (uint32_t)((uint32_t)(x) >> NUM_PHASE_FRAC_BITS)
+#define GET_PHASE_FRAC_PART(x)  (uint32_t)((uint32_t)(x) & PHASE_FRAC_MASK)
 
 #define DEFAULT_PHASE_FRAC      0
 #define DEFAULT_PHASE_INT       0
@@ -114,7 +115,7 @@
 one (unity) is given by PHASE_ONE
 one half and one quarter are useful for 4-point linear interp.
 */
-#define PHASE_ONE               (EAS_I32) (0x1L << NUM_PHASE_FRAC_BITS)
+#define PHASE_ONE               (int32_t) (0x1L << NUM_PHASE_FRAC_BITS)
 
 /*
  Multiply the signed audio sample by the unsigned fraction.
@@ -123,9 +124,9 @@
     uses (n-1) or less bits, where n == hardware bit width)
 */
 #define MULT_AUDIO_COEF(audio,coef)         /*lint -e704 <avoid divide for performance>*/ \
-            (EAS_I32)(                                  \
+            (int32_t)(                                  \
             (                                           \
-                ((EAS_I32)(audio)) * ((EAS_I32)(coef))  \
+                ((int32_t)(audio)) * ((int32_t)(coef))  \
             )                                           \
             >> NUM_PHASE_FRAC_BITS                      \
                                         )               \
@@ -136,14 +137,14 @@
 #define NUM_WET_DRY_INT_BITS        9   // 1
 
 /* define a 1.0 */
-#define WET_DRY_ONE                 (EAS_I32) ((0x1L << NUM_WET_DRY_FRAC_BITS))
-#define WET_DRY_MINUS_ONE           (EAS_I32) (~WET_DRY_ONE)
-#define WET_DRY_FULL_SCALE          (EAS_I32) (WET_DRY_ONE - 1)
+#define WET_DRY_ONE                 (int32_t) ((0x1L << NUM_WET_DRY_FRAC_BITS))
+#define WET_DRY_MINUS_ONE           (int32_t) (~WET_DRY_ONE)
+#define WET_DRY_FULL_SCALE          (int32_t) (WET_DRY_ONE - 1)
 
 #define MULT_AUDIO_WET_DRY_COEF(audio,coef) /*lint -e(702) <avoid divide for performance>*/ \
-            (EAS_I32)(                                      \
+            (int32_t)(                                      \
             (                                               \
-                ((EAS_I32)(audio)) * ((EAS_I32)(coef))      \
+                ((int32_t)(audio)) * ((int32_t)(coef))      \
             )                                               \
             >> NUM_WET_DRY_FRAC_BITS                        \
                                                      )
@@ -155,14 +156,14 @@
 /* the max positive gain used in the synth for EG1 */
 /* SYNTH_FULL_SCALE_EG1_GAIN must match the value in the dls2eas
 converter, otherwise, the values we read from the .eas file are bogus. */
-#define SYNTH_FULL_SCALE_EG1_GAIN   (EAS_I32) ((0x1L << NUM_EG1_FRAC_BITS) -1)
+#define SYNTH_FULL_SCALE_EG1_GAIN   (int32_t) ((0x1L << NUM_EG1_FRAC_BITS) -1)
 
 /* define a 1.0 */
-#define EG1_ONE                     (EAS_I32) ((0x1L << NUM_EG1_FRAC_BITS))
-#define EG1_MINUS_ONE               (EAS_I32) (~SYNTH_FULL_SCALE_EG1_GAIN)
+#define EG1_ONE                     (int32_t) ((0x1L << NUM_EG1_FRAC_BITS))
+#define EG1_MINUS_ONE               (int32_t) (~SYNTH_FULL_SCALE_EG1_GAIN)
 
-#define EG1_HALF                    (EAS_I32) (EG1_ONE/2)
-#define EG1_MINUS_HALF              (EAS_I32) (EG1_MINUS_ONE/2)
+#define EG1_HALF                    (int32_t) (EG1_ONE/2)
+#define EG1_MINUS_HALF              (int32_t) (EG1_MINUS_ONE/2)
 
 /*
 We implement the EG1 using a linear gain value, which means that the
@@ -178,9 +179,9 @@
 the EG1
 */
 #define MULT_EG1_EG1(gain,damping)      /*lint -e(704) <avoid divide for performance>*/ \
-            (EAS_I32)(                                      \
+            (int32_t)(                                      \
             (                                               \
-                ((EAS_I32)(gain)) * ((EAS_I32)(damping))    \
+                ((int32_t)(gain)) * ((int32_t)(damping))    \
             )                                               \
             >> NUM_EG1_FRAC_BITS                            \
                                         )
@@ -197,16 +198,16 @@
 // we can instead shift the result right by one less, hence the
 // modified shift right value of (NUM_EG1_FRAC_BITS -1)
 #define MULT_EG1_EG1_X2(gain,damping)       /*lint -e(702) <avoid divide for performance>*/ \
-            (EAS_I32)(                                      \
+            (int32_t)(                                      \
             (                                               \
-                ((EAS_I32)(gain)) * ((EAS_I32)(damping))    \
+                ((int32_t)(gain)) * ((int32_t)(damping))    \
             )                                               \
             >> (NUM_EG1_FRAC_BITS -1)                       \
                                         )
 
 #define SATURATE_EG1(x)     /*lint -e{734} saturation operation */              \
-    ((EAS_I32)(x) > SYNTH_FULL_SCALE_EG1_GAIN)  ? (SYNTH_FULL_SCALE_EG1_GAIN) : \
-    ((EAS_I32)(x) < EG1_MINUS_ONE)              ? (EG1_MINUS_ONE) : (x);
+    ((int32_t)(x) > SYNTH_FULL_SCALE_EG1_GAIN)  ? (SYNTH_FULL_SCALE_EG1_GAIN) : \
+    ((int32_t)(x) < EG1_MINUS_ONE)              ? (EG1_MINUS_ONE) : (x);
 
 
 /* use "digital cents" == "dents" instead of cents */
@@ -220,17 +221,17 @@
 #define NUM_DENTS_FRAC_BITS     12
 #define NUM_DENTS_INT_BITS      (HARDWARE_BIT_WIDTH - NUM_DENTS_FRAC_BITS)
 
-#define DENTS_FRAC_MASK             (EAS_I32) ((0x1L << NUM_DENTS_FRAC_BITS) -1)
+#define DENTS_FRAC_MASK             (int32_t) ((0x1L << NUM_DENTS_FRAC_BITS) -1)
 
 #define GET_DENTS_INT_PART(x)       /*lint -e(704) <avoid divide for performance>*/ \
-                            (EAS_I32)((EAS_I32)(x) >> NUM_DENTS_FRAC_BITS)
+                            (int32_t)((int32_t)(x) >> NUM_DENTS_FRAC_BITS)
 
-#define GET_DENTS_FRAC_PART(x)  (EAS_I32)((EAS_I32)(x) & DENTS_FRAC_MASK)
+#define GET_DENTS_FRAC_PART(x)  (int32_t)((int32_t)(x) & DENTS_FRAC_MASK)
 
-#define DENTS_ONE               (EAS_I32) (0x1L << NUM_DENTS_FRAC_BITS)
+#define DENTS_ONE               (int32_t) (0x1L << NUM_DENTS_FRAC_BITS)
 
 /* use CENTS_TO_DENTS to convert a value in cents to dents */
-#define CENTS_TO_DENTS (EAS_I32) (DENTS_ONE * (0x1L << NUM_EG1_FRAC_BITS) / 1200L)                          \
+#define CENTS_TO_DENTS (int32_t) (DENTS_ONE * (0x1L << NUM_EG1_FRAC_BITS) / 1200L)                          \
 
 
 /*
@@ -270,20 +271,20 @@
                 20.0                                        \
     )
 
-#define LFO_GAIN_TO_CENTS   (EAS_I32)                       \
+#define LFO_GAIN_TO_CENTS   (int32_t)                       \
     (                                                       \
                 DOUBLE_LFO_GAIN_TO_CENTS *                  \
                 (0x1L << NUM_EG1_FRAC_BITS)                 \
     )
 #endif
 
-#define LFO_GAIN_TO_CENTS (EAS_I32) (1671981156L >> (23 - NUM_EG1_FRAC_BITS))
+#define LFO_GAIN_TO_CENTS (int32_t) (1671981156L >> (23 - NUM_EG1_FRAC_BITS))
 
 
 #define MULT_DENTS_COEF(dents,coef)     /*lint -e704 <avoid divide for performance>*/   \
-            (EAS_I32)(                                  \
+            (int32_t)(                                  \
             (                                           \
-                ((EAS_I32)(dents)) * ((EAS_I32)(coef))  \
+                ((int32_t)(dents)) * ((int32_t)(coef))  \
             )                                           \
             >> NUM_DENTS_FRAC_BITS                      \
                                         )               \
@@ -293,32 +294,32 @@
 #define BITS_PER_AUDIO_SAMPLE   16
 
 /* we define 1 as 1.0 - 1 LSbit */
-#define DISTORTION_ONE          (EAS_I32)((0x1L << (BITS_PER_AUDIO_SAMPLE-1)) -1)
-#define DISTORTION_MINUS_ONE    (EAS_I32)(~DISTORTION_ONE)
+#define DISTORTION_ONE          (int32_t)((0x1L << (BITS_PER_AUDIO_SAMPLE-1)) -1)
+#define DISTORTION_MINUS_ONE    (int32_t)(~DISTORTION_ONE)
 
 /* drive coef is given as int.frac */
 #define NUM_DRIVE_COEF_INT_BITS     1
 #define NUM_DRIVE_COEF_FRAC_BITS    4
 
 #define MULT_AUDIO_DRIVE(audio,drive)       /*lint -e(702) <avoid divide for performance>*/ \
-            (EAS_I32)   (                               \
+            (int32_t)   (                               \
             (                                           \
-                ((EAS_I32)(audio)) * ((EAS_I32)(drive)) \
+                ((int32_t)(audio)) * ((int32_t)(drive)) \
             )                                           \
             >> NUM_DRIVE_COEF_FRAC_BITS                 \
                                                 )
 
 #define MULT_AUDIO_AUDIO(audio1,audio2)         /*lint -e(702) <avoid divide for performance>*/ \
-            (EAS_I32)   (                                   \
+            (int32_t)   (                                   \
             (                                               \
-                ((EAS_I32)(audio1)) * ((EAS_I32)(audio2))   \
+                ((int32_t)(audio1)) * ((int32_t)(audio2))   \
             )                                               \
             >> (BITS_PER_AUDIO_SAMPLE-1)                    \
                                                     )
 
 #define SATURATE(x)                                                         \
-    ((((EAS_I32)(x)) > DISTORTION_ONE)      ? (DISTORTION_ONE) :            \
-    (((EAS_I32)(x)) < DISTORTION_MINUS_ONE) ? (DISTORTION_MINUS_ONE) :  ((EAS_I32)(x)));
+    ((((int32_t)(x)) > DISTORTION_ONE)      ? (DISTORTION_ONE) :            \
+    (((int32_t)(x)) < DISTORTION_MINUS_ONE) ? (DISTORTION_MINUS_ONE) :  ((int32_t)(x)));
 
 
 
diff --git a/arm-wt-22k/lib_src/eas_mdls.c b/arm-wt-22k/lib_src/eas_mdls.c
index e8dc463..b08e24e 100644
--- a/arm-wt-22k/lib_src/eas_mdls.c
+++ b/arm-wt-22k/lib_src/eas_mdls.c
@@ -139,6 +139,14 @@
 #define DLS_MAX_INST_COUNT      256
 #define MAX_DLS_WAVE_SIZE       (1024*1024)
 
+#ifndef EAS_U32_MAX
+#define EAS_U32_MAX             (4294967295U)
+#endif
+
+#ifndef EAS_I32_MAX
+#define EAS_I32_MAX             (2147483647)
+#endif
+
 /*------------------------------------
  * typedefs
  *------------------------------------
@@ -408,7 +416,7 @@
 static EAS_RESULT Parse_wave (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U16 waveIndex);
 static EAS_RESULT Parse_wsmp (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p);
 static EAS_RESULT Parse_fmt (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p);
-static EAS_RESULT Parse_data (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_WSMP_DATA *p, EAS_SAMPLE *pSample);
+static EAS_RESULT Parse_data (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_WSMP_DATA *p, EAS_SAMPLE *pSample, EAS_U32 sampleLen);
 static EAS_RESULT Parse_lins(SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size);
 static EAS_RESULT Parse_ins (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size);
 static EAS_RESULT Parse_insh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pRgnCount, EAS_U32 *pLocale);
@@ -938,7 +946,7 @@
     }
 
     // limit to reasonable size
-    if (dataSize > MAX_DLS_WAVE_SIZE)
+    if (dataSize < 0 || dataSize > MAX_DLS_WAVE_SIZE)
     {
         return EAS_ERROR_SOUND_LIBRARY;
     }
@@ -1023,7 +1031,7 @@
     }
 
     /* allocate memory and read in the sample data */
-    pSample = pDLSData->pDLS->pDLSSamples + pDLSData->wavePoolOffset;
+    pSample = (EAS_U8*)pDLSData->pDLS->pDLSSamples + pDLSData->wavePoolOffset;
     pDLSData->pDLS->pDLSSampleOffsets[waveIndex] = pDLSData->wavePoolOffset;
     pDLSData->pDLS->pDLSSampleLen[waveIndex] = (EAS_U32) size;
     pDLSData->wavePoolOffset += (EAS_U32) size;
@@ -1033,7 +1041,7 @@
         return EAS_ERROR_SOUND_LIBRARY;
     }
 
-    if ((result = Parse_data(pDLSData, dataPos, dataSize, p, pSample)) != EAS_SUCCESS)
+    if ((result = Parse_data(pDLSData, dataPos, dataSize, p, pSample, (EAS_U32)size)) != EAS_SUCCESS)
         return result;
 
     return EAS_SUCCESS;
@@ -1126,6 +1134,14 @@
         /* get loop length */
         if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &p->loopLength, EAS_FALSE)) != EAS_SUCCESS)
             return result;
+
+        /* ensure no overflow */
+        if (p->loopLength
+            && ((p->loopStart > EAS_U32_MAX - p->loopLength)
+                || (p->loopStart + p->loopLength > EAS_U32_MAX / sizeof(EAS_SAMPLE))))
+        {
+            return EAS_FAILURE;
+        }
     }
 
     return EAS_SUCCESS;
@@ -1217,7 +1233,7 @@
  *
  *----------------------------------------------------------------------------
 */
-static EAS_RESULT Parse_data (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_WSMP_DATA *pWsmp, EAS_SAMPLE *pSample)
+static EAS_RESULT Parse_data (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_WSMP_DATA *pWsmp, EAS_SAMPLE *pSample, EAS_U32 sampleLen)
 {
     EAS_RESULT result;
     EAS_U8 convBuf[SAMPLE_CONVERT_CHUNK_SIZE];
@@ -1272,7 +1288,15 @@
 
     /* for looped samples, copy the last sample to the end */
     if (pWsmp->loopLength)
+    {
+        if (sampleLen < sizeof(EAS_SAMPLE)
+            || (pWsmp->loopStart + pWsmp->loopLength) * sizeof(EAS_SAMPLE) > sampleLen - sizeof(EAS_SAMPLE))
+        {
+            return EAS_FAILURE;
+        }
+
         pSample[pWsmp->loopStart + pWsmp->loopLength] = pSample[pWsmp->loopStart];
+    }
 
     return EAS_SUCCESS;
 }
@@ -1676,6 +1700,10 @@
     /* parse wlnk chunk */
     if ((result = Parse_wlnk(pDLSData, wlnkPos, &waveIndex)) != EAS_SUCCESS)
         return result;
+    if (waveIndex >= pDLSData->waveCount)
+    {
+        return EAS_FAILURE;
+    }
     pWsmp = &pDLSData->wsmpData[waveIndex];
 
     /* if there is any articulation data, parse it */
@@ -1718,6 +1746,17 @@
         }
 
         Convert_rgn(pDLSData, regionIndex, artIndex, (EAS_U16) waveIndex, pWsmp);
+
+        /* ensure loopStart and loopEnd fall in the range */
+        if (pWsmp->loopLength != 0)
+        {
+            EAS_U32 sampleLen = pDLSData->pDLS->pDLSSampleLen[waveIndex];
+            if (sampleLen < sizeof(EAS_SAMPLE)
+                || (pWsmp->loopStart + pWsmp->loopLength) * sizeof(EAS_SAMPLE) > sampleLen - sizeof(EAS_SAMPLE))
+            {
+                return EAS_FAILURE;
+            }
+        }
     }
 
     /* if local articulation, bump count */
diff --git a/arm-wt-22k/lib_src/jet.c b/arm-wt-22k/lib_src/jet.c
index 97672cf..2f1541f 100644
--- a/arm-wt-22k/lib_src/jet.c
+++ b/arm-wt-22k/lib_src/jet.c
@@ -282,10 +282,16 @@
         switch (infoType)
         {
             case INFO_NUM_SMF_CHUNKS:
+                if (temp >= JET_MAX_SEGMENTS) {
+                    return EAS_ERROR_INCOMPATIBLE_VERSION;
+                }
                 easHandle->jetHandle->numSegments = (EAS_U8) temp;
                 break;
 
             case INFO_NUM_DLS_CHUNKS:
+                if (temp >= JET_MAX_DLS_COLLECTIONS) {
+                    return EAS_ERROR_INCOMPATIBLE_VERSION;
+                }
                 easHandle->jetHandle->numLibraries = (EAS_U8) temp;
                 break;