~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to synti/stklib/RtWvIn.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************/
2
 
/*  RtWvIn Input Class,                    */
3
 
/*  by Gary P. Scavone, 1999-2000          */
4
 
/*                                         */
5
 
/*  This object inherits from WvIn and is  */
6
 
/*  used to read in realtime 16-bit data   */
7
 
/*  from a computer's audio port.          */
8
 
/*                                         */
9
 
/*  NOTE: This object is NOT intended for  */
10
 
/*  use in achieving simultaneous realtime */
11
 
/*  audio input/output (together with      */
12
 
/*  RtWvOut). Under certain circumstances  */
13
 
/*  such a scheme is possible, though you  */
14
 
/*  should definitely know what you are    */
15
 
/*  doing before trying.  For safer "full- */
16
 
/*  duplex" operation, use the RtDuplex    */
17
 
/*  class.                                 */
18
 
/*******************************************/
19
 
 
20
 
#include "RtWvIn.h"
21
 
 
22
 
RtWvIn :: RtWvIn(int chans, MY_FLOAT srate, int device)
23
 
{
24
 
  chunking = 1;
25
 
  looping = 0;
26
 
  sound_dev = new RtAudio(chans, srate, "record", device);
27
 
  channels = chans;
28
 
  bufferSize = RT_BUFFER_SIZE;
29
 
  data = 0;
30
 
  rtdata = (INT16 *) new INT16[(bufferSize+1)*channels];
31
 
 
32
 
  lastSamples = (INT16 *) new INT16[channels];
33
 
  for (int i=0;i<channels;i++) {
34
 
    lastSamples[i] = (INT16) 0.0;
35
 
  }
36
 
 
37
 
  this->getData(0);
38
 
 
39
 
  rate = (MY_FLOAT) srate / SRATE;
40
 
  if (fmod(rate, 1.0) > 0.0) interpolate = 1;
41
 
  else interpolate = 0;
42
 
  phaseOffset = (MY_FLOAT) 0.0;
43
 
  lastOutput = (MY_FLOAT *) new MY_FLOAT[channels];
44
 
  this->reset();
45
 
 
46
 
  gain = 0.00003052;
47
 
#if (defined(__STK_REALTIME_) && defined(__OS_IRIX_))
48
 
  // This is necessary under IRIX because it scales the input by 0.5
49
 
  // when using single-channel input.
50
 
  if (channels == 1) gain *= 2;
51
 
#endif
52
 
}
53
 
 
54
 
RtWvIn :: ~RtWvIn()
55
 
{
56
 
  delete sound_dev;
57
 
  if (rtdata) {
58
 
    delete [ ] rtdata;
59
 
    rtdata = 0;
60
 
  }
61
 
  if (lastSamples) {
62
 
    delete [ ] lastSamples;
63
 
    lastSamples = 0;
64
 
  }
65
 
}
66
 
 
67
 
void RtWvIn :: setRate(MY_FLOAT aRate)
68
 
{
69
 
  // Negative rates not allowed for realtime input
70
 
  rate = fabs(aRate);
71
 
 
72
 
  if (fmod(rate, 1.0) != 0.0) interpolate = 1;
73
 
  else interpolate = 0;
74
 
}
75
 
 
76
 
void RtWvIn :: addTime(MY_FLOAT aTime)   
77
 
{
78
 
  // Negative time shift no allowed for realtime input
79
 
  time += fabs(aTime);
80
 
}
81
 
 
82
 
void RtWvIn :: setLooping(int aLoopStatus)
83
 
{
84
 
  // No looping for realtime data.
85
 
  looping = 0;
86
 
}
87
 
 
88
 
long RtWvIn :: getSize()
89
 
{
90
 
  return bufferSize;
91
 
}
92
 
 
93
 
void RtWvIn :: getData(long index)
94
 
{
95
 
  static long temp = RT_BUFFER_SIZE*channels;
96
 
  sound_dev->recordBuffer(&rtdata[channels],temp);
97
 
 
98
 
  /* Fill in the extra sample frame for interpolation.
99
 
   * We do this by pre-pending the last sample frame
100
 
   * from the previous input buffer to the current one.
101
 
   */
102
 
  for (int i=0;i<channels;i++) {
103
 
    rtdata[i] = lastSamples[i];
104
 
    lastSamples[i] = rtdata[temp+i];
105
 
  }
106
 
}
107
 
 
108
 
int RtWvIn :: informTick()
109
 
{
110
 
  static MY_FLOAT alpha;
111
 
  static long index;
112
 
 
113
 
  if (time >= bufferSize) {
114
 
    this->getData(0);
115
 
    while (time >= bufferSize)
116
 
      time -= bufferSize;
117
 
  }
118
 
 
119
 
  // integer part of time address
120
 
  index = (long) time;
121
 
 
122
 
  if (interpolate) {
123
 
    // fractional part of time address
124
 
    alpha = time - (MY_FLOAT) index;
125
 
    index *= channels;
126
 
    for (int i=0;i<channels;i++) {
127
 
      //  Do linear interpolation
128
 
      lastOutput[i] = (MY_FLOAT) rtdata[index];
129
 
      lastOutput[i] += alpha * ((MY_FLOAT) rtdata[index+channels] - lastOutput[i]);
130
 
      lastOutput[i] *= gain;
131
 
      index++;
132
 
    }
133
 
  }
134
 
  else {
135
 
    index *= channels;
136
 
    for (int i=0;i<channels;i++) {
137
 
      lastOutput[i] = rtdata[index++];
138
 
      lastOutput[i] *= gain;
139
 
    }
140
 
  }
141
 
 
142
 
  // increment time, which can be negative
143
 
  time += rate;
144
 
 
145
 
  return finished;
146
 
}