Main Content

uiaudiometer

Create an audio meter component

Since R2023b

    Description

    meter = uiaudiometer creates an audio meter in a new figure.

    example

    meter = uiaudiometer(parent) specifies the object in which to create the audio meter.

    example

    meter = uiaudiometer(___,Name=Value) specifies audio meter properties using one or more name-value arguments.

    Use the audio meter component with UI figures created by the uifigure function. The audio meter component is also available in the App Designer Component Library. For an example that builds an app using the audio meter component, see Create an App to Play and Visualize Audio Files.

    example

    Examples

    collapse all

    Create an audio meter component using uiaudiometer. By default, the function creates a figure for the meter object using the uifigure function.

    meter = uiaudiometer

    Figure contains an object of type uiaudiometer.

    meter = 
      Meter with properties:
    
                   Value: [-80 -80]
              ValueUnits: 'dBFS'
                  Limits: [-80 3]
             LevelColors: [3x3 double]
        LevelColorLimits: [3x2 double]
             Orientation: 'vertical'
         MaxHoldDuration: 3
                Position: [10 10 80 400]
    
      Use GET to show all properties
    
    

    Create a UI figure window to contain the audio meter component. Call uiaudiometer with the figure window to specify it as the parent object.

    fig = uifigure;
    meter = uiaudiometer(fig);

    Figure contains an object of type uiaudiometer.

    Create an audio file reader and an audio device writer to read an audio file and play it. Use audioLevelMeter to create a peak level meter object.

    reader = dsp.AudioFileReader("RockDrums-44p1-stereo-11secs.mp3");
    player = audioDeviceWriter(reader.SampleRate);
    peakMeter = audioLevelMeter(SampleRate=reader.SampleRate, ...
        WindowLength=reader.SamplesPerFrame);

    Create an audio meter UI component.

    uimeter = uiaudiometer;

    Figure contains an object of type uiaudiometer.

    In a streaming loop, read in the audio and use the audio meter to display the measured peak levels. Use drawnow limitrate to periodically update the figure while in a stream processing loop.

    while ~isDone(reader) && isgraphics(uimeter)
        % Read an audio frame from file
        x = reader();
        % Compute peak levels and update the meter
        uimeter.Value = peakMeter(x);
        % Playback the audio frame
        player(x);
        drawnow limitrate
    end

    Figure contains an object of type uiaudiometer.

    As a best practice, release the System objects.

    release(reader);
    release(peakMeter);
    release(player);

    Use the LevelColorLimits and LevelColors properties to define four value levels and their corresponding colors. Specify the colors as hexadecimal color codes.

    levelLimits = [-80 -30; -30 -12; -12 -3; -3 3];
    levelColors = ["#77AC30" "#EDB120" "#D95319" "#A2142F"]';
    meter = uiaudiometer(LevelColorLimits=levelLimits,LevelColors=levelColors);

    Figure contains an object of type uiaudiometer.

    Set the value of the meter to zero to see the different levels displayed.

    meter.Value = 0;

    Figure contains an object of type uiaudiometer.

    Create an audio meter component. By default the meter is oriented vertically.

    meter = uiaudiometer;

    Figure contains an object of type uiaudiometer.

    Change the orientation of the meter by using dot notation to set the Orientation property to "horizontal".

    meter.Orientation = "horizontal";

    Figure contains an object of type uiaudiometer.

    Input Arguments

    collapse all

    Parent container, specified as a Figure object created using the uifigure function or one of its child containers: Tab, Panel, ButtonGroup, or GridLayout. If you do not specify a parent container, MATLAB® calls the uifigure function to create a new Figure object that serves as the parent container.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: meter = uiaudiometer(Orientation="horizontal")

    For a list of audio meter properties and their descriptions, see Meter Properties.

    Output Arguments

    collapse all

    Audio meter component, returned as an object.

    Version History

    Introduced in R2023b