필터 지우기
필터 지우기

How to use audioDeviceWriter ?

조회 수: 7 (최근 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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with DSP System Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by