-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlwfsource.h
83 lines (70 loc) · 2.31 KB
/
lwfsource.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
/**************************************************************************
* 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 _LWFSOURCE_H
#define _LWFSOURCE_H
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <exception>
#include <new>
#define WFS_BUFFERLENGTH 2000 // 2 s
// JC zkousim 10 mms namisto 100 - pro labs ne.
#define WFS_FRAMELENGTH 100 // 100 ms
#define WFS_DEFAULTDEVICE "/dev/dsp"
// 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 LWFSource
{
protected:
char *device;
FILE *dp;
int sampleFreq;
int channels;
int bitsPerSample;
int blockAlign;
char *buffer;
char *bufferLastByte;
volatile int bufferLen;
volatile int frameLen;
char *reading;
char *storing;
volatile int bytesRecorded;
volatile bool isRecording;
pthread_t thread;
pthread_mutex_t mutex;
pthread_cond_t cond;
void runRecording();
static void *recordingBypass(void *arg);
void recording();
void onData();
void recordFrame();
public:
LWFSource();
~LWFSource();
bool isAvailable(char* ret_whay_not = 0);
bool isOpen() {return dp != 0;};
void open();
void close();
void read(char *buff, int n);
void setFormat(int sf, int ch, int bps) {sampleFreq = sf; channels = ch; bitsPerSample = bps;};
void setDevice(char *d) {device = d;};
};
#endif