-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDummyOutput.cpp
175 lines (145 loc) · 3.76 KB
/
DummyOutput.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <windows.h>
#include <stdlib.h>
#include <winamp/out.h>
#include <winamp/gen.h>
#include "gen_waveseek.h"
void DummyOutConfig(HWND /*hwnd*/) { }
void DummyOutAbout(HWND /*hwnd*/) { }
void DummyOutInit() { }
void DummyOutQuit() { }
unsigned short pSampleBuffer[SAMPLE_BUFFER_SIZE];
unsigned int nFramePerWindow = 0,
nBufferPointer = 0,
nNumChannels = 0,
nBitsPerSample = 0;
unsigned long nCurrentAmplitude = 0,
nCurrentSampleCount = 0;
extern int nLengthInMS;
int DummyOutOpen(int samplerate, int numchannels, int bitspersamp, int /*bufferlenms*/, int /*prebufferms*/)
{
nNumChannels = numchannels;
nBitsPerSample = bitspersamp;
nCurrentSampleCount = nCurrentAmplitude = 0;
if (nLengthInMS > 0)
{
nFramePerWindow = MulDiv(nLengthInMS, samplerate, SAMPLE_BUFFER_SIZE * 1000) + 1;
}
return 1;
}
void DummyOutClose() { }
void AddSample(unsigned int nSample)
{
nCurrentAmplitude = max(nCurrentAmplitude, nSample);
++nCurrentSampleCount;
if (((nCurrentSampleCount / nNumChannels) == nFramePerWindow) && (nBufferPointer < SAMPLE_BUFFER_SIZE))
{
pSampleBuffer[nBufferPointer++] = nCurrentAmplitude;
nCurrentSampleCount = 0;
nCurrentAmplitude = 0;
}
}
int DummyOutWrite(char *buf, int len)
{
if (nFramePerWindow == 0)
{
return 1;
}
if (nBitsPerSample == 16)
{
const short * p = (short *)buf;
for (int i = 0; i < len / 2; i++)
{
const unsigned int nSample = abs(*(p++));
AddSample(nSample);
}
}
else if (nBitsPerSample == 24)
{
const char * p = (char *)buf;
for (int i = 0; i < len / 3; i++)
{
const unsigned int nSample = abs((((0xFF & *(p + 2)) << 24) | ((0xFF & *(p + 1)) << 16) | ((0xFF & *(p)) << 8)) >> 16);
p += 3;
AddSample((nSample));
}
}
else
{
// if we don't support it then we need to flag it
// so that a message is provided to the user else
// it can cause confusion due to looking broken.
extern int bUnsupported;
bUnsupported = 1;
}
return 0;
}
int DummyOutCanWrite()
{
return 65536;
}
int DummyOutIsPlaying()
{
return 0;
}
int DummyOutPause(int /*pause*/)
{
return 0;
}
void DummyOutSetVolume(int /*volume*/) { }
void DummyOutSetPanning(int /*pan*/) { }
void DummyOutFlush(int /*t*/) { }
int DummyOutGetOutputTime()
{
return 0;
}
int DummyOutGetWrittenTime()
{
return 0;
}
int DummyDSPIsActive()
{
return 0;
}
int DummyDSPDoSamples(short int * /*samples*/, int numsamples, int /*bps*/, int /*nch*/, int /*srate*/)
{
return numsamples;
}
Out_Module *pDummyOutput = NULL;
Out_Module *CreateOutput(HWND hwnd, HINSTANCE hDLL)
{
DestroyOutput();
nBufferPointer = 0;
ZeroMemory(pSampleBuffer, SAMPLE_BUFFER_SIZE * sizeof(unsigned short));
pDummyOutput = (Out_Module *)calloc(1, sizeof(Out_Module));
if (pDummyOutput)
{
pDummyOutput->version = OUT_VER;
pDummyOutput->id = 0xDEAD1234;
pDummyOutput->hMainWindow = hwnd;
pDummyOutput->hDllInstance = hDLL;
pDummyOutput->Config = DummyOutConfig;
pDummyOutput->About = DummyOutAbout;
pDummyOutput->Init = DummyOutInit;
pDummyOutput->Quit = DummyOutQuit;
pDummyOutput->Open = DummyOutOpen;
pDummyOutput->Close = DummyOutClose;
pDummyOutput->Write = DummyOutWrite;
pDummyOutput->CanWrite = DummyOutCanWrite;
pDummyOutput->IsPlaying = DummyOutIsPlaying;
pDummyOutput->Pause = DummyOutPause;
pDummyOutput->SetVolume = DummyOutSetVolume;
pDummyOutput->SetPan = DummyOutSetPanning;
pDummyOutput->Flush = DummyOutFlush;
pDummyOutput->GetOutputTime = DummyOutGetOutputTime;
pDummyOutput->GetWrittenTime = DummyOutGetWrittenTime;
}
return pDummyOutput;
}
void DestroyOutput()
{
if (pDummyOutput)
{
free(pDummyOutput);
pDummyOutput = NULL;
}
}