[QA403] - ASIO Driver - When?

Updated code with added functionality. It reads settings from the ASIO401.toml file, updates them and runs a test, where recorded data are plotted in the end. Looping outputs to inputs should produce a nice sine wave plot.
Some attenuator values takes some time to perform, hence the 1s pause.
To test, copy below into an m file and run it:

OutputAttnVals = [-12, -2, +8, +18];
InputAttnVals = [0.0, 6.0, 12.0, 18.0, 24.0, 30.0, 36.0, 42.0];
OutputAttnVals = [-2];
InputAttnVals = [0.0];
FSampleVals = [48000, 96000, 192000, 384000];
close all;
FSInx = 3;
for(k=1:length(OutputAttnVals))
for(m=1:length(InputAttnVals))
[InputFSlevel, OutputFSlevel, BlockSize]=GetSettings();
PutSettings(InputAttnVals(m), OutputAttnVals(k), BlockSize);
[NewInputFSlevel, NewOutputFSlevel, NewBlockSize]=GetSettings();
if((InputAttnVals(m) ~= NewInputFSlevel)|(OutputAttnVals(k) ~= NewOutputFSlevel)|(BlockSize ~= NewBlockSize))
disp(‘Error: ASIO401.toml was not updated correctly, exiting test’);
break;
end
title = sprintf(‘Fs: %d, InputAtt: %2.1f, OutputAtt: %2.1f’, FSampleVals(FSInx), InputAttnVals(m), OutputAttnVals(k));
TestQADevice(FSampleVals(FSInx), title);
end
end

function PutSettings(InputFSlevel, OutputFSlevel, BlockSize)
%Possible fullScaleOutputLevelDBV values: -12.0, -2.0, +8.0, +18.0
%Possible fullScaleInputLevelDBV values: 0.0, +6.0, +12.0, +18.0, +24.0, +30.0, +36.0, +42.0
Path = getenv(‘userprofile’);
fName = ‘ASIO401.toml’;
fullFilePath = strcat(Path, '', fName);
fid = fopen(fullFilePath, ‘w’);
fprintf(fid, ‘fullScaleInputLevelDBV = %2.1f\n’, InputFSlevel);
fprintf(fid, ‘fullScaleOutputLevelDBV = %2.1f\n’, OutputFSlevel);
fprintf(fid, ‘bufferSizeSamples = %d\n’, BlockSize);

fclose(fid);

end

function [InputFSLevel, OutputFSLevel, BlockSize] = GetSettings()
%Possible fullScaleOutputLevelDBV values: -12.0, -2.0, +8.0, +18.0
%Possible fullScaleInputLevelDBV values: 0.0, +6.0, +12.0, +18.0, +24.0, +30.0, +36.0, +42.0
%Assign default values to output variables, in case ASIO401.toml is missing line(s)
InputFSLevel = 0;
OutputFSLevel = -2;
BlockSize = 1024;
Path = getenv(‘userprofile’);
fName = ‘ASIO401.toml’;
fullFilePath = strcat(Path, '', fName);
fid = fopen(fullFilePath, ‘r’);
%Read the variables from the file
tline = ‘’;
while (ischar(tline))
tline = fgetl(fid);
if(~isempty(strfind(tline, ‘fullScaleInputLevelDBV’)))
inx = strfind(tline, ‘=’);
InputFSLevel = sscanf(tline(inx+1:end), “%d”);
continue;
end
if(~isempty(strfind(tline, ‘fullScaleOutputLevelDBV’)))
inx = strfind(tline, ‘=’);
OutputFSLevel = sscanf(tline(inx+1:end), “%d”);
continue;
end
if(~isempty(strfind(tline, ‘bufferSizeSamples’)))
inx = strfind(tline, ‘=’);
BlockSize = sscanf(tline(inx+1:end), “%d”);
continue;
end
end
fclose(fid);
end

function TestQADevice(FSample, Title)
deviceReader = audioDeviceReader(FSample, ‘Driver’, “ASIO”, ‘BitDepth’, “32-bit float”, ‘NumChannels’, 2);
deviceWriter = audioDeviceWriter(FSample, ‘Driver’, “ASIO”, ‘BitDepth’, “32-bit float”);

[Input_FS_Level, Output_FS_Level, BlockSize] = GetSettings();
setup(deviceWriter,zeros(BlockSize,2));
[audioFromDevice,numOverrun] = deviceReader();
pause(1);

OutputAmpCorrection = 1./(10.^(Output_FS_Level/20));
InputAmpCorrection = (10.^(Input_FS_Level/20));
Amp = 0.5;
tAccumulated = 0;
TotalRec = zeros(2*FSample, 2);
blockCnt = 0;    
tic    
while toc < 2
    acquiredAudio = deviceReader();
    TotalRec(blockCnt*BlockSize+1:(blockCnt+1)*BlockSize, :) = acquiredAudio;
    blockCnt = blockCnt+1;
    t=[0:1:(BlockSize-1)]./FSample+tAccumulated;
    OutputAudio(:,1) = Amp*OutputAmpCorrection*sin(2*pi*1000*t);
    OutputAudio(:,2) = Amp*OutputAmpCorrection*sin(2*pi*2000*t);
    tAccumulated = tAccumulated + BlockSize/FSample;
    deviceWriter(OutputAudio);
end
disp('Recording complete.')
release(deviceReader);
release(deviceWriter);
figure    
plot(TotalRec);
title(Title);

end

3 Likes

Hi @MartinLarsen, this is awesome, thanks for sharing!

If your Matlab environment can call python, then you could also call directly into the PyQa40x library and get fully calibrated readings from the QA40x.

2 Likes

Thanks, I’ll check it out - It should be possible according to Mathworks.
I will check the Python code and see if I can make something similar in C++, I will let you know if I’m succesfull in either of the two tracks. Great product!
Kind Regards,
Martin

1 Like

Hallo Martin, i am also interesting in using Matlab for Home use with QA403 and my other Lab Stuff like Osciloskope, Funktiongenerator and so on but i am unsure what Addon Modules i am need to Buy for Matlab Home edition (also New on Matlab :wink: )

Home License cost 119€ + Tax in Germany
Addons 35€ per ADDON not realy Home friendly, so can you give me please a little Advice what i realy need to start with ?

Stimulink i guess as minimum for Simulations right?
And may be Curve Fitting Toolbox for showing Graph’s (Measurements)

As Exsample i would like to make me an Curvetracer with Scope and and Generator Control or and may be an Bodeplotter.

I know thats works also on Python for no Costs but i am Interesting in Matlab :wink:

I am a bit unsure what i realy need for Starting with.

Robert

Here are my thoughts and findings so far:
First, a lot of effort has gone into making a Python control for the QA40x, and I believe that it should be the common starting point, regardless of what language we are using, simply because we can rely on that software to be updated. I can see that matlab can use python classes, and the same is true for C/C++. So my preferred solution is to use the Python library from Matlab and from C++.

Second, Python takes quite some configuration to work - Numpy needs to be installed, the right Python version needs to installed and cofigured in Matlab (Matlab only supports a number of Python versions, so you need later than 2020 to support Python 3.9).

I am currently struggling to get these things configured and running on my system, so for now I don’t have a better Matlab solution than the ASIO driver - but I think that is a good starting point :slight_smile:

Sorry for not reading your mail properly: if we get a working Matlab solution, you only need the basic Matlab license. Python is very close to Matlab, and I honestly recommend that you try out Python before considering Matlab.

1 Like

Hi Martin, thanks for youre Help.

I tried already Python with Help from other People with Bodeplotting and its worked but was a bit of work to get the Environment running on my Computer.

I hoped that Matlab is more Visual and a bit easier to learn.

I have only a little knowing with Softwareprogramming like C# , Arduino Programming and Microchip Microcontroller Programming.

https://www.eevblog.com/forum/testgear/rigol-hdo1000-and-hdo4000-12bit-oscilloscopes-launched-in-china/1225/

Robert

Hi @Frunse, may I suggest you try JupyterLab Desktop? It’s a very nice environment for running Python, and it can setup the python interpreter for you too. At the link below, you’ll see installers for Win/Mac/Linux at link 1)

And then, download the zip for PyQa40x from link 2. To do this, go to link 2 and look for the green button labeled “Code”. Click on that and download the zip. Open the zip and navigate through LibTest and look for FirstPrinciples.py. Open that. Copy all the code in there, and paste it into your JupyterLab Desktop session. Then click the right arrow at the top of the JupyterLab notebook to run the code. You should be greeted with some graphs (pasted below).

I can put some more details on at the github readme if you get stuck. But I do think Python is a better choice for algorithm development over matlab.

  1. GitHub - jupyterlab/jupyterlab-desktop: JupyterLab desktop application, based on Electron.
  2. GitHub - QuantAsylum/PyQa40x: Python library for bare-metal interface to QA40x hardware (including calibration)

1 Like

Hallo and yes thats what i used Jupiter Notebook to runn that Python Script.

for Bode Plot :wink:

I guess i need to go more into it.

Thank You Martin

Robert

Hey Etienne, thanks so much for your work! How much time and money do you need to include the relais control in a HMI that is started by the click on „ASIO controlpanel“?

1 Like