IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Filtre passe bande en Java


Sujet :

avec Java

  1. #1
    Membre du Club
    Homme Profil pro
    Architecte réseau
    Inscrit en
    Juillet 2011
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Architecte réseau
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2011
    Messages : 43
    Points : 43
    Points
    43
    Par défaut Filtre passe bande en Java
    Bonjour à tous,

    Pour affiner mon travail, je dois filtrer un signal (un fichier audio passé via un microphone) à l'aide d'un filtre passe bande. J'ai du mal à mettre ça en place, malgré toutes les explications que j'ai trouvé sur le net.

    Je travailles sur un projet de reconnaissance vocale en java, l'application marche très bien ...........mais seulement s'il y a pas de bruit, par contre dans un endroit où y a du vent, renflement... etc, la reconnaissance n'est pas vraiment au top.

    J'ai besoin de votre aide

    Merci

  2. #2
    Membre éprouvé

    Homme Profil pro
    Développeur J2EE Senior
    Inscrit en
    Mai 2008
    Messages
    419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur J2EE Senior
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Mai 2008
    Messages : 419
    Points : 900
    Points
    900
    Par défaut
    Salut

    Tout d'abord tout le monde n'est pas versé dans les filtres passe bande ici, donc un peu d'explication dans le genre "un signal audio est composé de sons à différentes fréquences, je veux éliminer tous les sons qui ont des fréquences inférieures à 5kHz ou supérieures à 15kHz" aiderait sans doute beaucoup les potentiels helpeurs


    A part ça ton énoncé est très vague, on ne sait pas avec quelles librairies tu travailles par exemple. Ni si ton problème est purement algorithmique, ou bien si tu ne comprends pas comment est modélisé le signal sonore, ou comment utiliser ta librairie, etc.


    L'idéal serait que tu nous montre un exemple de ce que tu arrives déjà à faire, en explicitant précisément ce qui te bloque
    Mes cours sur l'écosystème Java EE - N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Perso je ne sais pas ce qu'il te manque ...

    Mais je px te proposer un code java de filtrage du son qui marchait pas mal a l'epoque (repris d'a gauche a droite et réécris pour java (apparement on le retrouve ici mais il m'avait semblé que ca venait d'ailleurs)... bien entendu il va falloir le "brancher" au reste. Le code gere sample/sample je pense.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    double i1, i2, o1, o2;  /* temporary variables */
    		    double a0, a1, a2;  /* coefficients */
    		    double b0, b1, b2;  /* coefficients */
    		    double f;         /* last Frequency used */
    		    double q;         /* last Q used */
    		    double g;         /* last Gain used */
    		    long t;  /* last Type used /
     
    		    static int maxfilterunits=10;
     
    			double FilterCell(long Unit, double Input, double Frequency, double Q, double Gain, int Type)
    			{
    				/* --------------------------------------------------------------- */
    				double Output=0,S,omega,A,sn,cs,alpha,beta,temp1,temp2,temp3,temp4;
    				/* -- check if frequency, Q, gain or type has changed.. and, if so, update coefficients */
    				if ( ( Frequency != f ) || ( Q != q ) || ( Gain != g ) || ( Type != t ) ) {
    					f = Frequency; q = Q; g = Gain; t = Type; /* remember last frequency, q, gain and type */
    					switch (Type) {
    					case 0:                                               /* no filtering */
    						b0 = Math.pow( 10.0, Gain / 20.0 );               /* convert from dB to linear */
    						break;
    					case 1:                                               /* lowpass */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b1 = ( 1.0 - cs ) * a0 * Gain;
    						b0 = b1 * 0.5;
    						break;
    					case 2:                                               /* highpass */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b1 = -( 1.0 + cs ) * a0 * Gain;
    						b0 = -b1 * 0.5;
    						break;
    					case 3:                                               /* bandpass */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn =Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b0 = alpha * a0 * Gain;
    						break;
    					case 4:                                               /* notch */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b0 = a0 * Gain;
    						b1 = a1 * Gain;
    						break;
    					case 5:                                               /* lowshelf */
    						/* "shelf slope" 1.0 = max slope, because neither Q nor bandwidth is used in */
    						/* those filters (note: true only for lowshelf and highshelf, not peaking). */
    						S = 1.0; /* used only by lowshelf and highshelf */
    						A = Math.pow( 10.0 , ( Gain / 40.0 ) );                 /* Gain is expressed in dB */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						temp1 = A + 1.0; temp2 = A - 1.0; temp3 = temp1 * cs; temp4 = temp2 * cs;
    						beta = sn * Math.sqrt( ( A * A + 1.0 ) / S - temp2 * temp2 );
    						a0 = 1.0 / ( temp1 + temp4 + beta );
    						a1 = ( -2.0 * ( temp2 + temp3 ) ) * a0;
    						a2 = ( temp1 + temp4 - beta ) * a0;
    						b0 = ( A * ( temp1 - temp4 + beta ) ) * a0;
    						b1 = ( 2.0 * A * ( temp2 - temp3 ) ) * a0;
    						b2 = ( A * ( temp1 - temp4 - beta ) ) * a0;
    						break;
    					case 6:                                               /* highshelf */
    						/* "shelf slope" 1.0 = max slope, because neither Q nor bandwidth is used in */
    						/* those filters (note: true only for lowshelf and highshelf, not peaking). */
    						S = 1.0; /* used only by lowshelf and highshelf */
    						A = Math.pow( 10.0, ( Gain / 40.0 ) );                  /* Gain is expressed in dB */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						temp1 = A + 1.0; temp2 = A - 1.0; temp3 = temp1 * cs; temp4 = temp2 * cs;
    						beta = sn * Math.sqrt( ( A * A + 1.0 ) / S - temp2 * temp2 );
    						a0 = 1.0 / ( temp1 - temp4 + beta );
    						a1 = ( 2.0 * ( temp2 - temp3 ) ) * a0;
    						a2 = ( temp1 - temp4 - beta ) * a0;
    						b0 = ( A * ( temp1 + temp4 + beta ) ) * a0;
    						b1 = ( -2.0 * A * ( temp2 + temp3 ) ) * a0;
    						b2 = ( A * ( temp1 + temp4 - beta ) ) * a0;
    						break;
    					case 7:                                               /* peaking */
    						A = Math.pow( 10.0, ( Gain / 40.0 ) );                  /* Gain is expressed in dB */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						temp1 = alpha * A;
    						temp2 = alpha / A;
    						a0 = 1.0 / ( 1.0 + temp2 );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - temp2 ) * a0;
    						b0 = ( 1.0 + temp1 ) * a0;
    						b2 = ( 1.0 - temp1 ) * a0;
    						break;
    					}
    				}
    				/* -- filter loop: if you don't change the parameters of the filter dynamically, ~only this code will be executed. */
    				switch (Type) {
    				case 0:                                                  /* no filtering */
    					Output = b0*Input;
    					Output = Input;
    					break;
    				case 1:                                                  /* lowpass */
    				case 2:                                                  /* highpass */
    					Output = b0*Input + b1*i1 + b0*i2 - a1*o1 - a2*o2;
    					break;
    				case 3:                                                  /* bandpass */
    					Output = b0*Input - b0*i2 - a1*o1 - a2*o2;
    					break;
    				case 4:                                                  /* notch */
    					Output = b0*Input + b1*i1 + b0*i2 - a1*o1 - a2*o2;
    					break;
    				case 5:                                                  /* low shelving */
    				case 6:                                                  /* high shelving */
    					Output = b0*Input + b1*i1 + b2*i2 - a1*o1 - a2*o2;
    					break;
    				case 7:                                                  /* peaking */
    					Output = b0*Input + a1*i1 + b2*i2 - a1*o1 - a2*o2;
    					break;
    				}
    				o2=o1; o1=Output; i2=i1; i1=Input; /* update variables for recursion */
    				return(Output);
    			}
    Sinon il y'a aussi des librairies sonore un peu plus pro (genre Fmod) qui offre des DSP tout fait pour faire ce genre de choses...
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  4. #4
    Membre du Club
    Homme Profil pro
    Architecte réseau
    Inscrit en
    Juillet 2011
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Architecte réseau
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2011
    Messages : 43
    Points : 43
    Points
    43
    Par défaut
    Citation Envoyé par Aldian Voir le message
    Salut

    Tout d'abord tout le monde n'est pas versé dans les filtres passe bande ici, donc un peu d'explication dans le genre "un signal audio est composé de sons à différentes fréquences, je veux éliminer tous les sons qui ont des fréquences inférieures à 5kHz ou supérieures à 15kHz" aiderait sans doute beaucoup les potentiels helpeurs


    A part ça ton énoncé est très vague, on ne sait pas avec quelles librairies tu travailles par exemple. Ni si ton problème est purement algorithmique, ou bien si tu ne comprends pas comment est modélisé le signal sonore, ou comment utiliser ta librairie, etc.


    L'idéal serait que tu nous montre un exemple de ce que tu arrives déjà à faire, en explicitant précisément ce qui te bloque
    Salut

    Je ne connais rien en Traitement de signal, j'ai jamais fait cette matière à la fac.
    Pour faire simple : j'ai un code de reconnaissance vocale et je veux éliminer les sons de différents bruit ( vent, renflement ...); mais je sais pas quoi faire, ni quel algorithme utiliser, ni quelle librairie solliciter, je sais seulement que ça fait appel à des notion de Traitement de Signal.

    Merci

  5. #5
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Bah en theorie avec le bout de code que j'ai fillé tu t'en fous de connaitre le traitement de signal, faut juste lui faire confiance au code.

    Dans ton cas toi tu chercher le filtre numero 3 (BandPass). Apres il suffit de faire passer ce que ton micro envoye la dedans puis d'en faire ce que tu veux.
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  6. #6
    Membre régulier
    Inscrit en
    Janvier 2011
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 51
    Points : 71
    Points
    71
    Par défaut
    Tu dois tout de même te rendre compte que ton filtre ne purifiera pas totalement ton signal. Pour peu qui tu aies un parasites qui couvre durant un interval de temps toute ta plage de fréquences, tu ne pourras rien faire.
    Pour un exemple concret : Si un Kéké urbain a le malheur de passer avec son scooter pendant que tu enregistres, ta plage sera foutue durant quatre ou cinq secondes.

    Pour pouvoir savoir quel bruit tu peux dissocier des autres, je te conseille d'afficher ton fichier son avec des programmes retournant le spectrogramme du signal (un spectrogram est l'intensité de la présence d'une fréquence à un moment donné). Le spectrogram est aisément programmable dans d'autres langages de programmation tel que MATLAB où ça se résume à une fonction avec quelques paramètres.

    Voilà, j'espère que ces précisions t'aideront.

  7. #7
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    C'est vrai, il vaudrait mieux prototype avec matlab ou même LabView (module traitement de signal).
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  8. #8
    Membre éprouvé

    Homme Profil pro
    Développeur J2EE Senior
    Inscrit en
    Mai 2008
    Messages
    419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur J2EE Senior
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Mai 2008
    Messages : 419
    Points : 900
    Points
    900
    Par défaut
    Le code que te donne wax78 correspond si mes souvenirs sont bons à la modélisation d'un filtre passe bande d'ordre 1, ce qui devrait suffire (de toute manière l'ordre 2 et supérieur sont un chouia complexes. Donc voila le problème de l'algorithme réglé.

    En gros si tu considère que ton son en entrée est un tableau de fréquences, tu vas faire passer ces fréquences une à une dans l'algorithme, et si elles ne sont pas dans la bonne bande elles seront très amorties. C'est sans doute un peu moins bourrin que la méthode que j'avais suggérée de faire un test sur la fréquence et de gicler ce qui est inférieur à la borne inf ou supérieur à la borne sup.

    Par contre il te reste à déterminer les coefficients du filtre: Frequency, Q et Gain, dont l'algorithme a besoin. Et là, sans notions de traitement du signal ça va être dur. Je te conseille d'aller poser ce genre de question sur un forum d'électronique, tu as beaucoup plus de chances d'y trouver des gens calés sur le traitement du signal


    EDIT: par contre, comme l'a fait remarquer Samser, si des bruits parasites sont dans le spectre accepté, tu ne les filtrera pas de cette manière. Mais a priori tu ne dois pas être le premier à te poser cette problématique, tu devrait regarder comment font les autres
    Mes cours sur l'écosystème Java EE - N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  9. #9
    Membre du Club
    Homme Profil pro
    Architecte réseau
    Inscrit en
    Juillet 2011
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Architecte réseau
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2011
    Messages : 43
    Points : 43
    Points
    43
    Par défaut
    Citation Envoyé par wax78 Voir le message
    Perso je ne sais pas ce qu'il te manque ...

    Mais je px te proposer un code java de filtrage du son qui marchait pas mal a l'epoque (repris d'a gauche a droite et réécris pour java)... bien entendu il va falloir le "brancher" au reste. Le code gere sample/sample je pense.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    double i1, i2, o1, o2;  /* temporary variables */
    		    double a0, a1, a2;  /* coefficients */
    		    double b0, b1, b2;  /* coefficients */
    		    double f;         /* last Frequency used */
    		    double q;         /* last Q used */
    		    double g;         /* last Gain used */
    		    long t;  /* last Type used /
     
    		    static int maxfilterunits=10;
     
    			double FilterCell(long Unit, double Input, double Frequency, double Q, double Gain, int Type)
    			{
    				/* --------------------------------------------------------------- */
    				double Output=0,S,omega,A,sn,cs,alpha,beta,temp1,temp2,temp3,temp4;
    				/* -- check if frequency, Q, gain or type has changed.. and, if so, update coefficients */
    				if ( ( Frequency != f ) || ( Q != q ) || ( Gain != g ) || ( Type != t ) ) {
    					f = Frequency; q = Q; g = Gain; t = Type; /* remember last frequency, q, gain and type */
    					switch (Type) {
    					case 0:                                               /* no filtering */
    						b0 = Math.pow( 10.0, Gain / 20.0 );               /* convert from dB to linear */
    						break;
    					case 1:                                               /* lowpass */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b1 = ( 1.0 - cs ) * a0 * Gain;
    						b0 = b1 * 0.5;
    						break;
    					case 2:                                               /* highpass */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b1 = -( 1.0 + cs ) * a0 * Gain;
    						b0 = -b1 * 0.5;
    						break;
    					case 3:                                               /* bandpass */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn =Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b0 = alpha * a0 * Gain;
    						break;
    					case 4:                                               /* notch */
    						Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						a0 = 1.0 / ( 1.0 + alpha );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - alpha ) * a0;
    						b0 = a0 * Gain;
    						b1 = a1 * Gain;
    						break;
    					case 5:                                               /* lowshelf */
    						/* "shelf slope" 1.0 = max slope, because neither Q nor bandwidth is used in */
    						/* those filters (note: true only for lowshelf and highshelf, not peaking). */
    						S = 1.0; /* used only by lowshelf and highshelf */
    						A = Math.pow( 10.0 , ( Gain / 40.0 ) );                 /* Gain is expressed in dB */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						temp1 = A + 1.0; temp2 = A - 1.0; temp3 = temp1 * cs; temp4 = temp2 * cs;
    						beta = sn * Math.sqrt( ( A * A + 1.0 ) / S - temp2 * temp2 );
    						a0 = 1.0 / ( temp1 + temp4 + beta );
    						a1 = ( -2.0 * ( temp2 + temp3 ) ) * a0;
    						a2 = ( temp1 + temp4 - beta ) * a0;
    						b0 = ( A * ( temp1 - temp4 + beta ) ) * a0;
    						b1 = ( 2.0 * A * ( temp2 - temp3 ) ) * a0;
    						b2 = ( A * ( temp1 - temp4 - beta ) ) * a0;
    						break;
    					case 6:                                               /* highshelf */
    						/* "shelf slope" 1.0 = max slope, because neither Q nor bandwidth is used in */
    						/* those filters (note: true only for lowshelf and highshelf, not peaking). */
    						S = 1.0; /* used only by lowshelf and highshelf */
    						A = Math.pow( 10.0, ( Gain / 40.0 ) );                  /* Gain is expressed in dB */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						temp1 = A + 1.0; temp2 = A - 1.0; temp3 = temp1 * cs; temp4 = temp2 * cs;
    						beta = sn * Math.sqrt( ( A * A + 1.0 ) / S - temp2 * temp2 );
    						a0 = 1.0 / ( temp1 - temp4 + beta );
    						a1 = ( 2.0 * ( temp2 - temp3 ) ) * a0;
    						a2 = ( temp1 - temp4 - beta ) * a0;
    						b0 = ( A * ( temp1 + temp4 + beta ) ) * a0;
    						b1 = ( -2.0 * A * ( temp2 + temp3 ) ) * a0;
    						b2 = ( A * ( temp1 + temp4 - beta ) ) * a0;
    						break;
    					case 7:                                               /* peaking */
    						A = Math.pow( 10.0, ( Gain / 40.0 ) );                  /* Gain is expressed in dB */
    						omega = ( Math.PI*2 * Frequency ) / 44100;
    						sn = Math.sin( omega ); cs = Math.cos( omega );
    						alpha = sn / ( 2.0 * Q );
    						temp1 = alpha * A;
    						temp2 = alpha / A;
    						a0 = 1.0 / ( 1.0 + temp2 );
    						a1 = ( -2.0 * cs ) * a0;
    						a2 = ( 1.0 - temp2 ) * a0;
    						b0 = ( 1.0 + temp1 ) * a0;
    						b2 = ( 1.0 - temp1 ) * a0;
    						break;
    					}
    				}
    				/* -- filter loop: if you don't change the parameters of the filter dynamically, ~only this code will be executed. */
    				switch (Type) {
    				case 0:                                                  /* no filtering */
    					Output = b0*Input;
    					Output = Input;
    					break;
    				case 1:                                                  /* lowpass */
    				case 2:                                                  /* highpass */
    					Output = b0*Input + b1*i1 + b0*i2 - a1*o1 - a2*o2;
    					break;
    				case 3:                                                  /* bandpass */
    					Output = b0*Input - b0*i2 - a1*o1 - a2*o2;
    					break;
    				case 4:                                                  /* notch */
    					Output = b0*Input + b1*i1 + b0*i2 - a1*o1 - a2*o2;
    					break;
    				case 5:                                                  /* low shelving */
    				case 6:                                                  /* high shelving */
    					Output = b0*Input + b1*i1 + b2*i2 - a1*o1 - a2*o2;
    					break;
    				case 7:                                                  /* peaking */
    					Output = b0*Input + a1*i1 + b2*i2 - a1*o1 - a2*o2;
    					break;
    				}
    				o2=o1; o1=Output; i2=i1; i1=Input; /* update variables for recursion */
    				return(Output);
    			}
    Sinon il y'a aussi des librairies sonore un peu plus pro (genre Fmod) qui offre des DSP tout fait pour faire ce genre de choses...


    Citation Envoyé par wax78 Voir le message
    Bah en theorie avec le bout de code que j'ai fillé tu t'en fous de connaitre le traitement de signal, faut juste lui faire confiance au code.

    Dans ton cas toi tu chercher le filtre numero 3 (BandPass). Apres il suffit de faire passer ce que ton micro envoye la dedans puis d'en faire ce que tu veux.
    Bonjour

    Voilà ce que mon code renvoi : un fichier audio junk.wav ou junk.au
    ou je pourrais intégrer ce bout de code à ce programme java par exemple ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.sound.sampled.*;
     
    public class AudioRecorder02 extends JFrame{
     
      AudioFormat audioFormat;
      TargetDataLine targetDataLine;
     
      final JButton captureBtn =
                              new JButton("Capture");
      final JButton stopBtn = new JButton("Stop");
     
      final JPanel btnPanel = new JPanel();
      final ButtonGroup btnGroup = new ButtonGroup();
      final JRadioButton aifcBtn =
                            new JRadioButton("AIFC");
      final JRadioButton aiffBtn =
                            new JRadioButton("AIFF");
      final JRadioButton auBtn =//selected at startup
                         new JRadioButton("AU",true);
      final JRadioButton sndBtn =
                             new JRadioButton("SND");
      final JRadioButton waveBtn =
                            new JRadioButton("WAVE");
     
      public static void main( String args[]){
        new AudioRecorder02();
      }//end main
     
     
     
     
      public AudioRecorder02(){//constructor
        captureBtn.setEnabled(true);
        stopBtn.setEnabled(false);
     
        //Register anonymous listeners
        captureBtn.addActionListener(
          new ActionListener(){
            public void actionPerformed(
                                      ActionEvent e){
              captureBtn.setEnabled(false);
              stopBtn.setEnabled(true);
              //Capture input data from the
              // microphone until the Stop button is
              // clicked.
              captureAudio();
            }//end actionPerformed
          }//end ActionListener
        );//end addActionListener()
     
        stopBtn.addActionListener(
          new ActionListener(){
            public void actionPerformed(
                                      ActionEvent e){
              captureBtn.setEnabled(true);
              stopBtn.setEnabled(false);
              //Terminate the capturing of input data
              // from the microphone.
              targetDataLine.stop();
              targetDataLine.close();
            }//end actionPerformed
          }//end ActionListener
        );//end addActionListener()
     
        //Put the buttons in the JFrame
        getContentPane().add(captureBtn);
        getContentPane().add(stopBtn);
     
        //Include the radio buttons in a group
        btnGroup.add(aifcBtn);
        btnGroup.add(aiffBtn);
        btnGroup.add(auBtn);
        btnGroup.add(sndBtn);
        btnGroup.add(waveBtn);
     
        //Add the radio buttons to the JPanel
        btnPanel.add(aifcBtn);
        btnPanel.add(aiffBtn);
        btnPanel.add(auBtn);
        btnPanel.add(sndBtn);
        btnPanel.add(waveBtn);
     
        //Put the JPanel in the JFrame
        getContentPane().add(btnPanel);
     
        //Finish the GUI and make visible
        getContentPane().setLayout(new FlowLayout());
        setTitle("Copyright 2003, R.G.Baldwin");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300,120);
        setVisible(true);
      }//end constructor
     
      //This method captures audio input from a
      // microphone and saves it in an audio file.
      private void captureAudio(){
        try{
          //Get things set up for capture
          audioFormat = getAudioFormat();
          DataLine.Info dataLineInfo =
                              new DataLine.Info(
                                TargetDataLine.class,
                                audioFormat);
          targetDataLine = (TargetDataLine)
                   AudioSystem.getLine(dataLineInfo);
     
          //Create a thread to capture the microphone
          // data into an audio file and start the
          // thread running.  It will run until the
          // Stop button is clicked.  This method
          // will return after starting the thread.
          new CaptureThread().start();
        }catch (Exception e) {
          e.printStackTrace();
          System.exit(0);
        }//end catch
      }//end captureAudio method
     
      //This method creates and returns an
      // AudioFormat object for a given set of format
      // parameters.  If these parameters don't work
      // well for you, try some of the other
      // allowable parameter values, which are shown
      // in comments following the declarations.
      private AudioFormat getAudioFormat(){
        float sampleRate = 44100;
        //8000,11025,16000,22050,44100
        int sampleSizeInBits = 16;
        //8,16
        int channels = 1;
        //1,2
        boolean signed = true;
        //true,false
        boolean bigEndian = false;
        //true,false
        return new AudioFormat(sampleRate,
                               sampleSizeInBits,
                               channels,
                               signed,
                               bigEndian);
      }//end getAudioFormat
    //=============================================//
     
    //Inner class to capture data from microphone
    // and write it to an output audio file.
    class CaptureThread extends Thread{
      public void run(){
        AudioFileFormat.Type fileType = null;
        File audioFile = null;
     
        //Set the file type and the file extension
        // based on the selected radio button.
        if(aifcBtn.isSelected()){
          fileType = AudioFileFormat.Type.AIFC;
          audioFile = new File("junk.aifc");
        }else if(aiffBtn.isSelected()){
          fileType = AudioFileFormat.Type.AIFF;
          audioFile = new File("junk.aif");
        }else if(auBtn.isSelected()){
          fileType = AudioFileFormat.Type.AU;
          audioFile = new File("junk.au");
        }else if(sndBtn.isSelected()){
          fileType = AudioFileFormat.Type.SND;
          audioFile = new File("junk.snd");
        }else if(waveBtn.isSelected()){
          fileType = AudioFileFormat.Type.WAVE;
          audioFile = new File("junk.wav");
        }//end if
     
        try{
          targetDataLine.open(audioFormat);
          targetDataLine.start();
          AudioSystem.write(
                new AudioInputStream(targetDataLine),
                fileType,
                audioFile);
        }catch (Exception e){
          e.printStackTrace();
        }//end catch
     
      }//end run
    }//end inner class CaptureThread
    //=============================================//
     
    }//end outer class AudioRecorder02.java
    Merci beaucoup

Discussions similaires

  1. Filtre Passe-bande en java
    Par milanista91989 dans le forum Général Java
    Réponses: 6
    Dernier message: 14/05/2012, 16h18
  2. Filtre passe bande
    Par vanhelsing69 dans le forum Signal
    Réponses: 8
    Dernier message: 17/12/2008, 18h01
  3. Chargement de fichiers et filtre passe bande
    Par Caroline_1 dans le forum Signal
    Réponses: 12
    Dernier message: 13/12/2008, 22h29
  4. Filtre passe bande
    Par zinzaf dans le forum LabVIEW
    Réponses: 2
    Dernier message: 15/06/2008, 09h55
  5. Filtre passe Bande
    Par Mau dans le forum Algorithmes et structures de données
    Réponses: 4
    Dernier message: 28/06/2002, 17h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo