audiolayer.h 2.4 KB
Newer Older
llea's avatar
llea committed
1
2
/**
 *  Copyright (C) 2004-2005 Savoir-Faire Linux inc.
yanmorin's avatar
   
yanmorin committed
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
llea's avatar
llea committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *  Author:  Jerome Oufella <jerome.oufella@savoirfairelinux.com> 
 *
 *  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
 *  the Free Software Foundation; either version 2 of the License, or
 *  (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.
 */

jpbl's avatar
jpbl committed
21
22
23
24
#if defined(AUDIO_PORTAUDIO)

#ifndef _AUDIO_LAYER_H
#define _AUDIO_LAYER_H
llea's avatar
llea committed
25

yanmorin's avatar
   
yanmorin committed
26
27
#include <cc++/thread.h> // for ost::Mutex

jpbl's avatar
jpbl committed
28
#include "portaudiocpp/PortAudioCpp.hxx"
llea's avatar
llea committed
29

jpbl's avatar
jpbl committed
30
#include "../global.h"
jpbl's avatar
jpbl committed
31
#include "ringbuffer.h"
jpbl's avatar
jpbl committed
32

llea's avatar
llea committed
33
#define FRAME_PER_BUFFER	160
jpbl's avatar
jpbl committed
34
35
36
37
#define MIC_CHANNELS 		2 // 1=mono 2=stereo
#define SAMPLE_BYTES 		sizeof(int16)
#define SAMPLES_SIZE(i) 	(i * MIC_CHANNELS * SAMPLE_BYTES)

llea's avatar
llea committed
38

jpbl's avatar
jpbl committed
39
class RingBuffer;
jpbl's avatar
jpbl committed
40

jpbl's avatar
jpbl committed
41
class AudioLayer {
llea's avatar
llea committed
42
public:
yanmorin's avatar
   
yanmorin committed
43
44
45
46
47
48
49
50
51
  AudioLayer();
  ~AudioLayer(void);

  void openDevice(int);
  void startStream(void);
  void stopStream(void);
  void sleep(int);
  bool isStreamActive(void);
  bool isStreamStopped(void);
llea's avatar
llea committed
52

yanmorin's avatar
   
yanmorin committed
53
  void flushMain();
yanmorin's avatar
   
yanmorin committed
54
55
56
57
  int putMain(void* buffer, int toCopy);
  int putUrgent(void* buffer, int toCopy);
  int canGetMic();
  int getMic(void *, int);
yanmorin's avatar
   
yanmorin committed
58
  void flushMic();
yanmorin's avatar
   
yanmorin committed
59

yanmorin's avatar
   
yanmorin committed
60
61
  int audioCallback (const void *, void *, unsigned long,
        const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags);
jpbl's avatar
jpbl committed
62

yanmorin's avatar
   
yanmorin committed
63
64
  void setErrorMessage(const std::string& error) { _errorMessage = error; }
  std::string getErrorMessage() { return _errorMessage; }
llea's avatar
llea committed
65
66

private:
yanmorin's avatar
   
yanmorin committed
67
68
69
70
  void	closeStream	(void);
  RingBuffer _urgentRingBuffer;
  RingBuffer _mainSndRingBuffer;
  RingBuffer _micRingBuffer;
jpbl's avatar
jpbl committed
71
72

	portaudio::MemFunCallbackStream<AudioLayer> *_stream;
yanmorin's avatar
   
yanmorin committed
73
  std::string _errorMessage;
yanmorin's avatar
   
yanmorin committed
74
//	portaudio::AutoSystem autoSys;
yanmorin's avatar
   
yanmorin committed
75
  ost::Mutex _mutex;
yanmorin's avatar
   
yanmorin committed
76
  int NBCHARFORTWOINT16;
llea's avatar
llea committed
77
78
};

jpbl's avatar
jpbl committed
79
#endif // _AUDIO_LAYER_H_
llea's avatar
llea committed
80
81

#endif // defined(AUDIO_PORTAUDIO)