MATLAB Answers

0

real time audio wave plot

Asked by Kathleen Rosales on 9 Mar 2013
Latest activity Answered by Marcus Vollmer on 13 Jun 2014
how can i display the real time wave plot on an axes??
i'm using GUI which allows me to record and browse audio.. when i click the play button i want to display the wave plot on the axes.. i have no idea how to do this...
help please :D

  5 Comments

Walter Roberson
on 9 Mar 2013
How many frames per second did your tracking program handle?
The ear can hear delays on the order of 0.1 millisecond -- the equivalent of 10000 Hz.
function varargout = try2(varargin)
% TRY2 MATLAB code for try2.fig
% TRY2, by itself, creates a new TRY2 or raises the existing
% singleton*.
%
% H = TRY2 returns the handle to a new TRY2 or the handle to
% the existing singleton*.
%
% TRY2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TRY2.M with the given input arguments.
%
% TRY2('Property','Value',...) creates a new TRY2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before try2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to try2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help try2
% Last Modified by GUIDE v2.5 10-Jan-2013 16:53:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @try2_OpeningFcn, ...
'gui_OutputFcn', @try2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before try2 is made visible.
function try2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to try2 (see VARARGIN)
% Choose default command line output for try2
handles.output = hObject;
% create an axes that spans the whole gui
ah = axes('unit', 'normalized', 'position', [0 0 1 1]);
% import the background image and show it on the axes
bg = imread('bg3.jpg'); imagesc(bg);
% prevent plotting over the background and turn the axis off
set(ah,'handlevisibility','off','visible','off')
% making sure the background is behind all the other uicontrols
uistack(ah, 'bottom');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes try2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = try2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in browse.
function browse_Callback(hObject, eventdata, handles)
% hObject handle to browse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_name;
file_name = uigetfile({'*.wav'},'Load Wav File');
guidata(hObject,handles);
% --- Executes on button press in play.
function play_Callback(hObject, eventdata, handles)
% hObject handle to play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_name;
[x,fs]=wavread(file_name);
handles.r=audioplayer(x,fs);
play(handles.r);
guidata(hObject,handles);
% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject handle to stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
stop(handles.r);
guidata(hObject,handles);
% --- Executes on button press in pause.
function pause_Callback(hObject, eventdata, handles)
% hObject handle to pause (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pause(handles.r);
handles.stat=1;
guidata(hObject,handles);
% --- Executes on button press in resume.
function resume_Callback(hObject, eventdata, handles)
% hObject handle to resume (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
resume(handles.r);
handles.stat=0;
guidata(hObject,handles);
% --- Executes on button press in reverb.
function reverb_Callback(hObject, eventdata, handles)
% hObject handle to reverb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_name;
fs = 44100;
[song,fs] = wavread(file_name);
left=song(:,1);
leftout=left;
N=10000;
for n=N+1:length(left)
leftout(n)=left(n)+left(n-N); % approximately ? second echo
end
handles.r=audioplayer(leftout,fs);
play(handles.r);
guidata(hObject,handles);
% --- Executes on button press in Downsampling.
function Downsampling_Callback(hObject, eventdata, handles)
% hObject handle to Downsampling (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_name;
speed2 = get(handles.downSpeed,'String'); fs = 44100;
speed2 = str2num(speed2)
[song,fs] = wavread(file_name);
handles.output = song;
handles.fs = fs*speed2;
handles.r = audioplayer(handles.output, handles.fs);
play(handles.r);
guidata(hObject,handles);
% --- Executes on button press in flanging.
function flanging_Callback(hObject, eventdata, handles)
% hObject handle to flanging (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in record.
function record_Callback(hObject, eventdata, handles)
recordtime = get(handles.time,'String'); Fs = 44100;
recordtime = str2num(recordtime)
record = wavrecord(recordtime.*Fs,Fs);
[filename, pathname] = uiputfile('*.wav');
cd (pathname);
wavwrite(record,Fs,filename);
guidata(hObject,handles)
function time_Callback(hObject, eventdata, handles)
% hObject handle to time (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
recordtime = str2num(get(hObject,'String'));
if (isempty(recordtime))
set(hObject,'String','0')
end
handles.recordtime = recordtime;
guidata(hObject, handles);
% Hints: get(hObject,'String') returns contents of time as text
% str2double(get(hObject,'String')) returns contents of time as a double
% --- Executes during object creation, after setting all properties.
function time_CreateFcn(hObject, eventdata, handles)
% hObject handle to time (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in upSampling.
function upSampling_Callback(hObject, eventdata, handles)
% hObject handle to upSampling (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_name;
speed = get(handles.upSpeed,'String'); fs = 44100;
speed = str2num(speed)
[song,fs] = wavread(file_name);
handles.output = song;
handles.fs = fs/speed;
handles.r = audioplayer(handles.output, handles.fs);
play(handles.r);
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes2
function upSpeed_Callback(hObject, eventdata, handles)
% hObject handle to upSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of upSpeed as text
% str2double(get(hObject,'String')) returns contents of upSpeed as a double
speed = str2num(get(hObject,'String'));
if (isempty(speed))
set(hObject,'String','0')
end
handles.speed = speed;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function upSpeed_CreateFcn(hObject, eventdata, handles)
% hObject handle to upSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function downSpeed_Callback(hObject, eventdata, handles)
% hObject handle to downSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of downSpeed as text
% str2double(get(hObject,'String')) returns contents of downSpeed as a double
% --- Executes during object creation, after setting all properties.
function downSpeed_CreateFcn(hObject, eventdata, handles)
% hObject handle to downSpeed (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
speed2 = str2num(get(hObject,'String'));
if (isempty(speed2))
set(hObject,'String','0')
end
handles.speed2 = speed2;
guidata(hObject, handles);
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over browse.
function browse_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to browse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function reverb_CreateFcn(hObject, eventdata, handles)
% hObject handle to reverb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
that is my code............

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 10 Mar 2013

This cannot be done in MATLAB.
You might be able to get somewhere using the extensions of the (third-party) PsychToolBox

  1 Comment

Daniel Shub
on 10 Mar 2013
The ability to perceive audio-visual asynchrony is a lot slower ( 100 ms or so) compared to the temporal resolution of the auditory system ( http://www.ncbi.nlm.nih.gov/pubmed/12765396 0.02ms). You can probably come pretty close with standard MATLAB and an audioplayer object (or better its ASIO implementation which I haven't tried yet).

Sign in to comment.


Answer by Marcus Vollmer on 13 Jun 2014

  0 Comments

Sign in to comment.