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

Signal Discussion :

Acquisition d'un signal audio et le retransmission en temps réel


Sujet :

Signal

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 55
    Points : 44
    Points
    44
    Par défaut Acquisition d'un signal audio et le retransmission en temps réel
    bonjour,
    j'ai déjà pas mal de fois utilisé la DAQ de Mdatlab pour acquérir en temps réel un signal audio. cependant, dans cette nouvelle application, je voudrais pouvoir retourner (à la trame près) directement sur un haut parleur cette trame.
    j'ai pas mal cherché sur le forum et sur la FAQ mais j'ai l'impression que personne n'a déjà fait ca.....

    en fait je ne sais pas ou mettre mon code de l'analogoutput

    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
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    function ESSAI(varargin)
     
    %%
    % Error if an output argument is supplied.
    if nargout > 0
        error('Too many output arguments.');
    end
     
    %%
    % Based on the number of input arguments call the appropriate
    % local function.
    switch nargin
        case 0
            % Create the analog input object.
            data = localInitAI;
            % Create the  figure.
            data = localInitFig(data);
            hFig = data.handle.figure;
     
        case 1
            error('The ADAPTORNAME, ID and CHANID must be specified.');
        case 2
            % Initialize variables.
            data = [];
            action=varargin{1};
            hFig=varargin{2};
     
            % This may fail if only the ADAPTORNAME and ID were input.  However,
            % if the ID was 0, this will work.
            try
                data=get(hFig,'UserData');
            end
     
            % DATA will be empty if CHANID was not specified or if ID = 0.
            if isempty(data)
                error('The CHANID must be specified.');
            end
     
            % Based on the action, call the appropriate local function.
            switch action
                case 'close'
                    localClose(data);
                case 'stop'
                    data = localStop(data);
            end
        case 3
            % User specified the input - adaptor, id, chanNum.
            % Create the analog input object.
            [data, errflag] = localInitAI(varargin{:});
            if errflag
                error(lasterror)
            end
     
            % Create the  figure.
            data = localInitFig(data);
            hFig = data.handle.figure;
    end
     
    %%
    % Update the figure's UserData.
    if ~isempty(hFig)&ishandle(hFig),
        set(hFig,'UserData',data);
    end
     
    %%
    % Update the analog input object's UserData.
    if isvalid(data.ai)
        set(data.ai, 'UserData', data);
    end
     
    %% ***********************************************************************
    % Create the object and get the first fft.
    function [data, errflag] = localInitAI(varargin)
     
    % Initialize variables.
    errflag = 0;
    data = [];
     
    %%
    % Either no input arguments or all three - ADAPTORNAME, ID and CHANNELID.
    switch nargin
        case 0
            adaptor = 'winsound';
            id = 0;
            chan = 1;
        case 3
            adaptor = varargin{1};
            id = varargin{2};
            chan = varargin{3};
        otherwise
            lasterr('The ADAPTORNAME, ID and CHANID must be specified.');
            errflag = 1;
            return;
    end
     
    %%
     
    %%
    % Object Configuration.
    % Create an analog input object with one channel.
    ai = analoginput(adaptor, id);
    addchannel(ai, [1 2]);
     
     
    %%
    % Configure the analog input object.
    set(ai, 'SampleRate', 44100);
    timePeriod = 0.01;
     
    %%
    % Configure the analog input object to trigger manually twice.
    set(ai, 'SamplesPerTrigger', timePeriod*ai.sampleRate);
    set(ai, 'TriggerRepeat', 1);
    set(ai, 'TriggerType', 'manual');
    set(ai, 'TimerPeriod', timePeriod);
    set(ai, 'BufferingConfig',[2048,20]);
     
     
    %%
    % Object Execution.
    % Start the analog input object.
    start(ai);
     
    trigger(ai);
    %%
    % Obtain the available time and data.
    [d,time] = getdata(ai, ai.SamplesPerTrigger);
    %%
    Fs = get(ai, 'SampleRate');
    %%
    % Update the data structure.
    data.ai = ai;
    data.handle = [];
    %%
    % Set the object's UserData to data.
    set(data.ai, 'UserData', data);
     
    %% ***********************************************************************
    % Create the display.
    function data = localInitFig(data)
    fe=44100;
    btnColor=get(0,'DefaultUIControlBackgroundColor');
    screenUnits=get(0,'Units');
    set(0,'Units','pixels');
    screenSize=get(0,'ScreenSize');
    set(0,'Units',screenUnits);
    figWidth=600;
    figHeight=360;
    figPos=[(screenSize(3)-figWidth)/2 (screenSize(4)-figHeight)/2  ...
        figWidth                    figHeight];
     
    hFig=figure(...
        'Color'             ,btnColor                 ,...
        'IntegerHandle'     ,'off'                    ,...
        'DoubleBuffer'      ,'on'                     ,...
        'DeleteFcn'         ,'LOCA(''close'',gcbf)',...
        'MenuBar'           ,'none'                   ,...
        'HandleVisibility'  ,'on'                     ,...
        'Name'              ,'LOCA'           ,...
        'Tag'               ,'LOCA'           ,...
        'NumberTitle'       ,'off'                    ,...
        'Units'             ,'pixels'                 ,...
        'Position'          ,figPos                   ,...
        'UserData'          ,[]                       ,...
        'Colormap'          ,[0 0 0]                  ,...
        'Pointer'           ,'arrow'                  ,...
        'Visible'           ,'off'                     ...
        );
    set(hFig, 'Units','Normalize','OuterPosition',[0 0.035 1 0.965]);
     
    %menu
    hmenu(1) = uimenu('Parent', hFig,...
        'Label', ' Fichier ');
    hmenu(2) = uimenu(hmenu(1),...
        'Label', ' Quitter ',...
        'Callback', 'LOCA(''close'',gcbf)');
    hmenu(3) = uimenu(hFig,...
        'Label', ' Chargement ');
    hmenu(4) = uimenu('Parent', hmenu(3),...
        'Label', ' Signal ',...
        'Callback', 'LOCA(''chargement1'',gcbf)');
    hmenu(5) = uimenu('Parent', hmenu(3),...
        'Label', ' Bruit ',...
        'Callback', 'LOCA(''chargement2'',gcbf)');
     
     
     
    data.handle.figure = hFig;
     
    set(hFig,'Visible','on','UserData',data,'HandleVisibility', 'off');
    % set(hIm(2:2:21),'Visible','off');
     
    %%
    % Configure the callback to update the display.
    set(data.ai, 'TimerFcn', @localfftShowData);
     
    %% ***********************************************************************
    % Close the figure window.
    function localClose(data)
     
    %%
    % Stop the device if it is running and delete the object.
    if isvalid(data.ai)
        if isrunning(data.ai)
            stop(data.ai);
        end
        delete(data.ai);
    end
    %%
    % Close the figure window.
    delete(data.handle.figure);
     
    %% ***********************************************************************
    % Stop or start the device.
    function data = localStop(data)
     
    %%
    % Based on the state either stop or start.
    if isrunning(data.ai)
        % Stop the device.
        stop(data.ai);
        set(data.handle.toggle(1), 'String', 'Start');
     
        % Store the new state.
        data.state(1) = 1;
    else
        % Toggle the Start/Stop string.
        set(data.handle.toggle(1), 'String', 'Stop');
     
        % Store the new state.
        data.state(1) = 0;
     
        % Start the device.
        start(data.ai);
    end
     
     
    %% ***********************************************************************
    % Update the plot.
    function localfftShowData(obj,event)
    %%
    % Execute a peekdata.
    x = peekdata(obj, obj.SamplesPerTrigger);
     
    drawnow;
    merci pour votre aide car je suis vraiment perdu

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 55
    Points : 44
    Points
    44
    Par défaut suite du premier message
    bonjour,
    je reviens en ayant simplifier le model,
    je voudrais savoir tout simplement comment faire pour retourner directement ce que la carte son enregistre sur l'entrée et remetre directement sur la sortie

    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
     
    %
    fs=44100;
    %
    Aout = analogoutput('nidaq', 1);
    AI = analoginput('nidaq',1);
    chan_in = addchannel(AI,0);
    set(AI,'SampleRate',fs)
    %
    set(AI,'SamplesPerTrigger',fix(0.01*fs))
    set(AI,'TriggerType','Manual')
    blocksize = get(AI,'SamplesPerTrigger')
    %
    set(Aout,'TriggerType','Immediate');
    set(Aout,'SampleRate',fs)
    set(Aout,'Tag','dacout')
    addchannel(Aout,1);
    set(Aout.Channel,'OutputRange',[-1 1])
    %set(Aout, 'RepeatOutput', inf);
    set(Aout, 'RepeatOutput', 0);
    %
     
    %
    start([AI Aout] );
    trigger([AI Aout])
    %
    y = getdata(AI);
    putdata(Aout,y);
    voila si vous avez des idées pour avoir en temps réel la sortie et pouvoir l'écouter au casque

    merci pour vos réponse

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Je pense que tu peux t'inspirer de cette discussion

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 55
    Points : 44
    Points
    44
    Par défaut
    merci pour ton lien mais j'ai déjà regardé et ce n'est pas de la que vient mon problème.
    j'obtiens bien mon recouvrement nécéssaire mais je n'arrive pas à synchroniser mon analoginput avec analogoutput
    ce n'est pas avec une boucle que l'on peut résoudre le problème parce que c'est beaucoup trop lent..
    mais plutot avec les propriétées du "Trigger"


    je ne sais pas comment définir ce dernier

    merci pour ta réponse

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 55
    Points : 44
    Points
    44
    Par défaut
    bon ben en fait c'était super simple, en fait c'était dans le fonctionnement de "putdata" qu'il y avait un problème car je pensais que l'on ne pouvait pas remettre des informations tant que le buffer est rempli mais en fait si du moment qu'il n'est pas plein. par contre il ne faut qu'un seul start



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    putdata(ao,y);
    start(ao)
    ensuite à l'aide d'une boucle while je récupère mes échantillons de mon analoginput et je les remets dans la sortie directement et le tour et joué


    à bientot pour d'autre questions

  6. #6
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2011
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    Bonjour, j'ai le même soucis et je n'ai pas compris comment tu t'en es défait .
    je souhaite donc acquérir des données audios provenant d'un microphone et sortir ces données frame par frame (frame de 1000 échantillons)

    voici comment j'ai procédé :

    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
    %input
    AI = analoginput('winsound',0);
    chan=addchannel(AI,1);
    set(AI,'SampleRate',SampleRate);
    set(AI,'SamplesPerTrigger',duration*SampleRate);
    set(AI,'TriggerType','Manual')
     
    %output
    AO = analogoutput('winsound',0);    
    chan = addchannel(AO,1);
    set(AO,'SampleRate',SampleRate);
    set(AO,'TriggerType','Manual')
     
    start(AI);
    trigger(AI);
     
    i  =  1;
    semaphore=0;
    while  AI.SamplesAcquired  <  AI.SamplesPerTrigger
        while  AI.SamplesAcquired  <  1000*i
        end
    data  =  peekdata(AI,1000);
    putdata(AO,data);
        if semaphore == 0
        start(AO);
        trigger(AO);
        semaphore=1
        end
    i  =  i  +  1;
    end
     
     
    %Clean
    wait(AO,2*duration)
    delete(AO)
    clear AO
    delete(AI)
    clear AI
    je n'ai actuellement pas de son en sortie sans comprendre pourquoi.

    Merci d'avance

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Acquisition temps réel d'un signal audio
    Par zolle1 dans le forum Signal
    Réponses: 9
    Dernier message: 27/06/2011, 15h23
  2. Amplifier un signal audio
    Par flammeon dans le forum C++
    Réponses: 13
    Dernier message: 25/09/2006, 16h27
  3. Récuperer le signal audio d'un fichier .wav
    Par vienin dans le forum Multimédia
    Réponses: 2
    Dernier message: 11/10/2005, 16h25
  4. [TMS320C6416] FFT et IFFT sur un signal audio...
    Par 0x4e84 dans le forum Autres architectures
    Réponses: 1
    Dernier message: 18/04/2005, 20h21
  5. Réponses: 2
    Dernier message: 08/11/2004, 22h31

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