summaryrefslogtreecommitdiffstats
path: root/Src/Plugins/Input/in_vorbis/ExtendedRead.cpp
blob: c89f829dcf15077d147b411af7d596a424d289cc (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
#include "main.h"
#include "decoder.h"

extern "C"
{
	//returns handle!=0 if successful, 0 if error
	//size will return the final nb of bytes written to the output, -1 if unknown
	__declspec( dllexport ) intptr_t winampGetExtendedRead_openW(const wchar_t *fn, int *size, int *bps, int *nch, int *srate) {
		VorbisFile * f = VorbisFile::Create(fn,false);
		if(f) {
			if(!*bps) *bps=16; // FUCKO HAX
			Decoder * d = new Decoder();
			d->Init(f, *bps, *nch, false, false);
			*nch = (int)d->nch;
			*srate = (int)d->sr;
			*bps = (int)d->bps;
			*size = (int)(f->Length() * (double)((*nch) * (*srate) * (*bps/8)));
			return (intptr_t)d;
		}
		return 0;
	}

	__declspec( dllexport ) intptr_t winampGetExtendedRead_openW_float(const wchar_t *fn, int *size, int *bps, int *nch, int *srate) {
		VorbisFile * f = VorbisFile::Create(fn,false);
		if(f) {
			Decoder * d = new Decoder();
			d->Init(f, *bps, *nch, true, false);
			*nch = (int)d->nch;
			*srate = (int)d->sr;
			*bps = (int)d->bps;
			*size = (int)(f->Length() * (double)((*nch) * (*srate) * (*bps/8)));
			return (intptr_t)d;
		}
		return 0;
	}

	//returns nb of bytes read. -1 if read error (like CD ejected). if (ret<len), EOF is assumed
	__declspec( dllexport ) intptr_t winampGetExtendedRead_getData(intptr_t handle, char *dest, size_t len, int *killswitch) {
		Decoder * d = (Decoder *)handle;
		size_t used = 0;
		for(;;) {
			used += (UINT)d->Read((UINT)(len - used),dest + used);
			if(used >= len) break;
			if(!d->DoFrame()) break;
			if(*killswitch) break;
			if (used)
				return used;
		}
		return used;
	}

	// return nonzero on success, zero on failure.
	__declspec( dllexport ) int winampGetExtendedRead_setTime(intptr_t handle, int millisecs) {
		Decoder * d = (Decoder *)handle;
		d->Flush();
		return !d->Seek(((double)millisecs) / 1000.0);
	}

	__declspec( dllexport ) void winampGetExtendedRead_close(intptr_t handle) {
		Decoder * d = (Decoder *)handle;
		d->Flush();
		delete d->file;
		delete d;
	}
}