-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawEncoder.cpp
More file actions
45 lines (39 loc) · 774 Bytes
/
RawEncoder.cpp
File metadata and controls
45 lines (39 loc) · 774 Bytes
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
#include "RawEncoder.h"
#include <cstring>
RawEncoder::RawEncoder(const wchar_t *filename) : f(NULL)
{
name=(wchar_t*)malloc((wcslen(filename)+1)*sizeof(wchar_t));
wcscpy(name, filename);
}
DWORD RawEncoder::Init(const WAVEFORMATEX *format)
{
f = _wfopen(name, L"wb");
if (!f)
return ENCODER_ERROR_MASK;
return 0;
}
DWORD RawEncoder::Encode(BYTE *data, int size)
{
if (fwrite(data,1,size,f) != size)
return ENCODER_ERROR_MASK|1;
return 0;
}
wchar_t* RawEncoder::GetErrorString(DWORD error)
{
switch(error)
{
case ENCODER_ERROR_MASK:
return L"Can't open file";
case (ENCODER_ERROR_MASK|1):
return L"Can't write data in file (out of space?)";
default:
return NULL;
}
}
DWORD RawEncoder::Finalize()
{
if (f)
fclose(f);
free(name);
return 0;
}