AudioOutput.cpp 2.98 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
33
/*
  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_output.cpp
 */

jcaceres's avatar
jcaceres committed
34
35
#include "AudioOutput.h"
#include "Stream.h"
jcaceres's avatar
jcaceres committed
36
//#include "ambisonics/ambisonicsdecoder.h"
jcaceres's avatar
jcaceres committed
37
#include <cstring>
jcaceres's avatar
jcaceres committed
38
39
40
#include <iostream>

using namespace std;
jcaceres's avatar
jcaceres committed
41
42

AudioOutput::AudioOutput (AudioDevice * audioDevice, AudioInfoT audioInfo):
jcaceres's avatar
jcaceres committed
43
  OutputStreamPlugin ("Audio Output plugin"),
jcaceres's avatar
jcaceres committed
44
  audioDevice (audioDevice), audioInfo (audioInfo), decoder (NULL)
jcaceres's avatar
jcaceres committed
45
{
jcaceres's avatar
jcaceres committed
46
  dontRun = audioInfo->jack;
jcaceres's avatar
jcaceres committed
47
48
49
50
51
52
53
54
55
56
}

AudioOutput::~AudioOutput ()
{
}


int
AudioOutput::send (char *buf)
{
jcaceres's avatar
jcaceres committed
57
58
  audioDevice->writeBuffer (buf);
  return 0;
jcaceres's avatar
jcaceres committed
59
60
61
62
63
}

void
AudioOutput::run ()
{
jcaceres's avatar
jcaceres committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  _running = true;

  char *databuf = new char[audioInfo->getBytesPerBuffer ()];

  /*
   * if (decoder){
   * chan_len = rtBufferSize / chans;
   * input_chans = 4;
   * input_size = chan_len * 4;
   * }
   * else {
   * chan_len = rtBufferSize / chans;
   * input_chans = chans;
   * input_size = rtBufferSize;
   * }
   * double               decodedata[rtBufferSize];
   * double               codedata[input_size];
   * 
   * printf("size %d input_size %d input_chans %d tsize %d",
   * rtBufferSize, input_size, input_chans,rtBufferSize*chans*2); */

  cerr << "Started Audio Output Run" << endl;

  while (_running)
    {
      if (stream == NULL)
jcaceres's avatar
jcaceres committed
90
	{
jcaceres's avatar
jcaceres committed
91
	  cerr << "ERROR: AudioOutput has no stream to read from! " << endl;
jcaceres's avatar
jcaceres committed
92
	}
jcaceres's avatar
jcaceres committed
93
94
95
      xfrTo (databuf);  // from stream
      this->send (databuf); // to audioDevice
    }
jcaceres's avatar
jcaceres committed
96
97
98
}

void
99
AudioOutput::xfrTo (void* buf)
jcaceres's avatar
jcaceres committed
100
{
jcaceres's avatar
jcaceres committed
101
102
103
  stream->read (buf, key);
  //int rp = stream->read (buf, key);
  //cout << "readPosition " << rp  <<"\t\t" << endl;
jcaceres's avatar
jcaceres committed
104
105
106
107
108
}

void
AudioOutput::stop ()
{
jcaceres's avatar
jcaceres committed
109
  _running = false;
jcaceres's avatar
jcaceres committed
110
111
}

112
/*
jcaceres's avatar
jcaceres committed
113
114
void AudioOutput::plotVal (double v)
{
jcaceres's avatar
jcaceres committed
115
116
117
118
119
120
121
  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
122
}
123
*/