-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdrv_wav.cpp
More file actions
107 lines (75 loc) · 1.99 KB
/
mdrv_wav.cpp
File metadata and controls
107 lines (75 loc) · 1.99 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
File: MDRV_WAV.CPP
Description: -
Version: 1.00 - original
1.01 - fixed lengths written to WAV header.. they were 4 bytes short
1.02 - fixed lengths written to WAV header AGAIN @$^#!$#%$
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include "mdrv_wav.h"
MDRV_WAV::MDRV_WAV(FILE *fp) : MDRIVER_FMX()
{
dest=fp;
}
MDRV_WAV::~MDRV_WAV()
{
}
void MDRV_WAV::Init()
{
MDRIVER_FMX::Init();
}
void MDRV_WAV::Exit()
{
MDRIVER_FMX::Exit();
}
void MDRV_WAV::Start()
{
ULONG ltmp;
UWORD wtmp;
fwrite("RIFF",4,1,dest); // rID
fwrite("XXXX",4,1,dest); // rLen
fwrite("WAVE",4,1,dest); // wID
fwrite("fmt ",4,1,dest); // fID
ltmp=16; fwrite(<mp,4,1,dest); // fLen
wtmp=0x0001; // WAVE_FORMAT_PCM;
fwrite(&wtmp,2,1,dest); // wFormatTag
wtmp=(mode & DMODE_STEREO) ? 2 : 1;
fwrite(&wtmp,2,1,dest); // nChannels
ltmp=frequency;
fwrite(<mp,4,1,dest); // nSamplesPerSec
if(mode & DMODE_STEREO) ltmp<<=1;
if(mode & DMODE_16BITS) ltmp<<=1;
fwrite(<mp,4,1,dest); // nAvgBytesPerSec
wtmp=1;
if(mode & DMODE_16BITS) wtmp<<=1;
if(mode & DMODE_STEREO) wtmp<<=1;
fwrite(&wtmp,2,1,dest); // nBlockAlign
wtmp=(mode & DMODE_16BITS) ? 16 : 8;
fwrite(&wtmp,2,1,dest); // wBitsPerSample
fwrite("data",4,1,dest); // dID
fwrite("XXXX",4,1,dest); // dLen
MDRIVER_FMX::Start();
}
void MDRV_WAV::Stop()
{
ULONG len,ltmp;
MDRIVER_FMX::Stop();
fflush(dest);
len=ftell(dest);
ltmp=len-8;
fseek(dest,4,SEEK_SET);
fwrite(<mp,4,1,dest);
ltmp=len-44;
fseek(dest,40,SEEK_SET);
fwrite(<mp,4,1,dest);
fseek(dest,0,SEEK_END);
}
void MDRV_WAV::Update()
{
WriteBytes(buffer,4096);
fwrite(buffer,4096,1,dest);
}