-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaveWin.cpp
More file actions
136 lines (101 loc) · 2.34 KB
/
WaveWin.cpp
File metadata and controls
136 lines (101 loc) · 2.34 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// wavewin.cpp : implementation file
//
#include "stdafx.h"
#include "wavewin.h"
#include <math.h>
extern PBYTE gWave;
extern int gPlaying; // 0=Stop, 1=Record, 2=Test
extern BYTE gStaticWave[MAXWAVE + 1]; // Static wave buffer
/////////////////////////////////////////////////////////////////////////////
// CWaveWin
CWaveWin::CWaveWin()
{
m_WaveWinDC = NULL;
}
CWaveWin::~CWaveWin()
{
gPlaying = 0;
}
BEGIN_MESSAGE_MAP(CWaveWin, CStatic)
//{{AFX_MSG_MAP(CWaveWin)
ON_WM_PAINT()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CWaveWin::InitWave()
{
if (m_WaveWinDC != NULL) {
delete m_WaveWinDC;
}
m_WaveWinDC = new CWindowDC(this);
CRect rect;
GetClientRect(&rect);
double waveyl = rect.Height();
for (int i = 0;i <= 255;i++)
m_cWaveY[i] = (int)(waveyl - (i / (256.0 / (double)(waveyl - 2))));
ClearWave();
}
void CWaveWin::ClearWave()
{
for (int i = 0;i < MAXWAVE + 1;i++) {
gWave[i] = 0x7f;
m_oWave[i] = 0x80;
}
}
void CWaveWin::GenerateWave(double x)
{
double Step = MAXWAVE / 2.0*3.1415926 / x;
for (int i = 0;i < MAXWAVE + 1;i++) {
gWave[i] = (BYTE)(128 * sin(i / Step)) - 0x80;
if (gWave[i] > 0xFF) gWave[i] = 0xFF;
}
}
void CWaveWin::DrawWave()
{
register unsigned char x, y, o, m;
if (!m_WaveWinDC) return;
m = m_cWaveY[0x7F];
for (x = 0;x < MAXWAVE + 1;x++) {
gStaticWave[x] = gWave[x];
y = m_cWaveY[gWave[x]];
o = m_oWave[x];
if (y != o) {
m_WaveWinDC->SetPixelV(x + 2, o, _WAVEBKG);
m_WaveWinDC->SetPixelV(x + 2, y, _WAVEDAT);
}
m_oWave[x] = y;
if (y != m)
m_WaveWinDC->SetPixelV(x + 2, m, _WAVENUL);
}
}
/////////////////////////////////////////////////////////////////////////////
// CWaveWin message handlers
void CWaveWin::OnPaint()
{
// Signal that Wave is ready
if (gPlaying == -2) gPlaying = -1;
int x, y, m;
CBrush bk(_WAVEBKG);
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);
CBrush* pOldBrush = dc.SelectObject(&bk);
dc.Rectangle(rect);
dc.SelectObject(pOldBrush);
m = m_cWaveY[0x7F] - 1;
for (x = 0;x < MAXWAVE + 1;x++) {
y = m_oWave[x] - 1;
dc.SetPixelV(x + 1, y, _WAVEDAT);
if (y != m)
dc.SetPixelV(x + 1, m, _WAVENUL);
}
// Do not call CStatic::OnPaint() for painting messages
}
void CWaveWin::OnDestroy()
{
CStatic::OnDestroy();
if (m_WaveWinDC != NULL) {
delete m_WaveWinDC;
m_WaveWinDC = NULL;
}
}