Issues with audio device writer to read the output signal.

5 Ansichten (letzte 30 Tage)
charbel hourani
charbel hourani am 25 Jan. 2023
Beantwortet: Manoj Mirge am 23 Mär. 2023
Dear Community,
I am trying to build a code based on the ISO 9613-1 standard, that can filter an audio track based on atmospheric absorption.
In the following code, I created a user interface where I can input, Altitude, temperature, Humidity, Initial level and distance.
But when I started adding the apply button and call back functions to make sure that all the variables are entered. I am encountering problems with the "deviceWriter(audioOut);"
With the following error message :
Not enough input arguments.
Error in LiveEditorEvaluationHelperE678951713>apply_callback (line 133)
if ~isDeviceOpened
Error while evaluating UIControl Callback.
I need help please, finishing this code, by executing correctly the part where the audio must be played out on the computer speakers after being filtered.
Thank you in advance
% Create a user interface to input data
f = figure;
% Create text boxes for the different variables
global t1 t2 t3 t4 t5 isDeviceOpened
isDeviceOpened = false;
t1 = uicontrol('Style', 'edit', 'String', '10', 'Position', [20, 350, 100, 20]);
t2 = uicontrol('Style', 'edit', 'String', '20', 'Position', [120, 350, 100, 20]);
t3 = uicontrol('Style', 'edit', 'String', '70', 'Position', [220, 350, 100, 20]);
t4 = uicontrol('Style', 'edit', 'String', '100', 'Position', [320, 350, 100, 20]);
t5 = uicontrol('Style', 'edit', 'String', '', 'Position', [420, 350, 100, 20]);
% Create a button to apply the callback function
apply_button = uicontrol('Style', 'pushbutton', 'String', 'Apply', 'Position', [20, 100, 80, 20], 'Callback', {@apply_callback, t1, t2, t3, t4, t5});
% Create labels for the text boxes
uicontrol('Style', 'text', 'String', 'Altitude [m]:', 'Position', [20, 375, 100, 30]);
uicontrol('Style', 'text', 'String', 'Tempreture [ºC]:', 'Position', [120, 375, 100, 30]);
uicontrol('Style', 'text', 'String', 'Humidity [%]:', 'Position', [220, 375, 100, 30]);
uicontrol('Style', 'text', 'String', 'Initial Sound Level [dB]:', 'Position', [320, 375, 100, 30]);
uicontrol('Style', 'text', 'String', 'Distance [m]:', 'Position', [420, 375, 100, 30]);
oneThirdOctaveGraphicEQ = graphicEQ;
graphicEQ = oneThirdOctaveGraphicEQ;
function apply_callback(hObject, eventdata, t1, t2, t3, t4, t5, isDeviceOpened)
% Get the value of the edit text box
Altitude = str2double(get(t1, 'String')); % Expressed in meters over see level
Tc = str2double(get(t2, 'String')); % Tempretures in Degree Celsius
hr = str2double(get(t3, 'String')); % Relative humidity as a percentage
LdBi = str2double(get(t4, 'String')); % Initial SoundLevel in dB at 1m from source
d = str2double(get(t5, 'String')); % Distance in meters from source
if isnan(Altitude) || isnan(Tc) || isnan(hr) || isnan(LdBi) || isnan(d)
error('Invalid input')
end
%---------------------------------------------------------------------------------------------
%Initial Reference Data
Tk= Tc + 273.15; % Ambient atmospheric tempreture in Kelvin K
To=293.15; % Reference atmospheric tempreture in Kelvin 20C
pr=101.325; % Reference ambient atmospheric pressure in kPa
pa = pr * exp((-9.80665 * 0.0289644 * Altitude)/(8.31432 * Tk));% Ambient atmospheric pressure in kPa based on altitude
To1=273.16; % Triple-point isotherm temp: 273.16 K = 273.15 + 0.01 K (0.01°C)
p0=0.00002;
x=0.1151; % A help factor to shorten the formula
pi=p0*10^(LdBi/20); % Initial sound pressure ampliture in Pa
psat = pr * 10^((-6.8346 * (To1 / Tk)^1.261) + 4.6151); % Saturation vapor pressure
h = hr * (psat / pa); % Molar concentration of water vapor as percentage
frO = (pa / pr) * (24 + 4.04 * 10^4 * h * ((0.02 + h) / (0.391 + h))); % Oxygen relaxation frequency
frN = (pa / pr) * (Tk / To)^(-1/2) * (9 + 280 * h * exp(-4.170 * ((Tk / To)^(-1/3)-1))); % Nitrogen relaxation frequency
%---------------------------------------------------------------------------------------------
% Third Octave center frequncy for the garphic EQ in Hz based on ISO
oneThirdCenterFreqArray = [25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 ...
1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
%---------------------------------------------------------------------------------------------
f = oneThirdCenterFreqArray; % Third Octave center frequncy for the garphic EQ in Hz
for ii=1:numel(f)
z = 0.1068 * exp (-3352 / Tk) * (frN + f(ii)^2 / frN)^(-1); % A help factor to shorten the formula
y = (Tk / To)^(-5/2) * (0.01275 * exp (-2239.1 / Tk) * (frO + f(ii)^2 / frO)^(-1) + z); % A help factor to shorten the formula
alpha = 8.686 * f(ii)^2 * ((1.84 * 10^(-11) * (pa / pr)^(-1) * (Tk / To)^(1/2)) + y); % Pure tone attenuation coeffiecnt in dB/m for Atmospheric Absorption
pt = pi * exp(-x * alpha * d); % Sound pressure amplitude in Pa
AtmosphericAbs=alpha*d; % Atmospheric attenuation due to distance
Aabs=20 * log10(pt/p0); % Atmospheric attenuation due to distance in dB
Gain(ii) = Aabs - LdBi; % Atmospheric attenuation due to distance in dB per frequency
end
%---------------------------------------------------------------------------------------------
% Import Audio Track from Directory
frameLength = 1024;
fileReader = dsp.AudioFileReader('/Users/user/Documents/Music repertoire/TEST MUSIC/What Is Love 2016.mp3','SamplesPerFrame',frameLength);
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);
% ------------------------------
% Perform Graphic EQ Filtering according to Absorption Calculations
%release(graphicEQ); % Release system memory from previous run
oneThirdOctaveGraphicEQ.Bandwidth = '1/3 octave';
oneThirdOctaveGraphicEQ.Gains = Gain;
equalizer = graphicEQ;
visualize(equalizer);
% Playing the filtered audio out
while ~isDone(fileReader)
audioIn = fileReader();
audioOut = equalizer(audioIn);
%Opening the audioDeviceWriter
if ~isDeviceOpened
deviceWriter = audioDeviceWriter('SampleRate',fs);
setup(deviceWriter);
isDeviceOpened = true;
end
%Playing the sound
deviceWriter(audioOut);
% ...
% ...
% Close the audioDeviceWriter
release(deviceWriter);
drawnow limitrate % required to update parameter
end
end

Antworten (1)

Manoj Mirge
Manoj Mirge am 23 Mär. 2023
Hi charbel,
You have not provided isDeviceOpened argument to your apply_callback callback function while creating a uicontrol pushbutton.
% In below line, you have only given t1,t2,t3,t4 and t5 as arguments to your callback function.
apply_button = uicontrol('Style', 'pushbutton', 'String', 'Apply', 'Position', [20, 100, 80, 20], 'Callback', {@apply_callback, t1, t2, t3, t4, t5});
When user presses the Apply button, it will invoke the button pushed callback with following syntax:
apply_callback(hObject,eventdata,t1,t2,t3,t4,t5);
Since you have not provided isDeviceOpened argument to your function, if it tries to use the isDeviceOpened argument inside it, you will get the error stating ‘Not enough input arguments .
To make your code work provide isDeviceOpened argument in the callback function while creating the button.
apply_button = uicontrol('Style', 'pushbutton', 'String', 'Apply', 'Position', [20, 100, 80, 20], 'Callback', {@apply_callback, t1, t2, t3, t4, t5,isDeviceOpened});
Hope this helps.

Kategorien

Mehr zu Measurements and Spatial Audio finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by