home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / mac / soundutl / vmtrs10s.hqx / VUMeters / Sources / PowerMonitor.s < prev    next >
Text File  |  1993-08-25  |  6KB  |  166 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. /* PowerMonitor.s */
  22.  
  23. /*****************************************************************************/
  24. /*                                                                           */
  25. /* monitor the sound power level of the DSP                                  */
  26. /*                                                                           */
  27. /*****************************************************************************/
  28.  
  29. #include <DSP3210.h>
  30.  
  31. #define MonitorName Power
  32. #define NumSamples 240
  33.  
  34. NewModule(MonitorName, kdspSmoothModule, kdspAutoCache, power)
  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(power, MonitorName)
  43.  
  44.                                             /* sound AIAOs */
  45. NewScalableInputAIAOSection(Left, 1, kdsp3200Float, MonitorName)
  46. NewScalableInputAIAOSection(Right, 1, kdsp3200Float, MonitorName)
  47.  
  48.  
  49. NewParameterSection(Params, kdsp3200Float, MonitorName)
  50.  
  51. #define DSPCOMPILE
  52. #include <SoundMonitor.h>
  53.  
  54. AppendSection (power)
  55.  
  56. _power:
  57.  
  58.   GetSectionLabel(r3,frameScale)             /* r3 = &(1 / NumSamples) */
  59.   nop
  60.   nop
  61.   a0 = dsp(*r3)
  62.   nop
  63.   nop
  64.   r3 = PcLabel(d1_NumSamples)
  65.   *r3 = a0 = a0
  66.  
  67. /* Monitor left channel */
  68.   GetSectionLabel (r1, monitorLeft)        /* r1 = &monitorLeft */
  69.   r1 = *r1                                   /* r1 = monitorLeft */
  70.   nop
  71.   r1 - 0                                     /* monitor left channel? */
  72.   if (eq) pcgoto skip_monitor_left           /* no, then skip */
  73.   r3 = PcLabel(d1_NumSamples)             /* r3 = &(1 / NumSamples) */
  74.  
  75.   GetSectionAddress (r2, Left)               /* r2 = Left AIAO */
  76.   a1 = *r2 * *r2                             /* start unscaled total power */
  77.   a0 = *r3 * *r2++                           /* start scaled dc level */
  78.   r1 = (short) NumSamples - 2                /* r1 = loop count */
  79.   do r1
  80.   {
  81.     a1 = a1 + *r2 * *r2                      /* unscaled total power */
  82.     a0 = a0 + *r3 * *r2++                    /* scaled dc level */
  83.   }
  84.   GetSectionLabel (r1, fastLeftLevel)        /* r1 = &fastLeftLevel */
  85.   a1 = *r3 * a1                              /* scale total power */
  86.   a0 = a1 - a0*a0                            /* fastLeftLevel = total power - */
  87.                                              /*             dc power */
  88.   nop
  89.   nop
  90.   *r1 = a1 = ieee (a0)
  91.  
  92.   GetSectionLabel (r1, slowLeftLevel)         /* r1 = &slowLeftLevel */
  93.   a3 = dsp (*r1)                              /* a3 = old slowLeftLevel */
  94.   GetSectionLabel (r2, decayRate)             /* r2 = &decayRate */
  95.   r3 = PcLabel (max_decay)                    /* r3 = &max_decay */
  96.   a2 = dsp (*r2)                              /* a2 = decayRate */
  97.   a1 = a3 - a0                                /* compare current max with */
  98.                                               /* last max */
  99.   nop
  100.   nop
  101.   nop
  102.   nop
  103.   a2 = ifalt (*r3)                            /* if max > last max decay at */
  104.                                               /* max_decay rate */
  105.   nop
  106.   nop
  107.   a0 = a0 + a2*a1                             /* y(n) = (1-e)x(n) + ey(n-1) */
  108.   nop                                          /*  Actually y(n)=x(n)+e[y(n-1)-x(n)] */
  109.   nop                                          /*  where e is set to 0 if y(n-1)-x(n)<0 */
  110.   *r1 = a0 = ieee (a0)
  111.  
  112. skip_monitor_left:
  113.  
  114. /* Monitor right channel */
  115.   GetSectionLabel (r1, monitorRight)         /* r1 = &monitorRight */
  116.   r1 = *r1                                   /* r1 = monitorRight */
  117.   nop
  118.   r1 - 0                                     /* monitor right channel? */
  119.   if (eq) pcgoto skip_monitor_right          /* no, then skip */
  120.   r3 = PcLabel(d1_NumSamples)             /* r3 = &(1 / NumSamples) */
  121.  
  122.   GetSectionAddress (r2, Right)              /* r2 = Right AIAO */
  123.   a1 = *r2 * *r2                             /* start unscaled total power */
  124.   a0 = *r3 * *r2++                           /* start scaled dc level */
  125.   r1 = (short) NumSamples - 2                /* r1 = loop count */
  126.   do r1
  127.   {
  128.     a1 = a1 + *r2 * *r2                      /* unscaled total power */
  129.     a0 = a0 + *r3 * *r2++                    /* scaled dc level */
  130.   }
  131.   GetSectionLabel (r1, fastRightLevel)       /* r1 = &fastRightLevel */
  132.   a1 = *r3 * a1                              /* scale total power */
  133.   a0 = a1 - a0*a0                            /* fastRightLevel = total power - */
  134.   nop
  135.   nop
  136.   *r1 = a1 = ieee (a0)
  137.                                              /*              dc power */
  138.   GetSectionLabel (r1, slowRightLevel)        /* r1 = &slowRightLevel */
  139.   a3 = dsp (*r1)                              /* a3 = old slowRightLevel */
  140.   GetSectionLabel (r2, decayRate)             /* r2 = &decayRate */
  141.   r3 = PcLabel (max_decay)                    /* r3 = &max_decay */
  142.   a2 = dsp (*r2)                              /* a2 = decayRate */
  143.   a1 = a3 - a0                                /* compare current max with */
  144.                                               /* last max */
  145.   nop
  146.   nop
  147.   nop
  148.   nop
  149.   a2 = ifalt (*r3)                            /* if max < last max decay at */
  150.                                               /* max_decay rate*/
  151.   nop
  152.   nop
  153.   a0 = a0 + a2*a1                             /* y(n) = (1-e)x(n) + ey(n-1) */
  154.   nop                                          /*  Actually y(n)=x(n)+e[y(n-1)-x(n)] */
  155.   nop                                          /*  where e is set to 0 if y(n-1)-x(n)<0 */
  156.   *r1 = a1 = ieee (a0)
  157.  
  158. skip_monitor_right:
  159.  
  160.   return (RV)
  161.   nop
  162.  
  163. d1_NumSamples: float 0.00416666              /* 1 / NumSamples */
  164. max_decay:        float 0.0
  165. /* PowerMonitor.s */
  166.