home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 April / PCWorld_2007-04_cd.bin / audio-video / kmplayer / kmp.exe / SDK / Exam_C / DSP_TestC.cpp next >
C/C++ Source or Header  |  2002-12-11  |  9KB  |  333 lines

  1. // DSP_TestC.cpp : Defines the entry point for the DLL application.
  2. //
  3.  
  4. #include <stdlib.h>
  5. #include <windows.h>
  6. #include "stdafx.h"
  7. #include "..\KMPPlgIn.h"
  8.  
  9.  
  10. winampDSPHeader _winampDSPHeader;
  11. winampDSPModule _winampDSPModule;
  12.  
  13. kmpDSPHeader _kmpDSPHeader;
  14. kmpDSPModule _kmpDSPModule[3];
  15.  
  16.  
  17. winampDSPModule *getwinampDSPModule(int num)
  18. {
  19.  if(num==0) return &_winampDSPModule;
  20.  else return NULL;
  21.  }
  22.  
  23. int rand() // ║±┴╓╛≤ C┐í╝¡ ╖Ñ┤²║»╝÷╕ª ╕°╕╕╡Θ╛ε╝¡... ▒╫│╔ C┤┬ ╡╟┤┬╡Ñ 
  24. {  // ┐╓ └⌐╡╡┐∞┐í╝¡┤┬ ╛╚╡╚┤┬░┼╛▀... ╛╦╛╞╝¡ ░φ├─ ╜ß╝╝┐Σ...
  25.      
  26.     return 1;
  27. }
  28.  
  29. int ModifyAudio(winampDSPModule *this_mod,short int *samples,
  30.   int numsamples,int bps,int nch,int srate)
  31. {
  32.  int i,rr,aa;
  33.  unsigned short *ps;
  34.  unsigned char *pb;
  35.  
  36.  // ║±┴╓╛≤ C┐í╝¡ ╖ú┤²║»╝÷╕ª ╕°╕╕╡Θ░┘│╫...
  37.  
  38.  if (bps==16) {
  39.     ps=(unsigned short *)samples;
  40.     if (nch==2) {
  41.         for(i=0;i<numsamples;i++) {
  42.             rr=rand() % (0x8fff / 5);
  43.             aa=*ps+rr;
  44.             if(aa<-32768) aa=-32768;
  45.             else if(aa>32767) aa=32767;
  46.             *ps=aa;
  47.             ps++;
  48.             rr=rand() % (0x8fff / 5);
  49.             aa=*ps+rr;
  50.             if(aa<-32768) aa=-32768;
  51.             else if(aa>32767) aa=32767;
  52.             *ps=aa;
  53.             ps++;
  54.         }
  55.     }
  56.     else if(nch==1) {
  57.         for(i=0;i<numsamples;i++) {
  58.             rr=rand() % (0x8fff / 5);
  59.             aa=*ps+rr;
  60.             if(aa<-32768) aa=-32768;
  61.             else if(aa>32767) aa=32767;
  62.             *ps=aa;
  63.             ps++;
  64.         }
  65.     }
  66.  }
  67.  else if(bps==8) {
  68.     pb=(unsigned char *)samples;
  69.     if(nch==2) {
  70.         for(i=0;i<numsamples;i++) {
  71.             rr=rand() % (0x7f / 5);
  72.             aa=*pb+rr;
  73.             if(aa<0) aa=0;
  74.             else if(aa>255) aa=255;
  75.             *pb=aa;
  76.             pb++;
  77.             rr=rand() % (0x7f / 5);
  78.             aa=*pb+rr;
  79.             if(aa<0) aa=0;
  80.             else if(aa>255) aa=255;
  81.             *pb=aa;
  82.             pb++;
  83.         }
  84.     }
  85.     else if(nch==1) {
  86.         for(i=0;i<numsamples;i++) {
  87.             rr=rand() % (0x7f / 5);
  88.             aa=*pb+rr;
  89.             if(aa<0) aa=0;
  90.             else if(aa>255) aa=255;
  91.             *pb=aa;
  92.             pb++;
  93.         }
  94.     }
  95.  }
  96.  return numsamples;
  97. }
  98.  
  99. kmpDSPModule *getkmpDSPModule(int num)
  100. {
  101.  if(num==0) return &_kmpDSPModule[0];
  102.  else if(num==1) return &_kmpDSPModule[1];
  103.  else if(num==2) return &_kmpDSPModule[2];
  104.  else return NULL;
  105. }
  106.  
  107. int ModifyVideoHori(kmpDSPModule *this_mod,kmpYV12Image *image,int ewidth)
  108. {
  109.  int i,j;
  110.  unsigned char *ps,*pd;
  111.  
  112.  ps=image->y_plain;
  113.  for(i=0;i<image->Height;i++) {
  114.    pd=ps;
  115.    for(j=0;j<ewidth;j++) {
  116.      if ((j & 3)==0) *pd=0;
  117.      pd++;
  118.    }
  119.    ps=ps+image->Width;
  120.  }
  121.  return 0;
  122. }
  123.  
  124. int ModifyVideoVert(kmpDSPModule *this_mod,kmpYV12Image *image,int ewidth)
  125. {
  126.  int i;
  127.  unsigned char *pp;
  128.  
  129.  pp=image->y_plain;
  130.  for(i=0;i<image->Height;i++) {
  131.    if ((i & 3)==0) memset(pp,0,ewidth);
  132.    pp=pp+image->Width;
  133.  }
  134.  return 0;
  135. }
  136.  
  137. /*
  138.  
  139. int TimeDisplay(kmpDSPModule *this_mod,kmpYV12Image *image,int ewidth)
  140. {
  141.  HWND han;
  142.  HDC comhdc,hdc;
  143.  HBITMAP hbitmap;
  144.  HBRUSH hbrush;
  145.  RECT rr;
  146.  SYSTEMTIME time;
  147.  char buf[200];
  148.  void *dib;
  149.  BITMAPINFO bitmapinfo;
  150.  kmpYV12Image *Img;
  151.  
  152.  han=GetDesktopWindow();
  153.  hdc=GetDC(han);
  154.  comhdc=CreateCompatibleDC(hdc);
  155.  SetRect(&rr,0,0,image->Width,20);
  156.  hbitmap=CreateCompatibleBitmap(hdc,rr.right,rr.bottom);
  157.  hbrush=CreateSolidBrush(RGB(0,0,0));
  158.  SelectObject(comhdc,hbrush);
  159.  SelectObject(comhdc,hbitmap);
  160.  FillRect(comhdc,&rr,hbrush);
  161.  SetTextColor(comhdc,RGB(255,255,255));
  162.  SetBkMode(comhdc,TRANSPARENT);
  163.  GetSystemTime(&time);
  164.  sprintf(buf,"%02d:%02d:%02d",time.wHour,time.wMinute,time.wSecond);
  165.  TextOut(comhdc,1,1,buf,strlen(buf));
  166.  dib=malloc(rr.right*rr.bottom*4);
  167.  memset((void *)&bitmapinfo,0,sizeof(bitmapinfo));
  168.  bitmapinfo.bmiHeader.biBitCount=32;
  169.  bitmapinfo.bmiHeader.biHeight=rr.bottom;
  170.  bitmapinfo.bmiHeader.biWidth=rr.right;
  171.  bitmapinfo.bmiHeader.biPlanes=1;
  172.  bitmapinfo.bmiHeader.biSize=sizeof(bitmapinfo.bmiHeader);
  173.  bitmapinfo.bmiHeader.biSizeImage=rr.right*rr.bottom*4;
  174.  GetDIBits(comhdc,hbitmap,0,rr.bottom,dib,&bitmapinfo,DIB_RGB_COLORS);
  175.  DeleteObject(hbrush);
  176.  DeleteObject(hbitmap);
  177.  DeleteDC(comhdc);
  178.  ReleaseDC(han,hdc);
  179.  // ╛╞└╠░í│¬ DIB╕ª ╕╕╡Θ▒Γ └º╟╪╝¡ └╠╖╕░╘ ╕╣└╠ ╟╪╛▀ ╡╟│¬....
  180.  // └╜... ┐¬╜├ C┤┬ ║╣└Γ╟╪...
  181.  // ┴°┬Ñ ║╣└█╟╪...
  182.  // ╛╞┴≈ ├╓└√╚¡ ╡╟┴÷ ╛╩╛╥╜└┤╧┤┘.
  183.  // ░φ╝÷┤╘╡Θ└║ ╛╦╛╞╝¡ ░φ├─ ╛▓╝╝┐Σ...
  184.  
  185.  if(this_mod->ImageProcessor!=NULL) {
  186.      this_mod->ImageProcessor->kmpAllocYV12Image(rr.right,rr.bottom,&Img);
  187.      this_mod->ImageProcessor->kmpRGB32ToYV12(dib,rr.right,rr.bottom,Img);
  188.      this_mod->ImageProcessor->kmpYV12BlendTransDraw(Img,image,&rr,0,0,200);
  189.      this_mod->ImageProcessor->kmpFreeYV12Image(&Img);
  190.  }
  191.  free(dib);
  192.  
  193.  return 0;
  194. }
  195. */
  196.  
  197. int TimeDisplay(kmpDSPModule *this_mod,kmpYV12Image *image,int ewidth) 
  198. //HWND han; 
  199. HDC comhdc,hdc; 
  200. HBITMAP hbitmap; 
  201. HBRUSH hbrush; 
  202. RECT rr; 
  203. SYSTEMTIME time; 
  204. char buf[200]; 
  205. void *dib; 
  206. BITMAPINFO bitmapinfo; 
  207. kmpYV12Image *Img; 
  208.  
  209. // DesktopDC╕ª ╛≥╛ε│┐..// 
  210. hdc=GetDC(NULL); 
  211. comhdc=CreateCompatibleDC(hdc); 
  212. SetRect(&rr,0,0,image->Width,20); 
  213. // CreateDIBSection└╗ ╟╧▒Γ └º╟╤ ╝│┴ñ // 
  214. memset((void *)&bitmapinfo,0,sizeof(bitmapinfo)); 
  215. bitmapinfo.bmiHeader.biBitCount=32; 
  216. bitmapinfo.bmiHeader.biHeight=rr.bottom; 
  217. bitmapinfo.bmiHeader.biWidth=rr.right; 
  218. bitmapinfo.bmiHeader.biPlanes=1; 
  219. bitmapinfo.bmiHeader.biSize=sizeof(bitmapinfo.bmiHeader); 
  220. bitmapinfo.bmiHeader.biSizeImage=rr.right*rr.bottom*4; 
  221. bitmapinfo.bmiHeader.biCompression   = BI_RGB; 
  222. // CreateDIBSection└║ DDB(HBITMAP)╟╧░φ DIB└╗ ╡┐╜├┐í ╗²╝║╟╤┤┘.// 
  223. hbitmap= CreateDIBSection(hdc, &bitmapinfo, DIB_RGB_COLORS, 
  224. &dib, NULL, NULL); 
  225. HBITMAP hOldBitmap = (HBITMAP)SelectObject(comhdc, hbitmap); 
  226.  
  227. // └╠╣╠┴÷╕ª ├│╕«╟╧┤┬ ░·┴ñ └╙.. // 
  228. hbrush=CreateSolidBrush(RGB(0,0,0)); 
  229. FillRect(comhdc,&rr,hbrush); 
  230. DeleteObject(hbrush); 
  231. SetTextColor(comhdc,RGB(255,255,255)); 
  232. SetBkMode(comhdc,TRANSPARENT); 
  233. GetSystemTime(&time); 
  234. sprintf(buf,"%02d:%02d:%02d",time.wHour,time.wMinute,time.wSecond); 
  235. TextOut(comhdc,1,1,buf,strlen(buf)); 
  236. //dib=malloc(rr.right*rr.bottom*4); 
  237. //GetDIBits(comhdc,hbitmap,0,rr.bottom,dib,&bitmapinfo,DIB_RGB_COLORS); 
  238. //DeleteObject(hbitmap); <-- DeleteObject╕ª ╟╧╕Θ dib▒ε┴÷ ╛°╛ε┴ⁿ...// 
  239. SelectObject(comhdc, hOldBitmap); 
  240. DeleteDC(comhdc); 
  241. ReleaseDC(NULL,hdc); 
  242. // ╛╞└╠░í│¬ DIB╕ª ╕╕╡Θ▒Γ └º╟╪╝¡ └╠╖╕░╘ ╕╣└╠ ╟╪╛▀ ╡╟│¬.... 
  243. // └╜... ┐¬╜├ C┤┬ ║╣└Γ╟╪... 
  244. // ┴°┬Ñ ║╣└█╟╪... 
  245. // ╛╞┴≈ ├╓└√╚¡ ╡╟┴÷ ╛╩╛╥╜└┤╧┤┘. 
  246. // ░φ╝÷┤╘╡Θ└║ ╛╦╛╞╝¡ ░φ├─ ╛▓╝╝┐Σ... 
  247.  
  248. if(this_mod->ImageProcessor!=NULL) { 
  249.     this_mod->ImageProcessor->kmpAllocYV12Image(rr.right,rr.bottom,&Img); 
  250.     this_mod->ImageProcessor->kmpRGB32ToYV12(dib,rr.right,rr.bottom,Img); 
  251.     this_mod->ImageProcessor->kmpYV12BlendTransDraw(Img,image,&rr,0,0,200); 
  252.     this_mod->ImageProcessor->kmpFreeYV12Image(&Img); 
  253. //free(dib); <--- ┤δ╜┼┐í DeleteObject╖╬ dib▒ε┴÷ ┴÷┐≥// 
  254. DeleteObject(hbitmap); 
  255.  
  256. return 0; 
  257.  
  258.  
  259.  
  260. winampDSPHeader *winampDSPGetHeader2() // ┐└╡≡┐└╟├╖»▒╫└╬ Export╟╘╝÷
  261. {
  262.  // For Audio
  263.  _winampDSPHeader.version=0x20;
  264.  _winampDSPHeader.description="Test for Audio Plugin K-MultimediaPlayer";
  265.  _winampDSPHeader.getModule=&getwinampDSPModule;
  266.  
  267.  _winampDSPModule.description="Add noise v0.001 for K-MultimediaPlayer";
  268.  _winampDSPModule.hwndParent=0;
  269.  _winampDSPModule.hDllInstance=0;
  270.  _winampDSPModule.Config=NULL;
  271.  _winampDSPModule.Init=NULL;
  272.  _winampDSPModule.ModifySamples=ModifyAudio;
  273.  _winampDSPModule.Quit=NULL;
  274.  _winampDSPModule.userData=NULL;
  275.  
  276.  return &_winampDSPHeader;
  277. }
  278.  
  279.  
  280. kmpDSPHeader *kmpDSPGetHeader2() //║±╡≡┐└ ╟├╖»▒╫└╬ Export╟╘╝÷
  281. {
  282.  // For Video
  283.  _kmpDSPHeader.version=0x20;
  284.  _kmpDSPHeader.description="Test for Video Plugin K-MultimediaPlayer";
  285.  _kmpDSPHeader.getModule=getkmpDSPModule;
  286.  
  287.  _kmpDSPModule[0].description="Hori Scanline v0.001 for K-MultimediaPlayer";
  288.  _kmpDSPModule[0].hwndParent=0;
  289.  _kmpDSPModule[0].hDllInstance=0;
  290.  _kmpDSPModule[0].Config=NULL;
  291.  _kmpDSPModule[0].Init=NULL;
  292.  _kmpDSPModule[0].BeforeModifySamples=NULL;
  293.  _kmpDSPModule[0].AfterModifySamples=ModifyVideoHori;
  294.  _kmpDSPModule[0].Quit=NULL;
  295.  _kmpDSPModule[0].userData=NULL;
  296.  
  297.  _kmpDSPModule[1].description="Hori Scanline v0.001 for K-MultimediaPlayer";
  298.  _kmpDSPModule[1].hwndParent=0;
  299.  _kmpDSPModule[1].hDllInstance=0;
  300.  _kmpDSPModule[1].Config=NULL;
  301.  _kmpDSPModule[1].Init=NULL;
  302.  _kmpDSPModule[1].BeforeModifySamples=NULL;
  303.  _kmpDSPModule[1].AfterModifySamples=ModifyVideoVert;
  304.  _kmpDSPModule[1].Quit=NULL;
  305.  _kmpDSPModule[1].userData=NULL;
  306.  
  307.  _kmpDSPModule[2].description="Time Display v0.001 for K-MultimediaPlayer";
  308.  _kmpDSPModule[2].hwndParent=0;
  309.  _kmpDSPModule[2].hDllInstance=0;
  310.  _kmpDSPModule[2].Config=NULL;
  311.  _kmpDSPModule[2].Init=NULL;
  312.  _kmpDSPModule[2].BeforeModifySamples=NULL;
  313.  _kmpDSPModule[2].AfterModifySamples=TimeDisplay;
  314.  _kmpDSPModule[2].Quit=NULL;
  315.  _kmpDSPModule[2].userData=NULL;
  316.  
  317.  return &_kmpDSPHeader;
  318. }
  319.  
  320.  
  321.  
  322. BOOL APIENTRY DllMain( HANDLE hModule, 
  323.                        DWORD  ul_reason_for_call, 
  324.                        LPVOID lpReserved
  325.                      )
  326. {
  327.     return TRUE;
  328. }
  329.  
  330.