|
I have a GUI under development. Fairly advanced, with multiple tabs, etc, and made using Guide. I'm wanting to put a "Volume Meter" on it, that runs in realtime, displaying signal levels from the sound card. I have a timer callback that updates the plot. So, the update function is called 4 times a second, and it grabs data from the sound card, calculates the values to display and updates the plot in hte GUI. I'm using a bar plot. I set the 'NextPlot' value to 'UpdateChildren' in Guide editor so (I hoped) the axis props would not be reset each time new data is plotted.
The data from the card is betwee 0 and 1, converted to dB, so between -Inf (practically speaking around -110) and 0 dB. To make it plot the way I want (like a VU meter, with the bars coming up from the bottom), I added 110 to the data stream and set the YLim property to [0 110]. I set the Yticks to [0 20 40 60 80 90 100 110], and Ylabels to [-110 -90 -70 -50 -30 -20 -10 0], and both set to 'Manual'. Ylim mode also set to manual.
I should also mention that I am plotting two types of data (rms and peak) for left/right/and left+right channels. SO, that means I am constructing a data matrix to use in the bar() plot call. That means there are multiple barseries (I did do a test of just plotting a single value and the problem persists though - so I don't think this is the issue).
When the GUI figure is initially generated, the Y limits look as desired. BUT, when the first data is plotted, the y limits are changed - for example to -110 to -70. Additionally, the bar plots that DO show up don't exactly match the actual values that are being plotted. I have tried adding code to try to manually set the limits, which either have no effect, or I'm getting strange error messages, or other unintended results. The callback code is listed below, some of the things I tried to fix this are shown remmed out. Any help is appreciated, I seem to be in over my head here.
function UpdateMeter(hObject, event, handles)
% SPLmeterAxis is the Tag for the axis in the GUI
% get audio data
[Audiodata absrecposition overflow cstarttime]= PsychPortAudio('GetAudioData', handles.pahandle);
% calculate rms and peak values for Left, Right, and Left/Right mean channels
Audiodata = Audiodata';
rms = 20.*log10((sqrt(mean(Audiodata.^2))));
peak = 20.*log10(max(abs(Audiodata)));
LRmean = 20.*log10(sqrt(mean(mean(Audiodata.^2))));
% generate plotting matrix, adding 110 to the data to match manually set y limits, in order to %% get desired bar plots coming up from the bottom of the plot.
plotdat = [peak(1) rms(1);peak(2) rms(2);NaN LRmean ] +110
% PLOT
% axis(handles.SPLmeterAxis,'manual')
h=bar(handles.SPLmeterAxis, plotdat,1);
set(h(1),'facecolor','red','linewidth',1) %this shouldn't be needed but apparently it is!
%%these do nothing or generate errors
% set(h,'YLim',[0,110],'YLimMode','manual')
% set(handles.SPLmeterAxis,'YLim',[0,110],'YLimMode','manual')
% axis(handles.SPLmeterAxis,[0 4 0 110])
%%both of these generate a new axis and error about vector needing 2, 4, or 6 elements (?!)
% axis(h(1),[0 4 -110 0])
% axis(h,[0 4 -110 0])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Platform is WinXP, Matllab 7.12.0
|