~ubuntu-branches/ubuntu/natty/ecasound2.2/natty

« back to all changes in this revision

Viewing changes to libecasound/audiogate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2008-09-26 09:58:52 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080926095852-k3v9ewhmxpaltusw
Tags: 2.5.2-3
yodl 2.13.1 removed --unique-output option. Remove --unique-output
accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// ------------------------------------------------------------------------
2
2
// audiogate.cpp: Signal gates.
3
 
// Copyright (C) 1999-2002,2005-2007 Kai Vehmanen
 
3
// Copyright (C) 1999-2002,2005-2008 Kai Vehmanen
 
4
// Copyrtigh (C) 2008 Andrew Lees
4
5
//
5
6
// Attributes:
6
7
//     eca-style-version: 3
41
42
 
42
43
void GATE_BASE::init(SAMPLE_BUFFER* sbuf)
43
44
 
45
  gate_open = false;
44
46
  target = sbuf;
45
47
}
46
48
 
71
73
  durtime_rep = duration;
72
74
  position_in_samples_rep = 0;
73
75
  
74
 
  ECA_LOG_MSG(ECA_LOGGER::info, "(audiogate) Time crop gate created; opens at " +
 
76
  ECA_LOG_MSG(ECA_LOGGER::info, "Time crop gate created; opens at " +
75
77
              kvu_numtostr(begtime_rep) + " seconds and stays open for " +
76
78
              kvu_numtostr(durtime_rep) + " seconds.\n");
77
79
}
117
119
  openlevel_rep = threshold_openlevel / 100.0;
118
120
  closelevel_rep = threshold_closelevel / 100.0;
119
121
  rms_rep = use_rms;
 
122
  reopen_count_param_rep = 0;
120
123
 
121
124
  is_opened_rep = is_closed_rep = false;
122
125
 
123
126
  if (rms_rep) {
124
 
    ECA_LOG_MSG(ECA_LOGGER::info, "(audiogate) Threshold gate created; open threshold " +
 
127
    ECA_LOG_MSG(ECA_LOGGER::info, "Threshold gate created; open threshold " +
125
128
                kvu_numtostr(openlevel_rep * 100) + "%, close threshold " +
126
129
                kvu_numtostr(closelevel_rep * 100) + "%, using RMS volume.");
127
130
  }
128
131
  else {
129
 
    ECA_LOG_MSG(ECA_LOGGER::info, "(audiogate) Threshold gate created; open threshold " +
 
132
    ECA_LOG_MSG(ECA_LOGGER::info, "Threshold gate created; open threshold " +
130
133
                kvu_numtostr(openlevel_rep * 100) + "%, close threshold " +
131
134
                kvu_numtostr(closelevel_rep * 100) + "%, using peak volume.");
132
135
  }
133
136
}
134
137
 
 
138
void THRESHOLD_GATE::init(SAMPLE_BUFFER* sbuf)
 
139
{
 
140
  reopens_left_rep = reopen_count_param_rep;
 
141
  is_opened_rep = false;
 
142
  is_closed_rep = false;
 
143
  GATE_BASE::init(sbuf);
 
144
}
 
145
 
135
146
void THRESHOLD_GATE::analyze(SAMPLE_BUFFER* sbuf)
136
147
{
137
148
  if (rms_rep == true)
142
153
  if (is_opened_rep == false) {
143
154
    if (avolume_rep > openlevel_rep) { 
144
155
      open_gate();
145
 
      ECA_LOG_MSG(ECA_LOGGER::user_objects, "Threshold gate opened.");
 
156
      ECA_LOG_MSG(ECA_LOGGER::user_objects, "Threshold gate opened (reopen count = " + kvu_numtostr(reopens_left_rep) + ")");
146
157
      is_opened_rep = true;
 
158
      is_closed_rep = false;
147
159
    }
148
160
  }
149
161
  else if (is_closed_rep == false) {
150
162
    if (avolume_rep < closelevel_rep) { 
151
163
      close_gate();
152
 
      ECA_LOG_MSG(ECA_LOGGER::user_objects, "Threshold gate closed.");
 
164
      ECA_LOG_MSG(ECA_LOGGER::user_objects, "Threshold gate closed (reopens left = " + kvu_numtostr(reopens_left_rep) + ")");
153
165
      is_closed_rep = true;
 
166
      if (reopens_left_rep != 0) {
 
167
        is_opened_rep = false;
 
168
        if (reopens_left_rep > 0)
 
169
          --reopens_left_rep;
 
170
      } else {
 
171
        // - Could we stop the engine and exit here, maybe? -AL/2008-Jul
 
172
        // - Not from a chain operator, but the audio object
 
173
        //   that writes the stream to a file could in
 
174
        //   theory react in a special way to the 0-length 
 
175
        //   samplebuffers we generate when the gate is closed... -KV/2008-Jul
 
176
      }
154
177
    }
155
178
  }
156
179
}
167
190
      return 1.0;
168
191
    else 
169
192
      return 0.0;
 
193
  case 4:
 
194
    return reopen_count_param_rep;
170
195
  }
171
196
  return 0.0;
172
197
}
181
206
    closelevel_rep = value / 100.0;
182
207
    break;
183
208
  case 3: 
184
 
    if (value != 0) 
185
 
      rms_rep = true;
186
 
    else 
187
 
      rms_rep = false;
 
209
    rms_rep = (value != 0);
 
210
    break;
 
211
  case 4:
 
212
    reopen_count_param_rep = static_cast<int>(value);
188
213
    break;
189
214
  }
190
215
}