JackTrip.h 6.2 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
/*
  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.
*/

/*
jcaceres's avatar
jcaceres committed
31
 * JackTrip.h
jcaceres's avatar
jcaceres committed
32
33
 *
 * I/O Streams
jcaceres's avatar
jcaceres committed
34
35
36
37
38
39
40
41
42
43
 * -----------
 * - audioin and audioout are audio in and out.
 * - netin and netout are UDP network in and out.
 * - streamin connects netin to audioout or netout.  Command line arg networkInputQueueLengthInAudioBuffers
 * determines the amount of buffering in the stream.
 * - streamout connects audioin to audioout or netout.  DEFAULT_OUTPUT_STREAM_QUEUE_LENGTH are used to
 * buffer the connection (DEFAULT_OUTPUT_STREAM_QUEUE_LENGTH is the fewest output buffers that can 
 * be used reliably.
 */

jcaceres's avatar
jcaceres committed
44
45
#include "AudioInput.h"
#include "AudioOutput.h"
jcaceres's avatar
jcaceres committed
46
47
#include "udp_input.h"
#include "udp_output.h"
jcaceres's avatar
jcaceres committed
48
#include "Stream.h"
jcaceres's avatar
jcaceres committed
49
50
51
#include "udp.h"
#include <cstdlib>
#include <unistd.h>
jcaceres's avatar
jcaceres committed
52
#include <cstdio>
jcaceres's avatar
jcaceres committed
53
#include <iostream>
jcaceres's avatar
jcaceres committed
54
55
#include "audioInfo.h"
#include "networkInfo.h"
jcaceres's avatar
jcaceres committed
56
57
58
59
#include <QHostAddress>
#include <QString>
#include <ctime>
#include <QObject>
jcaceres's avatar
jcaceres committed
60
61
62
63
64


/* Define the audio sample type */
typedef signed short INT16;

jcaceres's avatar
jcaceres committed
65
66
#ifndef __JACKTRIP_H_
#define __JACKTRIP_H_
jcaceres's avatar
jcaceres committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

/** @brief Default settings used if not specified at the command line.
 *
 * Appropriate values depend on machine hardware.  Faster machines
 * can have lower buffer lengths without under / overrun problems etc.
 */

#define DEFAULT_SAMPLE_RATE 48000
#define DEFAULT_NETHARP_STRINGS 0
#define DEFAULT_AUDIO_CHANNELS 2
#define DEFAULT_NETWORK_QUEUE_LENGTH 2
#define DEFAULT_AUDIO_BUFFER_SIZE 128
#define DEFAULT_AUDIO_QUEUE_LENGTH 10
#define DEFAULT_HOSTNAME_MAXLENGTH 100
#define DEFAULT_NETWORK_PORT_OFFSET 0
#define DEFAULT_FIFO 0
#define DEFAULT_AUDIO_DEVICE 0	// audioDevice will choose the default device.
#define DEFAULT_SECONDS_BETWEEN_PLUCKS 1	// #Seconds between plucks, integer value.
#define DEFAULT_LOW_PASS_FILTER_COEFFICIENT 0	// Off, saves processor cycles.
#define DEFAULT_DELAY_LINE_COEFFICIENT 0	// Off, saves processor cycles.
#define DEFAULT_JACK 0	// Off 
#define DEFAULT_GUI 0	// Off
#define DEFAULT_PACKET_REDUNDANCY 4	// copies of a buffer in stream
#define DEFAULT_OUTPUT_STREAM_QUEUE_LENGTH 4	//! Minimum number of buffers that can be used reliably on your hardware.
#define DEFAULT_JACK_ALSA_READABLE_OFFSET 0

/** 
 * @brief contains all possible command line arguments.
 */
 
class AudioInput;
class AudioOutput;

struct streamThreads
{
jcaceres's avatar
jcaceres committed
102
103
104
105
106
107
  AudioInput *audioin;
  AudioOutput *audioout;
  UDPInput *netin;
  UDPOutput *netout;
  Stream *streamin;
  Stream *streamout;
jcaceres's avatar
jcaceres committed
108
109
110
};

enum runModeT
jcaceres's avatar
jcaceres committed
111
  { TRANSMIT, RECEIVE, NETMIRROR, SNDMIRROR, HARPT, HARPR, AUDIOINFO };
jcaceres's avatar
jcaceres committed
112
113
114

typedef struct cmdLineArgs
{
jcaceres's avatar
jcaceres committed
115
  int sampleRate;	/*! Audio sample rate.*/
jcaceres's avatar
jcaceres committed
116
117
118
  int netHarpStrings;	/*! Number of audio channels being sent over the network 
			 * connection.  In harp mode, any number of independent
			 * network channels (harp strings) can be run and mixed
jcaceres's avatar
jcaceres committed
119
120
			 * down to the number of audioChannels for monitoring.*/
  int audioChannels;	/*! Number of audio channels to output on audioout.*/
jcaceres's avatar
jcaceres committed
121
  int networkInputQueueLengthInPackets;	/*! Number of buffers of length rtBufferSize to buffer 
jcaceres's avatar
jcaceres committed
122
					 * the incoming network connection with.*/
jcaceres's avatar
jcaceres committed
123
  int framesPerAudioBuffer;	/*! Size of buffers to be fed to the audioDevice output
jcaceres's avatar
jcaceres committed
124
				 * device (in samples).*/
jcaceres's avatar
jcaceres committed
125
  int audioInputQueueLengthInAudioBuffers;	/*! Number of buffers of size framesPerAudioBuffer with which the
jcaceres's avatar
jcaceres committed
126
127
128
129
130
131
132
133
134
135
136
137
138
						 * audio output is buffered.*/
  char remoteHostname[100];	/*! Holds the hostname to connect to in TRANSMIT and HARPT mode.*/
  int networkPortOffset;	/*! Network port offset.*/
  int audioDeviceID;	/*! Will use default audio device if not specified.*/
  int runFifo;		/*! Run streambd with fifo priority (reduces delay).*/
  runModeT runMode;	/*! Run mode as defined above.*/
  int secondsBetweenPlucks;	/*! Number of seconds (integer) to wait between plucks.*/
  float lowPassFilterCoeff;	/*! Specifies low-pass filter coefficient.*/
  int delayIncrementBetweenStrings;	/*! Pitch increment between strings (cumulative).*/
  bool jack;		/*! Use jack audio subsystem, v.1, otherwise RtAudio.*/
  bool gui;		/*! GUI.*/
  int redundancy;		/*! copies of a buffer in stream */
  int jack_alsa_readable_offset; /*! bump up which is lowest alsa input channel */
jcaceres's avatar
jcaceres committed
139
140
141
142
143
} *cmdLineArgsT;

class AudioDevice;
class MainDialog;

jcaceres's avatar
jcaceres committed
144
class JackTrip:public QObject
jcaceres's avatar
jcaceres committed
145
{
jcaceres's avatar
jcaceres committed
146
147
  //Q_OBJECT public://***JPC COMENTED OUT
public:
jcaceres's avatar
jcaceres committed
148
149
  JackTrip();
  ~JackTrip();
jcaceres's avatar
jcaceres committed
150
151
152
153
154
  int cmd (MainDialog *eventThread);
  void start();
  void finish();
  void PrintUsage ();
  struct streamThreads t;
jcaceres's avatar
jcaceres committed
155

jcaceres's avatar
jcaceres committed
156
  int ParseCommandLine (int argc, char *argv[]);
jcaceres's avatar
jcaceres committed
157

jcaceres's avatar
jcaceres committed
158
  QString *GetLocalHostName ();
jcaceres's avatar
jcaceres committed
159

jcaceres's avatar
jcaceres committed
160
161
  void EstablishConnection (runModeT runMode, char *hostname,
			    UDPOutput * netout, UDPInput * netin);
jcaceres's avatar
jcaceres committed
162

jcaceres's avatar
jcaceres committed
163
  // int get_fifo_priority (void);
jcaceres's avatar
jcaceres committed
164

jcaceres's avatar
jcaceres committed
165
  // int set_fifo_priority (void);
jcaceres's avatar
jcaceres committed
166

jcaceres's avatar
jcaceres committed
167
  void ConnectStreamPlugins (InputStreamPlugin * from, OutputStreamPlugin * to,
jcaceres's avatar
jcaceres committed
168
		       Stream * through);
jcaceres's avatar
jcaceres committed
169

jcaceres's avatar
jcaceres committed
170
  void addStreamPlugin (InputStreamPlugin * from, Stream * str);
jcaceres's avatar
jcaceres committed
171

jcaceres's avatar
jcaceres committed
172
  void addStreamPlugin (OutputStreamPlugin * to, Stream * str);
jcaceres's avatar
jcaceres committed
173

jcaceres's avatar
jcaceres committed
174
175
  //void addSTKProcesses (Stream * str); //Remove STK dependency
  cmdLineArgs *args;
jcaceres's avatar
jcaceres committed
176
177
178
179
180
  AudioDevice *audioDevice;
		    public slots:
		    void go ();
  void stop ();
  void join ();
jcaceres's avatar
jcaceres committed
181
182
183
184

};


jcaceres's avatar
jcaceres committed
185
#endif