mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-12 01:30:49 +01:00
initial winamp plugin
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@41 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
4aec626083
commit
ac832cce80
@ -9,7 +9,7 @@ extern char * optarg;
|
||||
extern int optind, opterr, optopt;
|
||||
|
||||
void usage(const char * name) {
|
||||
fprintf(stderr,"vgmstream test decoder $Revision$\n"
|
||||
fprintf(stderr,"vgmstream test decoder $Revision$, $Date$\n"
|
||||
"Usage: %s [-o outfile.wav] [-l loop count]\n"
|
||||
"\t[-f fade time] [-i] [-p] [-c] [-m] infile\n"
|
||||
"Options:\n"
|
||||
|
18
winamp/Makefile
Normal file
18
winamp/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
export SHELL = /bin/sh
|
||||
export CFLAGS=-Wall -O3
|
||||
export LDFLAGS=-lm -L../src -lvgmstream
|
||||
export CC=i586-mingw32msvc-gcc
|
||||
export AR=i586-mingw32msvc-ar
|
||||
export STRIP=i586-mingw32msvc-strip
|
||||
|
||||
.PHONY: libvgmstream.a
|
||||
|
||||
in_vgmstream.dll: libvgmstream.a
|
||||
$(CC) -shared $(CFLAGS) in_vgmstream.c $(LDFLAGS) -o in_vgmstream.dll
|
||||
$(STRIP) in_vgmstream.dll
|
||||
|
||||
libvgmstream.a:
|
||||
$(MAKE) -C ../src libvgmstream.a
|
||||
|
||||
clean:
|
||||
rm -f in_vgmstream.dll
|
103
winamp/in2.h
Normal file
103
winamp/in2.h
Normal file
@ -0,0 +1,103 @@
|
||||
#include "out.h"
|
||||
|
||||
// note: exported symbol is now winampGetInModule2.
|
||||
|
||||
#define IN_VER 0x100
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int version; // module type (IN_VER)
|
||||
char *description; // description of module, with version string
|
||||
|
||||
HWND hMainWindow; // winamp's main window (filled in by winamp)
|
||||
HINSTANCE hDllInstance; // DLL instance handle (Also filled in by winamp)
|
||||
|
||||
char *FileExtensions; // "mp3\0Layer 3 MPEG\0mp2\0Layer 2 MPEG\0mpg\0Layer 1 MPEG\0"
|
||||
// May be altered from Config, so the user can select what they want
|
||||
|
||||
int is_seekable; // is this stream seekable?
|
||||
int UsesOutputPlug; // does this plug-in use the output plug-ins? (musn't ever change, ever :)
|
||||
|
||||
void (*Config)(HWND hwndParent); // configuration dialog
|
||||
void (*About)(HWND hwndParent); // about dialog
|
||||
|
||||
void (*Init)(); // called at program init
|
||||
void (*Quit)(); // called at program quit
|
||||
|
||||
void (*GetFileInfo)(char *file, char *title, int *length_in_ms); // if file == NULL, current playing is used
|
||||
int (*InfoBox)(char *file, HWND hwndParent);
|
||||
|
||||
int (*IsOurFile)(char *fn); // called before extension checks, to allow detection of mms://, etc
|
||||
// playback stuff
|
||||
int (*Play)(char *fn); // return zero on success, -1 on file-not-found, some other value on other (stopping winamp) error
|
||||
void (*Pause)(); // pause stream
|
||||
void (*UnPause)(); // unpause stream
|
||||
int (*IsPaused)(); // ispaused? return 1 if paused, 0 if not
|
||||
void (*Stop)(); // stop (unload) stream
|
||||
|
||||
// time stuff
|
||||
int (*GetLength)(); // get length in ms
|
||||
int (*GetOutputTime)(); // returns current output time in ms. (usually returns outMod->GetOutputTime()
|
||||
void (*SetOutputTime)(int time_in_ms); // seeks to point in stream (in ms). Usually you signal yoru thread to seek, which seeks and calls outMod->Flush()..
|
||||
|
||||
// volume stuff
|
||||
void (*SetVolume)(int volume); // from 0 to 255.. usually just call outMod->SetVolume
|
||||
void (*SetPan)(int pan); // from -127 to 127.. usually just call outMod->SetPan
|
||||
|
||||
// in-window builtin vis stuff
|
||||
|
||||
void (*SAVSAInit)(int maxlatency_in_ms, int srate); // call once in Play(). maxlatency_in_ms should be the value returned from outMod->Open()
|
||||
// call after opening audio device with max latency in ms and samplerate
|
||||
void (*SAVSADeInit)(); // call in Stop()
|
||||
|
||||
|
||||
// simple vis supplying mode
|
||||
void (*SAAddPCMData)(void *PCMData, int nch, int bps, int timestamp);
|
||||
// sets the spec data directly from PCM data
|
||||
// quick and easy way to get vis working :)
|
||||
// needs at least 576 samples :)
|
||||
|
||||
// advanced vis supplying mode, only use if you're cool. Use SAAddPCMData for most stuff.
|
||||
int (*SAGetMode)(); // gets csa (the current type (4=ws,2=osc,1=spec))
|
||||
// use when calling SAAdd()
|
||||
void (*SAAdd)(void *data, int timestamp, int csa); // sets the spec data, filled in by winamp
|
||||
|
||||
|
||||
// vis stuff (plug-in)
|
||||
// simple vis supplying mode
|
||||
void (*VSAAddPCMData)(void *PCMData, int nch, int bps, int timestamp); // sets the vis data directly from PCM data
|
||||
// quick and easy way to get vis working :)
|
||||
// needs at least 576 samples :)
|
||||
|
||||
// advanced vis supplying mode, only use if you're cool. Use VSAAddPCMData for most stuff.
|
||||
int (*VSAGetMode)(int *specNch, int *waveNch); // use to figure out what to give to VSAAdd
|
||||
void (*VSAAdd)(void *data, int timestamp); // filled in by winamp, called by plug-in
|
||||
|
||||
|
||||
// call this in Play() to tell the vis plug-ins the current output params.
|
||||
void (*VSASetInfo)(int nch, int srate);
|
||||
|
||||
|
||||
// dsp plug-in processing:
|
||||
// (filled in by winamp, called by input plug)
|
||||
|
||||
// returns 1 if active (which means that the number of samples returned by dsp_dosamples
|
||||
// could be greater than went in.. Use it to estimate if you'll have enough room in the
|
||||
// output buffer
|
||||
int (*dsp_isactive)();
|
||||
|
||||
// returns number of samples to output. This can be as much as twice numsamples.
|
||||
// be sure to allocate enough buffer for samples, then.
|
||||
int (*dsp_dosamples)(short int *samples, int numsamples, int bps, int nch, int srate);
|
||||
|
||||
|
||||
// eq stuff
|
||||
void (*EQSet)(int on, char data[10], int preamp); // 0-64 each, 31 is +0, 0 is +12, 63 is -12. Do nothing to ignore.
|
||||
|
||||
// info setting (filled in by winamp)
|
||||
void (*SetInfo)(int bitrate, int srate, int stereo, int synched); // if -1, changes ignored? :)
|
||||
|
||||
Out_Module *outMod; // filled in by winamp, optionally used :)
|
||||
} In_Module;
|
||||
|
||||
|
267
winamp/in_vgmstream.c
Normal file
267
winamp/in_vgmstream.c
Normal file
@ -0,0 +1,267 @@
|
||||
/* Winamp plugin interface for vgmstream */
|
||||
/* Largely copied from: */
|
||||
/*
|
||||
** Example Winamp .RAW input plug-in
|
||||
** Copyright (c) 1998, Justin Frankel/Nullsoft Inc.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../src/vgmstream.h"
|
||||
#include "in2.h"
|
||||
|
||||
#define PLUGIN_DESCRIPTION "vgmstream plugin ($Revision$, $Date$)"
|
||||
|
||||
/* post when playback stops */
|
||||
#define WM_WA_MPEG_EOF WM_USER+2
|
||||
|
||||
In_Module input_module; /* the input module, declared at the bottom of this file */
|
||||
DWORD WINAPI __stdcall decode(void *arg);
|
||||
|
||||
char lastfn[MAX_PATH+1] = {0}; /* name of the currently playing file */
|
||||
short sample_buffer[576*2*2]; /* 576 16-bit samples, stereo, possibly doubled in size for DSP */
|
||||
|
||||
/* hardcode these now, TODO will be configurable later */
|
||||
const double fade_seconds = 10.0;
|
||||
const double loop_count = 2.0;
|
||||
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
HANDLE decode_thread_handle = INVALID_HANDLE_VALUE;
|
||||
int paused = 0;
|
||||
int decode_abort = 0;
|
||||
int decode_pos_ms = 0;
|
||||
int decode_pos_samples = 0;
|
||||
int stream_length_samples = 0;
|
||||
int fade_samples = 0;
|
||||
|
||||
/* stubs, we don't do anything fancy yet */
|
||||
void config(HWND hwndParent) {}
|
||||
void about(HWND hwndParent) {}
|
||||
void init() {}
|
||||
void quit() {}
|
||||
|
||||
/* we don't recognize protocols */
|
||||
int isourfile(char *fn) { return 0; }
|
||||
|
||||
/* request to start playing a file */
|
||||
int play(char *fn)
|
||||
{
|
||||
int max_latency;
|
||||
|
||||
|
||||
/* don't lose a pointer! */
|
||||
if (vgmstream) {
|
||||
/* TODO: this should either pop up an error box or close the file */
|
||||
return 1;
|
||||
}
|
||||
/* open the stream, set up */
|
||||
vgmstream = init_vgmstream(fn);
|
||||
/* were we able to open it? */
|
||||
if (!vgmstream) {
|
||||
return 1;
|
||||
}
|
||||
/* will we be able to play it? */
|
||||
if (vgmstream->channels <= 0 || vgmstream->channels > 2) {
|
||||
/* TODO: > 2 channels is not unheard of, we should probably complain */
|
||||
close_vgmstream(vgmstream);
|
||||
vgmstream=NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Remember that name, friends! */
|
||||
strncpy(lastfn,fn,MAX_PATH);
|
||||
|
||||
/* open the output plugin */
|
||||
max_latency = input_module.outMod->Open(vgmstream->sample_rate,vgmstream->channels,
|
||||
16, 0, 0);
|
||||
/* were we able to open it? */
|
||||
if (max_latency < 0) {
|
||||
close_vgmstream(vgmstream);
|
||||
vgmstream=NULL;
|
||||
}
|
||||
|
||||
/* Set info display */
|
||||
/* TODO: actual bitrate */
|
||||
input_module.SetInfo(100,vgmstream->sample_rate,vgmstream->channels,1);
|
||||
|
||||
/* setup visualization */
|
||||
input_module.SAVSAInit(max_latency,vgmstream->sample_rate);
|
||||
input_module.VSASetInfo(vgmstream->sample_rate,vgmstream->channels);
|
||||
|
||||
decode_abort = 0;
|
||||
decode_pos_ms = 0;
|
||||
decode_pos_samples = 0;
|
||||
paused = 0;
|
||||
stream_length_samples = get_vgmstream_play_samples(loop_count,fade_seconds,vgmstream);
|
||||
fade_samples = fade_seconds * vgmstream->sample_rate;
|
||||
|
||||
decode_thread_handle = CreateThread(
|
||||
NULL, /* handle cannot be inherited */
|
||||
0, /* stack size, 0=default */
|
||||
decode, /* thread start routine */
|
||||
NULL, /* no parameter to start routine */
|
||||
0, /* run thread immediately */
|
||||
NULL); /* don't keep track of the thread id */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* pausing... */
|
||||
void pause() { paused=1; input_module.outMod->Pause(1); }
|
||||
void unpause() {paused=0; input_module.outMod->Pause(0); }
|
||||
int ispaused() { return paused; }
|
||||
|
||||
/* stop playback */
|
||||
void stop() {
|
||||
if (decode_thread_handle != INVALID_HANDLE_VALUE) {
|
||||
decode_abort=1;
|
||||
|
||||
/* arbitrary wait length */
|
||||
if (WaitForSingleObject(decode_thread_handle,1000) == WAIT_TIMEOUT) {
|
||||
/* TODO: error? */
|
||||
TerminateThread(decode_thread_handle,0);
|
||||
}
|
||||
CloseHandle(decode_thread_handle);
|
||||
decode_thread_handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
if (vgmstream) {
|
||||
close_vgmstream(vgmstream);
|
||||
vgmstream=NULL;
|
||||
}
|
||||
|
||||
input_module.outMod->Close();
|
||||
input_module.SAVSADeInit();
|
||||
}
|
||||
|
||||
/* get current stream length */
|
||||
int getlength() {
|
||||
return stream_length_samples*1000L/vgmstream->sample_rate;
|
||||
}
|
||||
|
||||
/* get current output time */
|
||||
int getoutputtime() {
|
||||
return decode_pos_ms+(input_module.outMod->GetOutputTime()-input_module.outMod->GetWrittenTime());
|
||||
}
|
||||
|
||||
/* seek */
|
||||
void setoutputtime() {
|
||||
/* TODO: seeking */
|
||||
}
|
||||
|
||||
/* pass these commands through */
|
||||
void setvolume(int volume) { input_module.outMod->SetVolume(volume); }
|
||||
void setpan(int pan) { input_module.outMod->SetPan(pan); }
|
||||
|
||||
/* display information */
|
||||
int infoDlg(char *fn, HWND hwnd) {
|
||||
/* TODO: info box */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* retrieve information on this or possibly another file */
|
||||
void getfileinfo(char *filename, char *title, int *length_in_ms) {
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
/* nothin' */
|
||||
void eq_set(int on, char data[10], int preamp) {}
|
||||
|
||||
/* the decode thread */
|
||||
DWORD WINAPI __stdcall decode(void *arg) {
|
||||
while (!decode_abort) {
|
||||
|
||||
int samples_to_do;
|
||||
int l;
|
||||
if (decode_pos_samples+576>stream_length_samples)
|
||||
samples_to_do=stream_length_samples-decode_pos_samples;
|
||||
else
|
||||
samples_to_do=576;
|
||||
|
||||
l = (samples_to_do*vgmstream->channels*2)<<(input_module.dsp_isactive()?1:0);
|
||||
|
||||
if (samples_to_do == 0) {
|
||||
input_module.outMod->CanWrite(); /* ? */
|
||||
if (!input_module.outMod->IsPlaying()) {
|
||||
PostMessage(input_module.hMainWindow, /* message dest */
|
||||
WM_WA_MPEG_EOF, /* message id */
|
||||
0,0); /* no parameters */
|
||||
return 0;
|
||||
}
|
||||
Sleep(10);
|
||||
}
|
||||
else if (input_module.outMod->CanWrite() >= l) {
|
||||
/* let vgmstream do its thing */
|
||||
render_vgmstream(sample_buffer,samples_to_do,vgmstream);
|
||||
|
||||
/* fade! */
|
||||
if (vgmstream->loop_flag && fade_samples > 0) {
|
||||
int samples_into_fade = decode_pos_samples - (stream_length_samples - fade_samples);
|
||||
if (samples_into_fade + samples_to_do > 0) {
|
||||
int j,k;
|
||||
for (j=0;j<samples_to_do;j++,samples_into_fade++) {
|
||||
if (samples_into_fade > 0) {
|
||||
double fadedness = (double)(fade_samples-samples_into_fade)/fade_samples;
|
||||
for (k=0;k<vgmstream->channels;k++) {
|
||||
sample_buffer[j*vgmstream->channels+k] =
|
||||
sample_buffer[j*vgmstream->channels+k]*fadedness;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
input_module.SAAddPCMData((char*)sample_buffer,vgmstream->channels,16,decode_pos_ms);
|
||||
input_module.VSAAddPCMData((char*)sample_buffer,vgmstream->channels,16,decode_pos_ms);
|
||||
decode_pos_samples+=samples_to_do;
|
||||
decode_pos_ms=decode_pos_samples*1000L/vgmstream->sample_rate;
|
||||
if (input_module.dsp_isactive())
|
||||
l =input_module.dsp_dosamples(sample_buffer,samples_to_do,16,vgmstream->channels,vgmstream->sample_rate) *
|
||||
2 * vgmstream->channels;
|
||||
|
||||
input_module.outMod->Write((char*)sample_buffer,l);
|
||||
} /* if we can write enough */
|
||||
else Sleep(20);
|
||||
} /* main loop */
|
||||
return 0;
|
||||
}
|
||||
|
||||
In_Module input_module =
|
||||
{
|
||||
IN_VER,
|
||||
PLUGIN_DESCRIPTION,
|
||||
0, // hMainWindow
|
||||
0, // hDllInstance
|
||||
"ADX\0ADX Audio File\0",
|
||||
1, // is_seekable
|
||||
1, // uses output
|
||||
config,
|
||||
about,
|
||||
init,
|
||||
quit,
|
||||
getfileinfo,
|
||||
infoDlg,
|
||||
isourfile,
|
||||
play,
|
||||
pause,
|
||||
unpause,
|
||||
ispaused,
|
||||
stop,
|
||||
getlength,
|
||||
getoutputtime,
|
||||
setoutputtime,
|
||||
setvolume,
|
||||
setpan,
|
||||
0,0,0,0,0,0,0,0,0, // vis stuff
|
||||
0,0, // dsp
|
||||
eq_set,
|
||||
NULL, // setinfo
|
||||
0 // out_mod
|
||||
};
|
||||
|
||||
__declspec( dllexport ) In_Module * winampGetInModule2()
|
||||
{
|
||||
return &input_module;
|
||||
}
|
||||
|
52
winamp/out.h
Normal file
52
winamp/out.h
Normal file
@ -0,0 +1,52 @@
|
||||
#define OUT_VER 0x10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int version; // module version (OUT_VER)
|
||||
char *description; // description of module, with version string
|
||||
int id; // module id. each input module gets its own. non-nullsoft modules should
|
||||
// be >= 65536.
|
||||
|
||||
HWND hMainWindow; // winamp's main window (filled in by winamp)
|
||||
HINSTANCE hDllInstance; // DLL instance handle (filled in by winamp)
|
||||
|
||||
void (*Config)(HWND hwndParent); // configuration dialog
|
||||
void (*About)(HWND hwndParent); // about dialog
|
||||
|
||||
void (*Init)(); // called when loaded
|
||||
void (*Quit)(); // called when unloaded
|
||||
|
||||
int (*Open)(int samplerate, int numchannels, int bitspersamp, int bufferlenms, int prebufferms);
|
||||
// returns >=0 on success, <0 on failure
|
||||
// NOTENOTENOTE: bufferlenms and prebufferms are ignored in most if not all output plug-ins.
|
||||
// ... so don't expect the max latency returned to be what you asked for.
|
||||
// returns max latency in ms (0 for diskwriters, etc)
|
||||
// bufferlenms and prebufferms must be in ms. 0 to use defaults.
|
||||
// prebufferms must be <= bufferlenms
|
||||
|
||||
void (*Close)(); // close the ol' output device.
|
||||
|
||||
int (*Write)(char *buf, int len);
|
||||
// 0 on success. Len == bytes to write (<= 8192 always). buf is straight audio data.
|
||||
// 1 returns not able to write (yet). Non-blocking, always.
|
||||
|
||||
int (*CanWrite)(); // returns number of bytes possible to write at a given time.
|
||||
// Never will decrease unless you call Write (or Close, heh)
|
||||
|
||||
int (*IsPlaying)(); // non0 if output is still going or if data in buffers waiting to be
|
||||
// written (i.e. closing while IsPlaying() returns 1 would truncate the song
|
||||
|
||||
int (*Pause)(int pause); // returns previous pause state
|
||||
|
||||
void (*SetVolume)(int volume); // volume is 0-255
|
||||
void (*SetPan)(int pan); // pan is -128 to 128
|
||||
|
||||
void (*Flush)(int t); // flushes buffers and restarts output at time t (in ms)
|
||||
// (used for seeking)
|
||||
|
||||
int (*GetOutputTime)(); // returns played time in MS
|
||||
int (*GetWrittenTime)(); // returns time written in MS (used for synching up vis stuff)
|
||||
|
||||
} Out_Module;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user