-
Notifications
You must be signed in to change notification settings - Fork 8
/
wfsource.h
86 lines (73 loc) · 2.64 KB
/
wfsource.h
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
85
86
/**************************************************************************
* copyright : (C) 2004-2006 by Petr Schwarz & Pavel Matejka *
* UPGM,FIT,VUT,Brno *
* email : {schwarzp,matejkap}@fit.vutbr.cz *
**************************************************************************
* *
* 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. *
* *
**************************************************************************/
#ifndef _WFSOURCE_H
#define _WFSOURCE_H
#include <windows.h>
#include <mmsystem.h>
#include <exception>
#include <new>
#define CWFS_BUFFERLENGTH 1000 // 1 s
#define CWFS_FRAMELENGTH 100 // 100 ms
// VC directive
//#pragma comment(lib, "winmm.lib") // link the WINMM.LIB library
// // if this library does not exist, import it with the libimp
// // or the tlibimp tool from WINMM.DLL
#ifndef CALLBACK
#define CALLBACK _pascal
#endif
// exceptions
class wf_error : public std::exception
{
protected:
char str[256];
public:
wf_error(const char *what_arg) throw() {strncpy(str, what_arg, 256);};
virtual const char *what () const throw () {return str;};
virtual ~wf_error() throw() {};
};
class CWFSource
{
protected:
HANDLE event;
int sampleFreq;
int channels;
int bitsPerSample;
HWAVEIN device;
tWAVEFORMATEX wf;
WAVEHDR header1;
WAVEHDR header2;
WAVEHDR *header;
char *buffer;
char *bufferLastByte;
int bufferLen;
int frameLen;
char *reading;
char *storing;
volatile int bytesRecorded;
volatile int recFrames;
volatile int actFrame;
volatile bool isRecording;
static void CALLBACK MMSCallback(HWAVEIN hwi, UINT uMSG, DWORD dwInstance,
DWORD dwParam1, DWORD dwParam2);
void onData();
void recordFrame();
public:
CWFSource();
~CWFSource();
bool isAvailable(char* ret_whay_not = 0);
void open(); // throw(wf_error, std::bad_alloc)
void close();
void read(char *buff, int n); // throw(wf_error);
void setFormat(int sf, int ch, int bps) {sampleFreq = sf; channels = ch; bitsPerSample = bps;};
};
#endif