AudioDevice.h 4.36 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
/*
  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.
*/

/*
 * audioDevice.h
jcaceres's avatar
jcaceres committed
32
33
34
35
36
37
 */

#ifndef	_AUDIO_DEVICE_H
#define	_AUDIO_DEVICE_H

#include <iostream>
jcaceres's avatar
jcaceres committed
38
39
#include <cstdlib>
#include <cmath>
jcaceres's avatar
jcaceres committed
40
41
#include "audioInfo.h"
#include "JackClient.h"
jcaceres's avatar
jcaceres committed
42
43
#include <QThread>
#include "JackTrip.h"
jcaceres's avatar
jcaceres committed
44
45
46
#include <QWaitCondition>
#include <QSemaphore>

jcaceres's avatar
jcaceres committed
47
48
49
50
51
52
53
54
/**
 * @brief Interfaces with an RtAudio sound device.
 */

// typedef class AudioDevice
class AudioDevice
{
public:
jcaceres's avatar
jcaceres committed
55
56
57
58
59
60
61
62
63
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  /** @brief Modes the audio device can be opened in:
   *
   * RECORD - The device can only be used for audio input.
   * PLAYBACK - The device can only be used for audio output.
   * DUPLEX - The device can be used for both input and output.
   */
  enum audioDeviceModeT
    { RECORD, PLAYBACK, DUPLEX };
public:
  AudioInput *inThread;
  AudioOutput *outThread;
  void setThreads(streamThreads t);

private:
  //RtAudio *device; //!< RtAudio Device.
  //RtAudio * device;
  JackClient *jdevice;

  char *buffer;		//!< Pointer to the RtAudio audio buffer.
  void *jibuffer;
  void *jobuffer;	  
  int streamID;		//!< RtAudio Stream ID
  int audioDeviceID;	//!< Audio device ID.
  AudioInfoT audioInfo;	//!< Relevant audio information.
  int numBuffers;		//!< Length of the device buffer (in buffers
  //!< of size AudioInfoT->framesPerBuffer).
  int bytesPerBuffer;	//!< Total number of bytes per audio buffer.
  int *stringsPerChan;	//!< Array of number of NetHarp strings per audio output channel for audio monitoring.
  bool harp;		//!< Harp mode?
  QSemaphore *readLock;	//!< Thread protection.
  QSemaphore *writeLock;	//!< Thread protection.
  audioDeviceModeT mode;	//!< Device mode.

  void generateHarpMixMap ();	//!< Generates mix map for mixing X NetHarp strings to Y audio channels

  //void checkRequirements (int i, RtAudioDeviceInfo * info);//Remove STK Dependency


public:

  /**
   * @brief Constructor.
   *
   * @param audioDeviceID - The device ID of the sound device to use (-1 for default).
   * @param numBuffers - The length of the queue of audio buffers maintained on the audio device.
   * @param audioInfo - Relevant audio information.
   */
  AudioDevice (int audioDeviceID, int numBuffers,
	       audioDeviceModeT mode,
	       AudioInfoT audioInfo);

  AudioDevice (bool test);

  ~AudioDevice ();

  /**
   * @brief tick the audio device.
   *
   * Plays the samples currently in the buffer, and (if in duplex mode), reads in a new buffer from the audio inputs.
   */
  //void tick ();//Remove STK Dependency
  /**
   * @brief tick the audio device.
   *
   *  Jack audio version, jack subsystem calls jtick.
   */
  void jtick ();

  /**
   * @brief read a buffer of audio samples from the device into the <b>to</b> buffer. (blocks).
   */
  void readBuffer (void *to);

  /**
   * @brief write a buffer of audio samples from the <b>from</b> buffer to the audio device buffer.  (blocks).
   */
  void writeBuffer (void *from);
  QWaitCondition jackWait;
  void bufferPtrs (void * jib, void * job);
  void jackStart ();
  void jackStop ();
  //Remove STK Dependency
  //void probeAudioDevices ();	//!< Probes audio devices to see if all required functionality is supported.
  void unlockRead ();
  void harpTick (void *toBuffer, void *fromBuffer);
  bool jack;
  // } *AudioDeviceT;
jcaceres's avatar
jcaceres committed
142
143
144
};

#endif