Plugin echo pour winamp

Description

Plugin Echo pour Winamp.
Permet d'ajouter de l'écho.
Une version plus complète bientot.
Testé avec Winamp 2.95
Compilé avec Visual C++ 6.0
Compiler et copier ou copier le fichier "dsp_test.dll" dans le répertoire de winamp --> C:\Program Files\Winamp\Plugins\

Source / Exemple :


#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#include "dsp.h"
#include "resource.h"

#define NB_ECHO_BUFFERS 10 // 

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

HWND echo_control_hwnd;

int quit_echo=0;

winampDSPModule *getModule(int which);

void config(struct winampDSPModule *this_mod);
int initecho(struct winampDSPModule *this_mod);
void quitecho(struct winampDSPModule *this_mod);
int modify_samples1(struct winampDSPModule *this_mod, short int *samples, int numsamples, int bps, int nch, int srate);

static BOOL CALLBACK echoProc (HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);

winampDSPHeader hdr = { DSP_HDRVER, "Nullsoft DSP demo v0.3 for Winamp 2", getModule };

int volume_general;
int gain_echo_L1;
int gain_echo_R1;
short echo1_actif = 1;

//****************************************************************************

winampDSPModule mod =
{
 "echo",
 NULL,	// hwndParent
 NULL,	// hDllInstance
 config,
 initecho,
 modify_samples1,
 quitecho
};

//****************************************************************************

#ifdef __cplusplus
extern "C" {
#endif

__declspec( dllexport ) winampDSPHeader *winampDSPGetHeader2()
{
 return &hdr;
}
#ifdef __cplusplus
}
#endif

//****************************************************************************

winampDSPModule *getModule(int which)
{
  switch (which)
   {
    case 0: return &mod;
    default:return NULL;
   }
}

//****************************************************************************

void config(struct winampDSPModule *this_mod)
{
 MessageBox(this_mod->hwndParent,"Rock'n'roll :)","Configuration",MB_OK);
}

//****************************************************************************

// initialisation du module
int initecho(struct winampDSPModule *this_mod)
{
 quit_echo=0;		
 ShowWindow((echo_control_hwnd=CreateDialog(this_mod->hDllInstance,MAKEINTRESOURCE(IDD_DIALOG1),this_mod->hwndParent,echoProc)),SW_SHOW); 
 return 0;
}

//****************************************************************************

// fonction quit du module
void quitecho(struct winampDSPModule *this_mod)
{
 if (this_mod == &mod)
  {
   quit_echo=1;
   if (echo_control_hwnd)
    {
     DestroyWindow(echo_control_hwnd);
     echo_control_hwnd=0;
    }
  }
}

//****************************************************************************

int modify_samples1(struct winampDSPModule *this_mod, short int *samples, int numsamples, int bps, int nch, int srate)
 {
  static short buffer[NB_ECHO_BUFFERS][4096];
  static int i,j;

  if (bps == 16 && nch == 2)
   {

    // mettre le bloc entrant dans le dernier bloc du buffer
    for (i = 0; i < numsamples*nch; i+=2)
     {
      buffer[NB_ECHO_BUFFERS-1][i]   = samples[i];   // voie gauche
      buffer[NB_ECHO_BUFFERS-1][i+1] = samples[i+1]; // voie droite
     }

    // calculer l'echo avec le premier bloc et le bloc entrant
    for (i = 0; i < numsamples*nch; i+=2)
     {
      samples[i]   = buffer[0][i]   * echo1_actif * gain_echo_L1/100 + buffer[NB_ECHO_BUFFERS-1][i];   // voie gauche
      samples[i+1] = buffer[0][i+1] * echo1_actif * gain_echo_R1/100 + buffer[NB_ECHO_BUFFERS-1][i+1]; // voie droite
     }

    // volume general
    for (i = 0; i < numsamples*nch; i+=2)
     {
      samples[i]   = samples[i]   * volume_general/100; // voie gauche
      samples[i+1] = samples[i+1] * volume_general/100; // voie droite
     } 

    // memoriser le bloc sortant
    for (i = 0; i < numsamples*nch; i+=2)
     {
      buffer[NB_ECHO_BUFFERS-1][i]   = samples[i];   // voie gauche
      buffer[NB_ECHO_BUFFERS-1][i+1] = samples[i+1]; // voie droite
     }

    // decaler tous les blocs vers la gauche pour laisser la place au prochain bloc entrant    
    for (j = 0; j < NB_ECHO_BUFFERS-1; j++)    
     {
      for (i = 0; i < numsamples*nch; i+=2)
       {
        buffer[j][i]   = buffer[j+1][i];   // voie gauche
        buffer[j][i+1] = buffer[j+1][i+1]; // voie droite
       }
     }
   }

  return numsamples;
}

//****************************************************************************

// procedure fenetre echo
static BOOL CALLBACK echoProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  
  if (uMsg == WM_DESTROY)
   {
   }
   
  if (uMsg == WM_COMMAND)
   {
    if(wParam == IDC_CHECK1)
     {
      if (IsDlgButtonChecked(hwndDlg , IDC_CHECK1) == BST_UNCHECKED)
       {
        SetDlgItemText(hwndDlg, IDC_CHECK1, "OFF");
        echo1_actif = 0;
       }
      if (IsDlgButtonChecked(hwndDlg , IDC_CHECK1) == BST_CHECKED)
       {
        SetDlgItemText(hwndDlg, IDC_CHECK1, "ON");
        echo1_actif = 1;
       }
     }
   }

  if (uMsg == WM_INITDIALOG)
   {    
    SetWindowPos(hwndDlg, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE); // positionner la fenetre en haut a gauche
        
    CheckDlgButton(hwndDlg, IDC_CHECK1, TRUE); // echo actif au demarrage
    SetDlgItemText(hwndDlg, IDC_CHECK1, "ON");

    SendDlgItemMessage(hwndDlg,IDC_SLIDER_VOLUME_GENERAL,TBM_SETRANGEMAX,0,100); // volume general a fond
    SendDlgItemMessage(hwndDlg,IDC_SLIDER_VOLUME_GENERAL,TBM_SETRANGEMIN,0,0);
    SendDlgItemMessage(hwndDlg,IDC_SLIDER_VOLUME_GENERAL,TBM_SETPOS,1,0);
    volume_general = 100-SendDlgItemMessage(hwndDlg,IDC_SLIDER_VOLUME_GENERAL,TBM_GETPOS,0,0);
     {
      char str[8];
      wsprintf(str,"%d",volume_general);
      SetDlgItemText(hwndDlg,IDC_STATIC_VOLUME_GENERAL,str);
     }

    SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINL1,TBM_SETRANGEMAX,0,100);
    SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINL1,TBM_SETRANGEMIN,0,0);
    SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINL1,TBM_SETPOS,1,50);
    gain_echo_L1 = 100-SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINL1,TBM_GETPOS,0,0);
     {
      char str[8];
      wsprintf(str,"%d",gain_echo_L1);
      SetDlgItemText(hwndDlg,IDC_STATIC_GAINL1,str);
     }

    SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINR1,TBM_SETRANGEMAX,0,100);
    SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINR1,TBM_SETRANGEMIN,0,0);
    SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINR1,TBM_SETPOS,1,50);
    gain_echo_R1 = 100-SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINR1,TBM_GETPOS,0,0);
     {
      char str[8];
      wsprintf(str,"%d",gain_echo_R1);
      SetDlgItemText(hwndDlg,IDC_STATIC_GAINR1,str);
     }
   }

  if (uMsg == WM_VSCROLL)
   {
    volume_general = 100-SendDlgItemMessage(hwndDlg,IDC_SLIDER_VOLUME_GENERAL,TBM_GETPOS,0,0);
     {
      char str[8];
      wsprintf(str,"%d",volume_general);
      SetDlgItemText(hwndDlg,IDC_STATIC_VOLUME_GENERAL,str);
     }    
    gain_echo_L1 = 100-SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINL1,TBM_GETPOS,0,0);
     {
      char str[8];
      wsprintf(str,"%d",gain_echo_L1);
      SetDlgItemText(hwndDlg,IDC_STATIC_GAINL1,str);
     }
    gain_echo_R1 = 100-SendDlgItemMessage(hwndDlg,IDC_SLIDER_GAINR1,TBM_GETPOS,0,0);
     {
      char str[8];
      wsprintf(str,"%d",gain_echo_R1);
      SetDlgItemText(hwndDlg,IDC_STATIC_GAINR1,str);
     }
   }

return 0;
}

//****************************************************************************

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.