File: SoundCard.h

package info (click to toggle)
wstools 0.4.8d-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,440 kB
  • ctags: 1,991
  • sloc: cpp: 13,880; makefile: 469
file content (84 lines) | stat: -rw-r--r-- 2,225 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
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
/*
 *   Copyright (C) 2002-2004 by Jonathan Naylor G4KLX
 *
 *   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.
 */

#ifndef SoundCard_H
#define	SoundCard_H

#include "SoundDev.h"

#include <wx/wx.h>

#ifdef __WINDOWS__
#include <windows.h>
#include <mmsystem.h>

const int NUM_IN_OUT_CHANNELS = 1;
const int BYTES_PER_SAMPLE    = 2;	/* Must be the same as the size of wxInt16 */
const int BITS_PER_SAMPLE     = BYTES_PER_SAMPLE * 8;

const int NUM_SOUND_BUFFERS_IN  = 30;
const int NUM_SOUND_BUFFERS_OUT = 30;
#endif

class CSoundCard : public ISoundDev {

    public:
    	CSoundCard(const wxString& device, int sampleRate, int rxBufferSize, int txBufferSize);
	virtual ~CSoundCard();

	virtual void openWrite();
	virtual void openRead();

	virtual void read(double* sample, int& len);
	virtual void write(double* sample, int len);

	virtual void close();

	static wxArrayString getDevices();

    private:
	wxString m_device;
	int      m_sampleRate;
	int      m_rxBufferSize;
	int      m_txBufferSize;

#ifdef __WINDOWS__
	UINT     m_devIn;
	HWAVEIN  m_waveIn;
	HANDLE   m_waveInEvent;
	wxInt16* m_waveInBuffer[NUM_SOUND_BUFFERS_IN];
	WAVEHDR  m_waveInHeader[NUM_SOUND_BUFFERS_IN];
	int      m_bufferInNum;

	UINT     m_devOut;
	HWAVEOUT m_waveOut;
	HANDLE   m_waveOutEvent;
	wxInt16* m_waveOutBuffer[NUM_SOUND_BUFFERS_OUT];
	WAVEHDR  m_waveOutHeader[NUM_SOUND_BUFFERS_OUT];
#else
	int      m_fd;
#endif

#ifdef __WINDOWS__
	void addInBuffer();
	void getDoneBuffer(int& iCntPrepBuf, int& iIndexDoneBuf) const;
	void addOutBuffer(int n);
#endif
};

#endif