Précédent   Forum du club des développeurs et IT Pro > Environnements de développement > MATLAB > Signal
Signal Forum d'entraide sur le traitement du signal en MATLAB
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 11/11/2010, 12h35   #1
harmonips
Futur Membre du Club
 
Arnaud Jeanvoine
Inscription : juin 2010
Messages : 54
Détails du profil
Informations personnelles :
Nom : Arnaud Jeanvoine

Informations forums :
Inscription : juin 2010
Messages : 54
Points : 15
Points : 15
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 :
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
harmonips est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2010, 11h10   #2
harmonips
Futur Membre du Club
 
Arnaud Jeanvoine
Inscription : juin 2010
Messages : 54
Détails du profil
Informations personnelles :
Nom : Arnaud Jeanvoine

Informations forums :
Inscription : juin 2010
Messages : 54
Points : 15
Points : 15
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 :
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
harmonips est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2010, 14h10   #3
Winjerome
Modérateur
 
Avatar de Winjerome
 
Homme Jérôme
Inscription : septembre 2009
Messages : 5 164
Détails du profil
Informations personnelles :
Nom : Homme Jérôme
Âge : 25
Localisation : France, Pyrénées Atlantiques (Aquitaine)

Informations forums :
Inscription : septembre 2009
Messages : 5 164
Points : 12 598
Points : 12 598
Bonjour,

Je pense que tu peux t'inspirer de cette discussion
__________________
Débutant en MATLAB ? Vous voulez faire une Interface Graphique ? Les Tutoriels et la FAQ sont là pour vous aider
Une erreur ? FAQ : Messages d'erreur et avertissements
"Ça ne marche pas" n'est pas une réponse acceptable Expliquez clairement votre problème (erreurs, résultats non attendus...).
Citation:
En essayant continuellement on finit par réussir. Donc: plus ça rate, plus on a de chance que ça marche. - Jacques Rouxel
L'expérience, c'est le nom que chacun donne à ses erreurs - Oscar Wilde
Pas de question technique par MP, Merci
Winjerome est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2010, 16h50   #4
harmonips
Futur Membre du Club
 
Arnaud Jeanvoine
Inscription : juin 2010
Messages : 54
Détails du profil
Informations personnelles :
Nom : Arnaud Jeanvoine

Informations forums :
Inscription : juin 2010
Messages : 54
Points : 15
Points : 15
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
harmonips est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/11/2010, 09h45   #5
harmonips
Futur Membre du Club
 
Arnaud Jeanvoine
Inscription : juin 2010
Messages : 54
Détails du profil
Informations personnelles :
Nom : Arnaud Jeanvoine

Informations forums :
Inscription : juin 2010
Messages : 54
Points : 15
Points : 15
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 :
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
harmonips est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/10/2012, 15h38   #6
totovai
Invité de passage
 
Homme
Inscription : mars 2011
Messages : 3
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : mars 2011
Messages : 3
Points : 1
Points : 1
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 :
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
totovai est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 20h03.


 
 
 
 
Partenaires

Hébergement Web