If I load 2 different music , after loading both , the UIAxes becomes the same, how do i fix this?
4 次查看(过去 30 天)
显示 更早的评论
So,
If i load 2 different music afte the 2nd import the Axes becomes the same as the first imported music.
Code involved in importing and playing tracks:
% Button pushed function: browse1
function browse1Pushed(app, event)
[filename,pathname]=uigetfile({'*.wav;*.mp3;'},'Choose file');
app.IMPORTEditField.Value=strcat(pathname,filename);
[app.y,Fs]=audioread(app.IMPORTEditField.Value);
app.player=audioplayer(app.y,Fs);
app.leftChannel = app.y(:, 1);
app.rightChannel = app.y(:, 2);
info=audioinfo(app.IMPORTEditField.Value);
app.timeinseconds=0:seconds(1/Fs):seconds(info.Duration);
app.timeinseconds=app.timeinseconds(1:end-1);
app.Bps=info.BitsPerSample;
app.totalsample=info.TotalSamples;
app.NumOfChannels=info.NumChannels;
app.samplerate=info.SampleRate;
app.totalduration=info.Duration;
current=get(app.player,'CurrentSample');
app.Label_12.Text=char(app.timeinseconds(current));
app.Label_3.Text=string(app.Bps(current));
app.Label_5.Text=string(app.NumOfChannels(current));
app.Label_4.Text=string(app.totalsample(current));
app.Label_2.Text=string(app.samplerate(current));
app.Label.Text=string(app.totalduration(current));
%
% axes(ap);
% plot(app.leftChannel);
plot(app.UIAxes,app.timeinseconds,app.y,'b',[-seconds(0.2) app.timeinseconds(end)], [0 0],'k',[app.timeinseconds(current) app.timeinseconds(current)],[min(min(app.y)) max(max(app.y))],'y');
xlim(app.UIAxes,[-seconds(0.2) app.timeinseconds(end)]);
ylim(app.UIAxes,[min(min(app.y)) max(max(app.y))]);
app.DJMIXERVERSION10UIFigure.Visible='off';
app.DJMIXERVERSION10UIFigure.Visible='on';
end
% % % % % % % % % % Callback to Play Music 1
% Button pushed function: play1
function play1Pushed(app, event)
play(app.player);
current=get(app.player,'CurrentSample');
app.Label_12.Text=char(app.timeinseconds(current));
drawnow;
plot(app.UIAxes,app.timeinseconds,app.y,'b',[-seconds(0.2) app.timeinseconds(end)], [0 0],'k',[app.timeinseconds(current) app.timeinseconds(current)],[min(min(app.y)) max(max(app.y))],'y');
xlim(app.UIAxes,[-seconds(0.2) app.timeinseconds(end)]);
ylim(app.UIAxes,[min(min(app.y)) max(max(app.y))]);
while app.timeinseconds(current)~=app.timeinseconds(end)
current=get(app.player,'CurrentSample');
app.Label_12.Text=string(app.timeinseconds(current));
plot(app.UIAxes,app.timeinseconds,app.y,'b',[-seconds(0.2) app.timeinseconds(end)], [0 0],'k',[app.timeinseconds(current) app.timeinseconds(current)],[min(min(app.y)) max(max(app.y))],'y');
xlim(app.UIAxes,[-seconds(0.2) app.timeinseconds(end)]);
ylim(app.UIAxes,[min(min(app.y)) max(max(app.y))]);
drawnow;
% pause(0.1);
end
end
Below is the code involved with loading the 2nd track
% Button pushed function: browse2
function browse2Pushed(app, event)
[filename,pathname]=uigetfile({'*.wav;*.mp3;'},'File Selector');
app.IMPORTEditField_2.Value=strcat(pathname,filename);
[app.y,Fs]=audioread(app.IMPORTEditField_2.Value);
app.player2=audioplayer(app.y,Fs);
info=audioinfo(app.IMPORTEditField_2.Value);
app.leftChannel = app.y(:, 1);
app.rightChannel = app.y(:, 2);
app.timeinseconds=0:seconds(1/Fs):seconds(info.Duration);
app.timeinseconds=app.timeinseconds(1:end-1);
app.Bps=info.BitsPerSample;
app.totalsample=info.TotalSamples;
app.NumOfChannels=info.NumChannels;
app.samplerate=info.SampleRate;
app.totalduration=info.Duration;
current=get(app.player2,'CurrentSample');
app.Label_9.Text=char(app.timeinseconds(current));
app.Label_7.Text=string(app.Bps(current));
app.Label_11.Text=string(app.NumOfChannels(current));
app.Label_6.Text=string(app.totalsample(current));
app.Label_10.Text=string(app.samplerate(current));
app.Label_8.Text=string(app.totalduration(current));
app.leftChannel = app.y(:, 1);
app.rightChannel = app.y(:, 2);
plot(app.UIAxes_2,app.timeinseconds,app.y,'b',[-seconds(0.2) app.timeinseconds(end)], [0 0],'k',[app.timeinseconds(current) app.timeinseconds(current)],[min(min(app.y)) max(max(app.y))],'y');
xlim(app.UIAxes_2,[-seconds(0.2) app.timeinseconds(end)]);
ylim(app.UIAxes_2,[min(min(app.y)) max(max(app.y))]);
app.DJMIXERVERSION10UIFigure.Visible='off';
app.DJMIXERVERSION10UIFigure.Visible='on';
end
% Button pushed function: play2
function play2Pushed(app, event)
play(app.player2);
current=get(app.player2,'CurrentSample');
app.Label_9.Text=char(app.timeinseconds(current));
drawnow;
plot(app.UIAxes_2,app.timeinseconds,app.y,'b',[-seconds(0.2) app.timeinseconds(end)], [0 0],'k',[app.timeinseconds(current) app.timeinseconds(current)],[min(min(app.y)) max(max(app.y))],'y');
xlim(app.UIAxes_2,[-seconds(0.2) app.timeinseconds(end)]);
ylim(app.UIAxes_2,[min(min(app.y)) max(max(app.y))]);
% ax.Color = 'blue';ax.Color = 'blue';
while app.timeinseconds(current)~=app.timeinseconds(end)
current=get(app.player2,'CurrentSample');
app.Label_9.Text=string(app.timeinseconds(current));
plot(app.UIAxes_2,app.timeinseconds,app.y,'b',[-seconds(0.2) app.timeinseconds(end)], [0 0],'k',[app.timeinseconds(current) app.timeinseconds(current)],[min(min(app.y)) max(max(app.y))],'y');
xlim(app.UIAxes_2,[-seconds(0.2) app.timeinseconds(end)]);
ylim(app.UIAxes_2,[min(min(app.y)) max(max(app.y))]);
drawnow;
% pause(0.1);
end
end
Notice:
These are two different music.
My concern is, sometimes the stated problem does not happen.
Once I upload the 2nd track regardless of the serial(either track1 or track 2), i am facing these issues.

When i merge the both audio and load it, the UIAxeses are fixed.

0 个评论
采纳的回答
Cris LaPierre
2021-12-31
编辑:Cris LaPierre
2021-12-31
Because you are using the same variable name to capture the imported track in both browse1 and browse2 functions, namely app.y. You also plot app.y in both your play1 and play2 functions. The variable app.y will only hold the information of the last audio track loaded. Since your workflow is likely to first load both tracks then play them, you will see the same data in both plots.
function browse1Pushed(app, event)
...
[app.y,Fs]=audioread(app.IMPORTEditField.Value);
%^^^^^
...
end
function play1Pushed(app, event)
...
plot(app.UIAxes,app.timeinseconds,app.y,...
% ^^^^^
...
end
function browse2Pushed(app, event)
...
[app.y,Fs]=audioread(app.IMPORTEditField_2.Value);
%^^^^^
...
end
function play2Pushed(app, event)
...
plot(app.UIAxes_2,app.timeinseconds,app.y,'b',...
% ^^^^^
...
end
10 个评论
Cris LaPierre
2021-12-31
编辑:Cris LaPierre
2021-12-31
its the app.y.
app.file(1).y
Those are two different variables, or more accurately stated, two different fields in the app structure. They are not the same thing. Given the changes you have made, you should no longer be using app.y anywhere. Remove it from your app properties so that cases like this throw an error.
You should be using app.file(1).y:
app.file(1).leftchannel = app.file(1).y(:,1)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
