How to use audioDeviceWriter ?

1 回表示 (過去 30 日間)
Dora Kokai
Dora Kokai 2020 年 11 月 23 日
編集済み: Dora Kokai 2020 年 11 月 28 日
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)

回答 (1 件)

Jimmy Lapierre
Jimmy Lapierre 2020 年 11 月 24 日
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 件のコメント
Walter Roberson
Walter Roberson 2020 年 11 月 26 日
Just use
audiowriter(y(:));
Walter Roberson
Walter Roberson 2020 年 11 月 26 日
Your g is a scalar coming out of your function.

サインインしてコメントする。

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by