How to use audioDeviceWriter ?
Afficher commentaires plus anciens
I would like to use a compressor/expander and I get the following message:
Error using audioDeviceWriter/setup
The number of input channels must be less than or equal to 255.
Error in audioDeviceWriter/setupImpl
Error in gyak (line 29)
audiowriter(y); - Show complete stack trace
The compressor's code is from the dafx book and i would like to see the result in timescope.
function[y,g] = compexp(x)
CT=0.00016;
CS=1;
ET=2.6;
ES=5;
tav = 0.01;
at = 0.03;
rt = 0.003;
delay = 150;
xrms = 0;
g = 1;
buffer = zeros(1,delay);
for n = 1:length(x)
xrms = (1-tav) * xrms + tav * x(n)^2;
X = 10*log10(xrms);
G = min([0, CS*(CT-X), ES*(ET-X)]);
f = 10^(G/20);
if f < g
coeff = at;
else
coeff = rt;
end
g = (1-coeff) * g + coeff * f;
y(n) = g * buffer(end);
buffer = [x(n) buffer(1:end-1)];
end
end
%using
frameLength = 1024;
audioreader= dsp.AudioFileReader( ...
'Filename','mintaa.wav', ...
'SamplesPerFrame',frameLength);
audiowriter = audioDeviceWriter( ...
'SampleRate',audioreader.SampleRate);
scope = timescope( ...
'SampleRate',audioreader.SampleRate, ...
'TimeSpanOverrunAction','Scroll', ...
'TimeSpanSource','property',...
'TimeSpan',1, ...
'BufferLength',44100*4, ...
'YLimits',[-1 1], ...
'ShowGrid',true, ...
'LayoutDimensions',[2,1], ...
'NumInputPorts',2, ...
'ShowLegend',true, ...
'Title',['Original vs. Compressed Audio (top)' ...
' and Compressor Gain in dB (bottom)']);
while ~isDone(audioreader)
x = audioreader();
y = compexp(x);
audiowriter(y);
x1 = x(:,1);
y1 = y(:,1);
scope([x1,y1]);
end
release(audioreader)
release(compexp)
release(audiowriter)
release(scope)
Réponses (1)
Jimmy Lapierre
le 24 Nov 2020
0 votes
I suspect that compexp returns a row vector instead of a column vector, so it looks like 1024 channels. Try pre-allocating y before your loop in compexp (i.e. y = zeros(x)) so that it's a column like x.
3 commentaires
Dora Kokai
le 26 Nov 2020
Walter Roberson
le 26 Nov 2020
Just use
audiowriter(y(:));
Walter Roberson
le 26 Nov 2020
Your g is a scalar coming out of your function.
Catégories
En savoir plus sur Audio Processing Algorithm Design dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!