AudioInput.cpp 2.47 KB
Newer Older
jcaceres's avatar
jcaceres committed
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
/*
  JackTrip: A Multimachine System for High-Quality Audio 
  Network Performance over the Internet

  Copyright (c) 2008 Chris Chafe, Juan-Pablo Caceres,
  SoundWIRE group at CCRMA.
  
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:
  
  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*/

/*
 * audio_input.cpp
 *
jcaceres's avatar
jcaceres committed
33
34
 * Audio input class.  Takes rtBuffers from the sound device and 
 * puts them into the Stream.
jcaceres's avatar
jcaceres committed
35
 * 
jcaceres's avatar
jcaceres committed
36
37
 */

jcaceres's avatar
jcaceres committed
38
39
#include "AudioInput.h"
#include "Stream.h"
jcaceres's avatar
jcaceres committed
40
41
42
#include <iostream>

using namespace std;
jcaceres's avatar
jcaceres committed
43
44

AudioInput::AudioInput (AudioDevice * audioDevice, AudioInfoT audioInfo):
jcaceres's avatar
jcaceres committed
45
  InputStreamPlugin ("Audio Input StreamPlugin"),
jcaceres's avatar
jcaceres committed
46
  audioDevice (audioDevice), audioInfo (audioInfo)
jcaceres's avatar
jcaceres committed
47
{
jcaceres's avatar
jcaceres committed
48
  dontRun = audioInfo->jack;
jcaceres's avatar
jcaceres committed
49
50
51
52
53
54
55
56
57
}

AudioInput::~AudioInput ()
{
}

int
AudioInput::rcv (char *buf)
{
jcaceres's avatar
jcaceres committed
58
59
  audioDevice->readBuffer (buf);
  return 0;
jcaceres's avatar
jcaceres committed
60
61
62
63
64
}

void
AudioInput::stop ()
{
jcaceres's avatar
jcaceres committed
65
66
  _running = false;
  audioDevice->unlockRead ();
jcaceres's avatar
jcaceres committed
67
68
69
70
71
}

void
AudioInput::run ()
{
jcaceres's avatar
jcaceres committed
72
  _running = true;
jcaceres's avatar
jcaceres committed
73

jcaceres's avatar
jcaceres committed
74
  char *databuf = new char[audioInfo->getBytesPerBuffer ()];
jcaceres's avatar
jcaceres committed
75

jcaceres's avatar
jcaceres committed
76
  cerr << "Started AUDIO Input Run" << endl;
jcaceres's avatar
jcaceres committed
77

jcaceres's avatar
jcaceres committed
78
79
80
81
  while (_running)
    {
      rcv (databuf);	// from audioDevice
      if (stream == NULL)
jcaceres's avatar
jcaceres committed
82
	{
jcaceres's avatar
jcaceres committed
83
	  cerr << "ERROR: AudioInput has no stream to write to! " << endl;
jcaceres's avatar
jcaceres committed
84
	}
jcaceres's avatar
jcaceres committed
85
86
      xfrFrom (databuf);	// to stream
    }
jcaceres's avatar
jcaceres committed
87
88
89
90
91
92
}


void
AudioInput::xfrFrom (void *buf)
{
jcaceres's avatar
jcaceres committed
93
  stream->write (buf, key);
jcaceres's avatar
jcaceres committed
94
95
96
}


97
/*
jcaceres's avatar
jcaceres committed
98
99
void AudioInput::plotVal (double v)
{
jcaceres's avatar
jcaceres committed
100
101
102
103
104
105
106
  if(_rcvr!=NULL)
    {
      ThreadCommEvent *e = new ThreadCommEvent (v,
						0.0,
						0.0);
      QApplication::postEvent (_rcvr, e);	// to app event loop
    }
jcaceres's avatar
jcaceres committed
107
}
108
*/