winamp � plugin � �용한 프로그래�
winamp � 경우 다양한 plugin 를 지�한다.
input pluginì�€ 해당 í™”ì�¼ì�„ ì�½ì–´ë“œë¦¬ê³ output plugin 으로ì�˜ ì¶œë ¥ì�„ 소스를 ì œê³µí•œë‹¤. output plugin ì�€ ì¶œë ¥ 소스를 사운드카드나 하드 디스í�¬ë¡œì�˜ ì¶œë ¥ì�„ 관장한다. ì�´ 중간ì—� DSP 와 Visual plugin ì�´ callback 으로 결과물ì�„ ë°›ì�€ë’¤ 변수들ì�„ ì�´ìš©í•œë‹¤.
ì�´ë“¤ì�„ 잘 ì�´ìš©í•˜ë©´ 복잡한 ACM ê´€ë ¨ 처리 ì—†ì�´ 훌ë¥í•œ 확장성ì�˜ í”Œë ˆì�´ì–´ë¥¼ 만들 수 있ì�„ 것ì�´ë‹¤.
Simple Code ¶
컴파ì�¼í•˜ë ¤ë©´ in2.h 와 Out.h ê°€ 필요하다. ì�´ëŠ” http://www.winamp.com/nsdn/ ì—�서 Winamp SDK를 다운받는다.
~cpp
#include <windows.h>
#include <stdio.h>
#include "in2.h"
// define procedures, that'll be found in a .DLL
typedef In_Module* (*INHDRPROC)(void);
typedef Out_Module* (*OUTHDRPROC)(void);
// dsp-functions
int dsp_donothing(short int *, int cnt, int, int, int) {
return cnt;
}
int dsp_isactive() {
return 0;
}
// other functions, needed to get it to work
void SAVSAInit(int maxlatency_in_ms, int srate){
}
void SAVSADeInit(){
}
void SAAddPCMData(void *PCMData, int nch, int bps, int timestamp){
// printf ("%d,%d,%d\n", nch,bps,timestamp);
}
int SAGetMode(){
return 0;
}
void SAAdd(void *data, int timestamp, int csa){
}
void VSAAddPCMData(void *PCMData, int nch, int bps, int timestamp){
// printf ("%d,%d,%d\n", nch,bps,timestamp);
}
int VSAGetMode(int *specNch, int *waveNch) {
*specNch = *waveNch = 0;
return 0;
}
void VSAAdd(void *data, int timestamp){
}
void VSASetInfo(int nch, int srate){
}
void SetInfo(int bitrate, int srate, int stereo, int synched){
}
void playFile() {
// 플러그�� DLL들� load 하는 부분.
HINSTANCE hout = LoadLibrary("out_wave.dll");
HINSTANCE hin = LoadLibrary("in_vorbis.dll");
// 모듈 ê´€ë ¨ í�¬ì�¸í„° 얻어오는 부분
INHDRPROC ihp = (INHDRPROC)GetProcAddress(hin,"winampGetInModule2");
OUTHDRPROC ohp = (OUTHDRPROC)GetProcAddress(hout,"winampGetOutModule");
// Mapping.
In_Module* in = ihp();
Out_Module* out = ohp();
// ë²„ì „ì�´ 다른 경우ì—� 대한 처리.
if (in->version != IN_VER || out->version != OUT_VER)
{
FreeLibrary(hout);
FreeLibrary(hin);
return;
}
// ì�´ 프로그램ì�€ console mode 기반ì�´ë‹¤. 그러므로 window ê´€ë ¨ 셋팅ì�€ NULL.
out->hMainWindow = NULL;
out->hDllInstance = hout;
in->hMainWindow = NULL;
in->hDllInstance = hin;
if (in->UsesOutputPlug)
{
in->outMod = out;
}
// 아� 파악 안� 부분. input plugin 과 Visual plugin 연결부분�� ��.
// 함수í�¬ì�¸í„°ë“¤ì�„ ì �ì ˆí•˜ê²Œ 매핑해준다.
// 여기서는 화면 ì¶œë ¥ 부분ì�´ 없으므로 비어있는 callback 함수를 만들어서 연결해준다.
// 추후ì—� Visualization 부분ì�„ 만들때는 ì‹¤ì œ 함수부분ì�„ ì�´ìš©í•˜ê²Œ ë� 것ì�´ë‹¤.
in->SAVSAInit = SAVSAInit;
in->SAVSADeInit = SAVSADeInit;
in->SAAdd = SAAdd;
in->SAGetMode = SAGetMode;
in->SAAddPCMData = SAAddPCMData;
in->VSAAddPCMData = VSAAddPCMData;
in->VSAGetMode = VSAGetMode;
in->VSAAdd = VSAAdd;
in->VSASetInfo = VSASetInfo;
// DSP Plugin 부분. ì—시 위와 비슷한 ë§¥ë�½ì�¼ë“¯.
in->dsp_dosamples = dsp_donothing;
in->dsp_isactive = dsp_isactive;
in->SetInfo = SetInfo;
// 플러그� 초기화.
out->Init();
in->Init();
char playFile[256] = "garden.ogg";
printf ("%d \n", in->version); // 플러그ì�¸ ë²„ì „ì�´ ì¶œë ¥
printf ("%s \n", in->description); // 플러그ì�¸ 설명ì�´ ì¶œë ¥
printf ("%s \n", in->FileExtensions); // 해당 플러그�� 지�하는 확장�가 나옴.
// if playing starts correctly
if (!in->Play(playFile))
{
// 볼륨 & panning (좌 ìš° balance) ì¡°ì •.
in->SetVolume(255);
in->SetPan(0);
//int x = 1,len = in->GetLength();
//for (;x=1 && in->GetOutputTime()<len;) Sleep(100);
for (int i=0;i<10000;i++) {
printf(" %d ms\n", in->GetLength()); // ì „ì²´ play time (ms)
printf("current : %d ms\n", in->GetOutputTime()); // 진행중 play time (ms)
Sleep(1000); // ê°� plugin ì—�서ì�˜ 작업ì�€ ë©€í‹°ìŠ¤ë ˆë“œë¡œ 비ë�™ê¸°ì �으로 ì�¼ì–´ë‚œë‹¤.
}
// when playing stops, terminate
in->Stop();
}
// un-init plugins
in->Quit();
out->Quit();
// dll 들 �용 완료.
FreeLibrary(hin);
FreeLibrary(hout);
}
void main() {
playFile();
}









