aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/SDK/out_null/main.c
blob: 55eb9906bee1e25b1838fc3cfff6431f42c7dd4e (plain) (blame)
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
#include <windows.h>
#include <shlobj.h>
#include "../winamp/out.h"

#define PI_VER2 "v1.2"

/* #ifdef __alpha
#define PI_VER PI_VER2 " (AXP)"
#else
#define PI_VER PI_VER2 " (x86)"
#endif */

int getwrittentime();
int getoutputtime();

int srate, numchan, bps, active;
volatile int writtentime, w_offset;


BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
	return TRUE;
}

Out_Module out;

static int last_pause=0;

void config(HWND hwnd)
{
}

void about(HWND hwnd)
{
}

void init()
{
}

void quit()
{
}

int start_t;

int open(int samplerate, int numchannels, int bitspersamp, int bufferlenms, int prebufferms)
{
	start_t=GetTickCount();
 	w_offset = writtentime = 0;
	active=1;
	numchan = numchannels;
	srate = samplerate;
	bps = bitspersamp;
	return 1;
}

void close()
{
}

int write(char *buf, int len)
{
	writtentime += len;
	return 0;
}

int canwrite()
{
	if (last_pause) return 0;
	if (getwrittentime() < getoutputtime()+MulDiv(65536,1000,srate*bps*numchan/8)) return 65536;
	return 0;
}

int isplaying()
{
	return 0;
}

int pause(int pause)
{
	int t=last_pause;
	if (!last_pause && pause) { w_offset+=GetTickCount()-start_t;  writtentime=0; }
	if (last_pause && !pause) { start_t=GetTickCount(); }
	last_pause=pause;
	return t;
}

void setvolume(int volume)
{
}

void setpan(int pan)
{
}

void flush(int t)
{
  w_offset=t;
  start_t=GetTickCount();
  writtentime=0;
}
	
int getoutputtime()
{
	if (last_pause)
		return w_offset;
	return GetTickCount()-start_t + w_offset;
}

int getwrittentime()
{
	int t=srate*numchan,l;
	int ms=writtentime;

	if (t)
	{
	l=ms%t;
	ms /= t;
	ms *= 1000;
	ms += (l*1000)/t;

	ms/=(bps/8);

	return ms + w_offset;
	}
	else
		return ms;
}

Out_Module out = {
	OUT_VER,
	"Nullsoft NULL Output " PI_VER2
	
	,
	65,
	0, // hmainwindow
	0, // hdllinstance
	config,
	about,
	init,
	quit,
	open,
	close,
	write,
	canwrite,
	isplaying,
	pause,
	setvolume,
	setpan,
	flush,
	getoutputtime,
	getwrittentime
};

__declspec( dllexport ) Out_Module * winampGetOutModule()
{
	return &out;
}