Skip to main content
Skip table of contents

Processing audio through Audio Weaver Design using MATLAB

About This Guide

This application note describes ways to process input audio through Audio Weaver Design (AWD) using MATLAB scripts.

How to load a system

There are two ways to load an Audio Weaver Design (AWD): -

  1. Load from file: Use the following command to load an AWD from a file on the computer.

MATLAB
GSYS = load_awd(fullfile(dirStr, ‘Example.awd'));
  1. Grab from the AudioWeaver Designer : This is a quicker method of opening the AWD for this command to work, AudioWeaver Designer should be open.

MATLAB
GSYS = get_gsys;

Configure the for Non-Real Time Processing

The AudioWeaver Server searches for a specific command to configure a Real Time vs a non-Real Time System.

For a Non-Real Time, the following command is set to 0 which by default on 1 for assuming a Real Time System by default.

MATLAB
SYS.targetSpecificInfo.RT = 0;

Setting Internal Build Settings

  • Internal Settings to match the Designer.

    • Specify the Datatype to match the designer.

    • Validate Top Level Input Pin

    • Validate Top Level Out Pin

    • Validate Top Level Block Sizes

The following command can be used to set the designer settings.

CODE
global AWE_INFO;

Building the System on Designer

The following command is used to build the system with the above-mentioned settings.

CODE
SYS = build(SYS);

Example – AutoAmp

The Application Note has attached .m file along with AutoAmp_Example.awd as examples for the audio processing. In this example a signal test chirp is generated between 100Hz - 20kHz.

MATLAB
% ----------------------------------------------------------------------
% Load a system or grab it from Designer
% ----------------------------------------------------------------------

P = mfilename('fullpath');

[dirStr, baseStr, extStr] = fileparts(P);

if (1)

   % Load from file

    GSYS = load_awd(fullfile(dirStr, 'AutoAmp_Example.awd'));

else

	% Grab from Designer

    GSYS = get_gsys;

end

SYS = GSYS.SYS;

% ----------------------------------------------------------------------
% Configure the system for non-real-time processing
% (This disables double buffering of the I/O pins)
% ----------------------------------------------------------------------

SYS.targetSpecificInfo.RT = 0;

% ----------------------------------------------------------------------
% Set internal build settings to match Designer
% ----------------------------------------------------------------------

global AWE_INFO;

AWE_INFO.buildControl.matchDataType = 0;

AWE_INFO.buildControl.matchDataType = 0;

AWE_INFO.buildControl.validateTopLevelOutputPin = 0;

AWE_INFO.buildControl.validateTopLevelBlockSizes = 0;

% ----------------------------------------------------------------------
% Build the system
% ----------------------------------------------------------------------

SYS = build(SYS);

% ----------------------------------------------------------------------
% Generate a test signal
% ----------------------------------------------------------------------

numChannels = SYS.inputPin{1}.type.numChannels;

SR = SYS.inputPin{1}.type.sampleRate;

blockSize = SYS.inputPin{1}.type.blockSize;

L = SR;	  % 1 second of audio

%NUM_BLOCKS = 100;

numBlocks = round(L / blockSize);

% The actual length

L = numBlocks * blockSize;

N = (0:(L-1)).';

x = chirp(N/SR, 100, L/SR, 20000) * 0.1;

X = x * linspace(1, 2, numChannels);

% ----------------------------------------------------------------------
% Processing the input test signal
% ----------------------------------------------------------------------

% [SYS, Y] = process(SYS, {X}, numBlocks);

% Y = Y{1};

if (0) % 0 or 1

    % Process everything in one call if 1

    WIRE_IN = {X}; % X is input data.  Turn into system input wire

    [SYS, WIRE_OUT] = process(SYS, WIRE_IN, numBlocks); % call process function, tell how many blocks, and give input data

    Y = WIRE_OUT{1};

else

    % Process block-by-block if 0

    Y = [];

    for i = 1:numBlocks % loop over all the blocks

        if (i == 200) % if we're at block number 200, change the mute to announcements

            % Add a Announcement Noise with every 200 block

            SYS.CellPhoneMute.isMuted = 0;

        elseif (i == 400)

            SYS.PinkNoiseMute.isMuted = 0;

        elseif (i == 700)

            SYS.WhiteNoiseMute.isMuted = 0;

        end

        startIndex = (i - 1) * blockSize + 1; % Start index of data

        endIndex = startIndex + blockSize - 1; % End index of data

        WIRE_IN = {X(startIndex:endIndex, :)}; % Get data out of the input array from the correct indexes (get both channels)

        [SYS, WIRE_OUT] = process(SYS, WIRE_IN, 1); % Process 1 block, and get SYS object back, get wire output

        fprintf(1, 'Processing block %d of %d\n', i, numBlocks); % 100 blocks, 1 block at a time

        if (isempty(Y)) % Accumulate all the wire output into Y, 1 block at a time

            Y = WIRE_OUT{1};

        else

            Y = [Y; WIRE_OUT{1}];

        end

    end

end

% Plot data

figure;

subplot(211);

plot(X);

title('Input Plot'); 

subplot(212);

plot(Y);

title('Output Plot'); 

===================================================================================

Output Processing

The processing can be configured by changing the number of audio blocks to 100 or varying it according to the block size in the AWD. The output plot for 100 blocks is as shown.

Figure 1 : Plot of input vs output for 100 blocks

Figure 2: Output vs Input Plot for 750 Blocks

AutoAmp_Example.awd

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.