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

« back to all changes in this revision

Viewing changes to synti/stklib/RtDuplex.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
 
/*  Real-Time Duplex Input/Output Class,   */
3
 
/*  by Gary P. Scavone, 1999-2000          */
4
 
/*                                         */
5
 
/*  This object opens the sound i/o        */
6
 
/*  device, reads buffers in from it, and  */
7
 
/*  pokes buffers of samples out to it.    */
8
 
/*                                         */
9
 
/*  At the moment, duplex mode is possible */
10
 
/*  only on Linux (OSS), IRIX, and         */
11
 
/*  Windows95/98 platforms.                */
12
 
/*******************************************/
13
 
 
14
 
#include "RtDuplex.h"
15
 
 
16
 
#if (defined(__STK_REALTIME_) )
17
 
 
18
 
RtDuplex :: RtDuplex(int chans, MY_FLOAT srate, int device)
19
 
{
20
 
  // We'll let RTSoundIO deal with channel and srate limitations.
21
 
  channels = chans;
22
 
  sound_dev = new RtAudio(channels, srate, "duplex", device);
23
 
  writeCounter = 0;
24
 
  gain = 0.00003052;
25
 
  data_length = RT_BUFFER_SIZE*channels;
26
 
  indata = (INT16 *) new INT16[data_length+10];
27
 
  outdata = (INT16 *) new INT16[data_length+10];
28
 
  insamples = new MY_FLOAT[channels];
29
 
#if (defined(__STK_REALTIME_) && defined(__OS_IRIX_))
30
 
  // This is necessary under IRIX because it scales the input by 0.5
31
 
  // when using single-channel input.
32
 
  if (channels == 1) gain *= 2;
33
 
#endif
34
 
  // Read half a buffer to get started
35
 
  readCounter = data_length / 2;
36
 
  sound_dev->recordBuffer(&indata[readCounter],(data_length/2));
37
 
}
38
 
 
39
 
RtDuplex :: ~RtDuplex()
40
 
{
41
 
  sound_dev->playBuffer(outdata,writeCounter);
42
 
  writeCounter = 0;
43
 
  while (writeCounter<data_length)      {
44
 
    outdata[writeCounter++] = 0;
45
 
  }
46
 
  sound_dev->playBuffer(outdata,writeCounter);
47
 
  sound_dev->playBuffer(outdata,writeCounter);  // Are these extra writes necessary?
48
 
  sound_dev->playBuffer(outdata,writeCounter);
49
 
  delete [ ] insamples;
50
 
  delete [ ] indata;
51
 
  delete [ ] outdata;
52
 
  delete sound_dev;
53
 
}
54
 
 
55
 
MY_FLOAT RtDuplex :: tick(MY_FLOAT outsample)
56
 
{
57
 
  // We offset the data read and data write calls by RT_BUFFER_SIZE / 2
58
 
  if (readCounter >= data_length) {
59
 
    sound_dev->recordBuffer(indata,data_length);
60
 
    readCounter = 0;
61
 
  }
62
 
  *insamples = (MY_FLOAT) indata[readCounter++];
63
 
  if (channels > 1) {
64
 
    int i;
65
 
    for (i=1;i<channels;i++)
66
 
      *insamples += (MY_FLOAT) indata[readCounter++];
67
 
    *insamples /= i;
68
 
  }
69
 
  *insamples *= gain;
70
 
 
71
 
  for (int i=0;i<channels;i++)
72
 
    outdata[writeCounter++] = (short) (outsample * 32000.0);
73
 
 
74
 
  if (writeCounter >= data_length) {
75
 
    sound_dev->playBuffer(outdata,data_length);
76
 
    writeCounter = 0;
77
 
  }
78
 
  return *insamples;
79
 
}
80
 
 
81
 
MY_MULTI RtDuplex :: mtick(MY_MULTI outsamples)
82
 
{
83
 
  int i;
84
 
  // We offset the data read and data write calls by RT_BUFFER_SIZE / 2
85
 
  if (readCounter >= data_length) {
86
 
    sound_dev->recordBuffer(indata,data_length);
87
 
    readCounter = 0;
88
 
  }
89
 
  for (i=0;i<channels;i++)
90
 
    insamples[i] = (MY_FLOAT) (indata[readCounter++]*gain);
91
 
 
92
 
  for (i=0;i<channels;i++)
93
 
    outdata[writeCounter++] = (short) (*outsamples++ * 32000.0);
94
 
 
95
 
  if (writeCounter >= data_length) {
96
 
    sound_dev->playBuffer(outdata,data_length);
97
 
    writeCounter = 0;
98
 
  }
99
 
  return insamples;
100
 
}
101
 
 
102
 
#endif