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

Téléchargez Discussion :

[Windows] Controle du volume


Sujet :

Téléchargez

  1. #1
    Membre averti

    Inscrit en
    Août 2007
    Messages
    302
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 302
    Points : 352
    Points
    352
    Par défaut [Windows] Controle du volume
    Bonjour,

    Je vous propose un nouvel élément à utiliser : Contrôle du volume

    si vous êtes sous Windows, vous pouvez utiliser la fonction MEX ci-dessous pour ajuster le volume sonore.

    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
     
    % load some music
    load handel;
    player = audioplayer(y, Fs);
    t = 3; % time of play in seconds
    ts = [1 (get(player, 'SampleRate')*t)];
     
    disp('Playing at current volume...');
    playblocking(player,ts);
     
    % read current volume
    [left, right] = mx_volume('WAVE');
     
    % set volume to a dummy value and play music
    mx_volume('WAVE', 8000, 8000);
    disp('Playing at a volume of 8000...');
    playblocking(player,ts);
     
    % set volume to a another dummy value and play music
    mx_volume('WAVE', 500, 500);
    disp('Playing at a volume of 500...');
    playblocking(player,ts);
     
    % left channel only
    mx_volume('WAVE', 8000, 0);
    disp('Playing on the left channel only...');
    playblocking(player,ts);
     
    % right channel only
    mx_volume('WAVE', 0, 8000);
    disp('Playing on the right channel only...');
    playblocking(player,ts);
     
    % set volume back to original values
    mx_volume('WAVE', left, right);
    disp('Playing at original volume');
    playblocking(player,ts);
    Salutations,


    Gregoire

    -----------------------

    Dut (08/01/2010) : ajout d'une version compilée mx_volume.dll pour les version 7 de MATLAB

    Dut (08/06/2013) : ajout d'une version compilée mx_volume.mexw64 pour les versions 64 bits de MATLAB

  2. #2
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 53 166
    Points
    53 166
    Par défaut
    C'est plutôt pas mal ça...

    La valeur max du volume est-elle fixée ? (j'ai 32767 sur ma machine)
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  3. #3
    Membre averti

    Inscrit en
    Août 2007
    Messages
    302
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 302
    Points : 352
    Points
    352
    Par défaut
    oui il y a un maximum... qui dépend de la carte son... (mais au max 2^16-1 dans tous les cas)

    Salutations,

    Grég

  4. #4
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 53 166
    Points
    53 166
    Par défaut
    Une petite télécommande toute simple :

    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
    function ctrvol
     
    fig = figure('units','normalized',...
        'position',[.1 .1 .1 .33],...
        'menubar','none',...
        'toolbar','none',...
        'resize','off',...
        'numbertitle','off');
     
    movegui(fig,'center')
     
    [left, right] = mx_volume('WAVE');
     
    uicontrol('style','slider',...
        'units','normalized',...
        'position',[.2 .2 .2 .7],...
        'tag','slidl',...
        'max',(2^16-1)/2,...
        'callback',@cb_vol,...
        'value',left)
     
    uicontrol('style','slider',...
        'units','normalized',...
        'position',[.6 .2 .2 .7],...
        'tag','slidr',...
        'max',(2^16-1)/2,...
        'callback',@cb_vol,...
        'value',right)
     
    uicontrol('style','checkbox',...
        'units','normalized',...
        'position',[.2 .05 .2 .1],...
        'tag','chkl',...
        'value',1,...
        'callback',@cb_vol)
     
    uicontrol('style','checkbox',...
        'units','normalized',...
        'position',[.6 .05 .2 .1],...
        'tag','chkr',...
        'value',1,...
        'callback',@cb_vol)
     
    handles = guihandles(fig);
    guidata(fig,handles);
     
    function cb_vol(obj,event)
     
        handles = guidata(gcbf);
     
        [left, right] = mx_volume('WAVE');
     
        switch get(obj,'tag')
     
            case 'chkr'
                val = get(obj,'value');
                if ~val
                    mx_volume('WAVE', left, 0);
                else
                    mx_volume('WAVE', left, get(handles.slidr,'value'));
                end
            case 'chkl'
                val = get(obj,'value');
                if ~val
                    mx_volume('WAVE', 0, right);
                else
                    mx_volume('WAVE', get(handles.slidl,'value'), right);
                end
     
            case 'slidr'
     
                if get(handles.chkr,'value')
                    mx_volume('WAVE', left, get(obj,'value'));
                end
     
            case 'slidl'
                if get(handles.chkl,'value')
                    mx_volume('WAVE', get(obj,'value'), right);
                end
        end
    Les uicontrol de gauche pour le canal de gauche, ceux de droite, pour le canal de droite

    Il faut bien entendu que mx_volume.mexw32 soit dans le même répertoire

    A améliorer...
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  5. #5
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 53 166
    Points
    53 166
    Par défaut
    Avec des slider qui répondent en temps réel :

    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
    function ctrvol
     
    fig = findobj('type','figure','tag','ctrvol');
     
    if ishandle(fig)
        return
    end
     
    fig = figure('units','normalized',...
        'position',[.1 .1 .1 .33],...
        'menubar','none',...
        'toolbar','none',...
        'resize','off',...
        'numbertitle','off',...
        'visible','off',...
        'tag','ctrvol');
     
    movegui(fig,'center')
     
    [left, right] = mx_volume('WAVE');
     
    u = uipanel('units','normalized',...
        'position',[.066 .15 .4 .8],...
        'title','Left');
     
    handles.ui(1) = uicomponent(u,'style','javax.swing.jslider','name','slidl',...
        'units','normalized','Orientation',true,...
        'minimum',0,'maximum',100,'value',100*double(left)/((2^16-2)/2),...
        'PaintTicks',true,'MajorTickSpacing',50,...
        'PaintLabels', true,'MajorTickSpacing',10);
    set(handles.ui(1),'position',[.05 0 .9 1],'StateChangedCallback',@cb_vol);
     
    u = uipanel('units','normalized',...
        'position',[.533 .15 .4 .8],...
        'title','Right');
     
    handles.ui(2) = uicomponent(u,'style','javax.swing.jslider','name','slidr',...
        'units','normalized','Orientation',true,...
        'minimum',0,'maximum',100,'value',100*double(right)/((2^16-2)/2),...
        'PaintTicks',true,'MajorTickSpacing',50,...
        'PaintLabels', true,'MajorTickSpacing',10);
    set(handles.ui(2),'position',[.05 0 .9 1],'StateChangedCallback',@cb_vol);
     
    u = uipanel('units','normalized','position', [.066 .02 .868 .125],...
        'title','Mute');
    handles.chkl = uicontrol(u,'style','checkbox',...
        'units','normalized',...
        'position',[.15 .05 .3 .9],...
        'tag','chkl',...
        'value',1,...
        'callback',@cb_vol);
     
    handles.chkr = uicontrol(u,'style','checkbox',...
        'units','normalized',...
        'position',[.7 .05 .3 .9],...
        'tag','chkr',...
        'value',1,...
        'callback',@cb_vol);
     
    guidata(fig,handles);
     
    set(fig,'visible','on')
     
    function cb_vol(obj,event)
     
        val = get(obj,'value');
     
        if isprop(obj,'name')
            str = get(obj,'name');
        else str = get(obj,'tag');
        end
     
        fig = findobj('type','figure','tag','ctrvol');
        handles = guidata(fig);
     
        [left, right] = mx_volume('WAVE');
     
        switch str
     
            case 'chkr'
                if ~val
                    mx_volume('WAVE', left, 0);
                else
                    mx_volume('WAVE', left, (2^16-1)/2*get(handles.ui(2),'value')/100);
                end
            case 'chkl'
                if ~val
                    mx_volume('WAVE', 0, right);
                else
                    mx_volume('WAVE', (2^16-1)/2*get(handles.ui(1),'value')/100, right);
                end
     
            case 'slidr'
                val = (2^16-1)/2*val/100;
                if get(handles.chkr,'value')
                    mx_volume('WAVE', left, val);
                end
     
            case 'slidl'
                val = (2^16-1)/2*val/100;
                if get(handles.chkl,'value')
                    mx_volume('WAVE', val, right);
                end
        end
    Il faut récupérer cette contribution du FEX : UICOMPONENT - expands uicontrol to all Java classes
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  6. #6
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 53 166
    Points
    53 166
    Par défaut
    Ajout d'une version compilée de la Dll pour les version 7 de MATLAB
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  7. #7
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 53 166
    Points
    53 166
    Par défaut
    Ajout d'une version compilée pour les versions 64 bits de MATLAB
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

Discussions similaires

  1. [C#] Avoir un control de type control de volume windows
    Par legillou dans le forum Windows Forms
    Réponses: 3
    Dernier message: 02/11/2009, 13h13
  2. Controle de volume sonore de Windows
    Par halimi dans le forum MATLAB
    Réponses: 5
    Dernier message: 22/01/2009, 06h01
  3. Background pour Window/Control récupéré de Windows
    Par adrienfehr dans le forum Windows Presentation Foundation
    Réponses: 3
    Dernier message: 26/08/2008, 08h48
  4. Slider Control MFC Volume
    Par Copernic09 dans le forum MFC
    Réponses: 6
    Dernier message: 30/12/2007, 11h07
  5. [VB.NET]Comment controler le Volume/Mute d'une ligne audio?
    Par jazz matazz dans le forum Contribuez
    Réponses: 7
    Dernier message: 31/03/2006, 02h25

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