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

« back to all changes in this revision

Viewing changes to libecasound/audiogate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2008-03-23 21:42:49 UTC
  • mfrom: (3.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080323214249-evlfv3y1o8q747la
Tags: 2.4.6.1-2
* Bug fix: "FTBFS with GCC 4.3: missing #includes", thanks to Martin
  Michlmayr (Closes: #454890).
- 13_gcc4: updated

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-2006 Kai Vehmanen
 
3
// Copyright (C) 1999-2002,2005-2007 Kai Vehmanen
4
4
//
5
5
// Attributes:
6
6
//     eca-style-version: 3
47
47
void TIME_CROP_GATE::analyze(SAMPLE_BUFFER* sbuf)
48
48
{
49
49
  parameter_t etime = begtime_rep + durtime_rep;
50
 
  if (curtime_rep >= begtime_rep) {
 
50
  parameter_t curtime = static_cast<parameter_t>(position_in_samples_rep) / samples_per_second();
 
51
 
 
52
  if (curtime >= begtime_rep) {
 
53
    /* note: handle the special case where a zero open time
 
54
     *       has been requested */
51
55
    if (begtime_rep == etime) 
52
56
      open_gate();
53
 
    else if (curtime_rep < etime) 
 
57
    else if (curtime < etime)
54
58
      open_gate();
55
 
    else 
 
59
    else
56
60
      close_gate();
57
61
  }
58
 
  else 
 
62
  else
59
63
    close_gate();
60
64
 
61
 
  curtime_rep += static_cast<double>(sbuf->length_in_samples()) / samples_per_second();
 
65
  position_in_samples_rep += sbuf->length_in_samples();
62
66
}
63
67
 
64
68
TIME_CROP_GATE::TIME_CROP_GATE (CHAIN_OPERATOR::parameter_t open_at, CHAIN_OPERATOR::parameter_t duration)
65
69
{
66
70
  begtime_rep = open_at;
67
71
  durtime_rep = duration;
68
 
  curtime_rep = 0.0;
 
72
  position_in_samples_rep = 0;
69
73
  
70
74
  ECA_LOG_MSG(ECA_LOGGER::info, "(audiogate) Time crop gate created; opens at " +
71
75
              kvu_numtostr(begtime_rep) + " seconds and stays open for " +
88
92
  switch (param) {
89
93
  case 1: 
90
94
    begtime_rep = value;
91
 
    curtime_rep = 0.0;
 
95
    position_in_samples_rep = 0;
92
96
    break;
93
97
  case 2: 
94
98
    durtime_rep = value;
96
100
  }
97
101
}
98
102
 
 
103
void TIME_CROP_GATE::set_samples_per_second(SAMPLE_SPECS::sample_rate_t new_value)
 
104
{
 
105
  double ratio (new_value);
 
106
  ratio /= samples_per_second();
 
107
  /* note: as we store position as samples, changes in sampling rate
 
108
   *       require recalculation of position */
 
109
  position_in_samples_rep = static_cast<SAMPLE_SPECS::sample_pos_t>(position_in_samples_rep * ratio);
 
110
  ECA_SAMPLERATE_AWARE::set_samples_per_second(new_value);
 
111
}
 
112
 
99
113
THRESHOLD_GATE::THRESHOLD_GATE (CHAIN_OPERATOR::parameter_t threshold_openlevel, 
100
114
                                CHAIN_OPERATOR::parameter_t threshold_closelevel,
101
115
                                bool use_rms)