audiolayer.h 3.75 KB
Newer Older
jpbl's avatar
jpbl committed
1
2
3
4
/*
 *  Copyright (C) 2004-2005 Savoir-Faire Linux inc.
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 *  Author:  Jerome Oufella <jerome.oufella@savoirfairelinux.com> 
5
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
jpbl's avatar
jpbl committed
6
7
8
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 *  (at your option) any later version.
 *                                                                              
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *                                                                              
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _AUDIO_LAYER_H
#define _AUDIO_LAYER_H

#include <cc++/thread.h> // for ost::Mutex

#include "portaudiocpp/PortAudioCpp.hxx"

#include "../global.h"
#include "ringbuffer.h"
31
#include "audiodevice.h"
jpbl's avatar
jpbl committed
32
33
34
35

#define FRAME_PER_BUFFER	160

class RingBuffer;
36
class ManagerImpl;
jpbl's avatar
jpbl committed
37
38

class AudioLayer {
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
	public:
		AudioLayer(ManagerImpl* manager);
		~AudioLayer(void);

		/*
		 * @param indexIn
		 * @param indexOut
		 * @param sampleRate
		 * @param frameSize
		 */
		void openDevice(int, int, int, int);
		void startStream(void);
		void stopStream(void);
		void sleep(int);
		bool hasStream(void);
		bool isStreamActive(void);
		bool isStreamStopped(void);

		void flushMain();
		int putMain(void* buffer, int toCopy);
		int putUrgent(void* buffer, int toCopy);
		int canGetMic();
		int getMic(void *, int);
		void flushMic();

		int audioCallback (const void *, void *, unsigned long,
				const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags);
		int miniAudioCallback (const void *, void *, unsigned long,
				const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags);

		void setErrorMessage(const std::string& error) { _errorMessage = error; }
		std::string getErrorMessage() { return _errorMessage; }

		/**
		 * Get the sample rate of audiolayer
		 * accessor only
		 */
		unsigned int getSampleRate() { return _sampleRate; }
		unsigned int getFrameSize() { return _frameSize; }
		int getDeviceCount();
		AudioDevice* getAudioDeviceInfo(int index, int ioDeviceMask);

		enum IODEVICE {InputDevice=0x01, OutputDevice=0x02 };

		/**
		 * Toggle echo testing on/off
		 */
		void toggleEchoTesting();

	private:
		void closeStream (void);
		RingBuffer _urgentRingBuffer;
		RingBuffer _mainSndRingBuffer;
		RingBuffer _micRingBuffer;
		ManagerImpl* _manager; // augment coupling, reduce indirect access
		// a audiolayer can't live without manager

		portaudio::MemFunCallbackStream<AudioLayer> *_stream;

		/**
		 * Sample Rate SFLphone should send sound data to the sound card 
		 * The value can be set in the user config file- now: 44100HZ
		 */
		unsigned int _sampleRate;
		
		/**
 		 * Length of the sound frame we capture or read in ms
 		 * The value can be set in the user config file - now: 20ms
 		 */	 		
		unsigned int _frameSize;
		
		/**
		 * Input channel (mic) should be 1 mono
		 */
		unsigned int _inChannel; // mic

		/**
		 * Output channel (stereo) should be 1 mono
		 */
		unsigned int _outChannel; // speaker

		/**
		 * Default volume for incoming RTP and Urgent sounds.
		 */
		unsigned short _defaultVolume; // 100

		/**
		 * Echo testing or not
		 */
		bool _echoTesting;

		std::string _errorMessage;
		ost::Mutex _mutex;

		float *table_;
		int tableSize_;
		int leftPhase_;
jpbl's avatar
jpbl committed
136
137
138
139
};

#endif // _AUDIO_LAYER_H_