File: Compressor.cpp

package info (click to toggle)
audacity 0.98-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,896 kB
  • ctags: 4,089
  • sloc: cpp: 26,099; ansic: 4,961; sh: 2,465; makefile: 156; perl: 23
file content (74 lines) | stat: -rw-r--r-- 1,842 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**********************************************************************

  Audacity: A Digital Audio Editor

  FilterFade.cpp

  Dominic Mazzoni

**********************************************************************/

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "Filter.h"
#include "FilterCompressor.h"

bool FilterCompressor::Prepare(WaveTrack * t, double t0, double t1,
                               sampleCount total)
{
   wxString temp;
   wxWindow *parent = NULL;

   temp =
       wxGetTextFromUser
       ("Please enter an increment (in milliseconds) to apply the filter to",
        "Increment: ", "1", parent, -1, -1, TRUE);

   if (temp == "")
      return false;

   while (sscanf((const char *) temp, "%d", &increment) < 0) {
      temp = wxGetTextFromUser("Please enter a value greater than zero:",
                               "Increment: ", "1", parent, -1, -1, TRUE);
      if (temp == "")
         return false;
   }

   how_far = 0;

   increment *= t->rate / 100;

   return true;
}

void FilterCompressor::DoIt(sampleType * src, sampleType * dst,
                            sampleCount total, sampleCount x,
                            sampleCount len)
{
   for (int i = 0; i < len; i++) {
      if (how_far == 2 * increment)
         how_far = 0;
      if (how_far == 0) {
         for (int i2 = i; i2 < len && i2 <= increment; i2++) {
            if (i2 == i)
               max_region = src[i];
            else if (src[i2] > max_region)
               max_region = src[i2];
         }
      } else if (how_far <= increment) {
         dst[i] = (sampleType) (src[i] * 32767 / max_region);
      } else
         dst[i] = (sampleType) (src[i]);
      ++how_far;
   }
}
}