Dependencies:   mbed

Revision:
0:8e3468376286
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Distotion_Unit.cpp	Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,42 @@
+/*****************************************************/
+/*  Distotion_Unit.cpp                               */
+/*                                                   */
+/*****************************************************/
+
+#define     DIST_MAIN
+#include    "Distotion_Unit.h"
+
+#define  LIMIT_P        (32767)
+#define  LIMIT_N        (-32768)
+
+int distotion(int iEffectIn) {
+
+    int iSignal;
+
+    // Input Gain
+    iSignal = iEffectIn * g_inputGain;
+
+    // Clip
+    switch(g_distMode){
+        case 1: if (iSignal < 0)iSignal *= (-1);
+                if (iSignal >= g_clipLevel)iSignal = g_clipLevel;
+                break;
+        case 2: if (iSignal >= g_clipLevel)iSignal = g_clipLevel;
+                if (iSignal <= -g_clipLevel)iSignal = -g_clipLevel;
+                break;
+        case 3: if (iSignal >= g_clipLevel)iSignal = g_clipLevel;
+                if (iSignal <= (-g_clipLevel / 2))iSignal = (-g_clipLevel / 2);
+                break;
+        default:break;
+    }
+        
+    // Output Gain
+    iSignal *= g_outputGain;
+    if (iSignal >= LIMIT_P)iSignal = LIMIT_P;
+    if (iSignal <= LIMIT_N)iSignal = LIMIT_N;
+
+    return iSignal;
+
+}
+
+#undef      DIST_MAIN
\ No newline at end of file