home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / mac / soundutl / vmtrs10s.hqx / VUMeters / Sources / MaxMonitor.s < prev    next >
Text File  |  1993-08-25  |  6KB  |  150 lines

  1. /*
  2.  *                  ARTA VUMeters for Macintosh
  3.  *                      Malcolm Slaney
  4.  *                 Advanced Technology Group
  5.  *                Apple Computer, Inc.
  6.  *                 malcolm@apple.com
  7.  *                     1992-1993
  8.  *
  9.  *    Warranty Information
  10.  *    Even though Apple has reviewed this software, Apple makes no warranty
  11.  *    or representation, either express or implied, with respect to this
  12.  *    software, its quality, accuracy, merchantability, or fitness for a 
  13.  *    particular purpose.  As a result, this software is provided "as is,"
  14.  *    and you, its user, are assuming the entire risk as to its quality
  15.  *    and accuracy.
  16.  *
  17.  *    Copyright (c) 1992-1993 by Apple Computer, Inc
  18.  *        All Rights Reserved.
  19.  */
  20.  
  21. /* MaxMonitor.s */
  22.  
  23. /*****************************************************************************/
  24. /*                                                                           */
  25. /*  Monitor the maximum sound level of the DSP.                              */
  26. /*                                                                           */
  27. /*****************************************************************************/
  28.  
  29. #include <DSP3210.h>
  30.  
  31. #define MonitorName Max
  32. #define NumSamples 240
  33.  
  34. NewModule(MonitorName, kdspSmoothModule, kdspAutoCache, max)
  35.  
  36.   long  (100<<16), 240, 1000                   // 10ms, 24Khz
  37.   long  (200<<16), 240, 1000                  // 5ms, 48Khz
  38.  
  39.   long  (12042240), 240, 1000                 // 5.44218ms, 44.1Khz
  40.   long  (6021120), 240, 1000                 // 10.88435ms, 22.05Khz
  41.  
  42. NewCachedProgramSection(max, MonitorName)
  43.  
  44.                                             /* sound AIAOs */
  45. NewScalableInputAIAOSection(Left, 1, kdsp3200Float, MonitorName)
  46. NewScalableInputAIAOSection(Right, 1, kdsp3200Float, MonitorName)
  47.  
  48. NewParameterSection(Params, kdsp3200Float, MonitorName)
  49.  
  50. #define DSPCOMPILE
  51. #include <SoundMonitor.h>
  52.  
  53. AppendSection (max)
  54.  
  55. _max:
  56.  
  57. /* Monitor left channel */
  58.   GetSectionLabel (r1, monitorLeft)           /* r1 = &monitorLeft */
  59.   r1 = *r1                                    /* r1 = monitorLeft */
  60.   nop
  61.   r1 - 0                                      /* monitor left channel? */
  62.   if (eq) pcgoto skip_monitor_left            /* no, then skip */
  63.                                         /* be careful what comes after branch */
  64.  
  65.                                         /* find max of current left frame */
  66.   r1 = (short) NumSamples - 1                 /* r1 = loop count */
  67.   GetSectionAddress (r2, Left)                /* r2 = Left AIAO */
  68.   r3 = PcLabel (zero)                         /* r3 = &0.0 */
  69.   a0 = *r3                                    /* a0 = 0.0 */
  70.   do r1
  71.   {
  72.     a1 = -*r2                                 /* a1 = -current sample */
  73.     a1 = ifalt (*r2++)                        /* a1 = abs (current sample) */
  74.     
  75.     a2 = a1 - a0                              /* compare current max with */
  76.                                               /* abs (current sample) */
  77.     a0 = ifagt (a1)                           /* a0 = max (a0, a1) */
  78.   }
  79.   GetSectionLabel (r1, fastLeftLevel)          /* r1 = &fastLeftLevel */
  80.   *r1 = a1 = ieee (a0)                          /* Store result */
  81.  
  82.   GetSectionLabel (r1, slowLeftLevel)         /* r1 = &slowLeftLevel */
  83.   a3 = dsp (*r1)                              /* a3 = slowLeftLevel */
  84.   GetSectionLabel (r2, decayRate)             /* r2 = &decayRate */
  85.   r3 = PcLabel (max_decay)                    /* r3 = &max_decay */
  86.   a2 = dsp (*r2)                              /* a2 = decayRate */
  87.   a1 = a3 - a0                                /* compare current max with */
  88.                                               /* last max */
  89.   a2 = ifalt (*r3)                            /* if max > last max decay at */
  90.                                               /* max_decay rate */
  91.   nop
  92.   nop
  93.   a0 = a0 + a2*a1                             /* y(n) = (1-e)x(n) + ey(n-1) */
  94.   nop                                          /*  Actually y(n)=x(n)+e[y(n-1)-x(n)] */
  95.   nop                                          /*  where e is set to 0 if y(n-1)-x(n)<0 */
  96.   *r1 = a0 = ieee (a0)
  97.  
  98. skip_monitor_left:
  99.  
  100. /* Monitor right channel */
  101.   GetSectionLabel (r1, monitorRight)          /* r1 = &monitorRight */
  102.   r1 = *r1                                    /* r1 = monitorRight */
  103.   nop
  104.   r1 - 0                                      /* monitor right channel? */
  105.   if (eq) pcgoto skip_monitor_right           /* no, then skip */
  106.   /* be careful what comes after branch */
  107.  
  108. /* find max of current right frame */
  109.   r1 = (short) NumSamples - 1                 /* r1 = loop count */
  110.   GetSectionAddress (r2, Right)               /* r2 = Right AIAO */
  111.   r3 = PcLabel (zero)                         /* r3 = &0.0 */
  112.   a0 = *r3                                    /* a0 = Right[0] */
  113.   do r1
  114.   {
  115.     a1 = -*r2                                 /* a1 = -current sample */
  116.     a1 = ifalt (*r2++)                        /* a1 = abs (current sample) */
  117.     
  118.     a2 = a1 - a0                              /* compare current max with */
  119.                                               /* abs (current sample) */
  120.     a0 = ifagt (a1)                           /* a0 = max (a0, a1) */
  121.   }
  122.   GetSectionLabel (r1, fastRightLevel)          /* r1 = &fastRightLevel */
  123.   *r1 = a1 = ieee (a0)                          /* Store result */
  124.  
  125.   GetSectionLabel (r1, slowRightLevel)        /* r1 = &slowRightLevel */
  126.   a3 = dsp (*r1)                              /* a3 = slowLeftLevel */
  127.   GetSectionLabel (r2, decayRate)             /* r2 = &decayRate */
  128.   r3 = PcLabel (max_decay)                    /* r3 = &max_decay */
  129.   a2 = dsp (*r2)                              /* a2 = decayRate */
  130.   a1 = a3 - a0                                /* compare current max with */
  131.                                               /* last max */
  132.   a2 = ifalt (*r3)                            /* if max < last max decay at */
  133.                                               /* max_decay rate*/
  134.   nop
  135.   nop
  136.   a0 = a0 + a2*a1                             /* y(n) = (1-e)x(n) + ey(n-1) */
  137.   nop                                          /*  Actually y(n)=x(n)+e[y(n-1)-x(n)] */
  138.   nop                                          /*  where e is set to 0 if y(n-1)-x(n)<0 */
  139.   *r1 = a0 = ieee (a0)
  140.  
  141. skip_monitor_right:
  142.  
  143.   return (RV)
  144.   nop
  145.  
  146. max_decay:  float  0.0
  147. zero:  float  0.0
  148.  
  149. /* MaxMonitor.s */
  150.