release() system object error in PhaseVocoder implementation. to read audio from a mic and output it from a speaker...
2 ビュー (過去 30 日間)
古いコメントを表示
%%
% Initialize some variables used in configuring the System objects you
% create below.
WindowLen = 256;
AnalysisLen = 64;
SynthesisLen = 90;
Hopratio = SynthesisLen/AnalysisLen;
%%
% Create a System object to read in the input speech signal from an audio
% file.
%{
reader = dsp.AudioFileReader('SpeechDFT-16-8-mono-5secs.wav', ...
'SamplesPerFrame',AnalysisLen, ...
'OutputDataType','double');
%}
%% *********
% *********
reader = audioDeviceReader('SamplesPerFrame',AnalysisLen, ...
'OutputDataType','double');
% *********
% *********
%%
% Create a buffer System object, which is used for the ST-FFT.
buff = dsp.Buffer(WindowLen, WindowLen - AnalysisLen);
% Create a Window System object, which is used for the ST-FFT. This object
% applies a window to the buffered input data.
win = dsp.Window('Hanning', 'Sampling', 'Periodic');
%%
% Create an FFT System object, which is used for the ST-FFT.
dft = dsp.FFT;
% Create an IFFT System object, which is used for the IST-FFT.
idft = dsp.IFFT('ConjugateSymmetricInput',true,'Normalize',false);
%%
% Create a System object to play original speech signal.
Fs = 8000;
player = audioDeviceWriter('SampleRate',Fs, ...
'SupportVariableSizeInput',true, ...
'BufferSize',512);
% Create a System object to log your data.
logger = dsp.SignalSink;
%%
% Initialize the variables used in the processing loop.
yprevwin = zeros(WindowLen-SynthesisLen,1);
gain = 1/(WindowLen*sum(hanning(WindowLen,'periodic').^2)/SynthesisLen);
unwrapdata = 2*pi*AnalysisLen*(0:WindowLen-1)'/WindowLen;
yangle = zeros(WindowLen,1);
firsttime = true;
%% Stream Processing Loop
% Now that you have instantiated your System objects, you can create a
% processing loop that performs time stretching on the input signal. The
% loop is stopped when you reach the end of the input file, which is
% detected by the |AudioFileReader| System object.
tic
while toc < 10
y = reader();
player(y); % Play back original audio
% ST-FFT
% FFT of a windowed buffered signal
yfft = dft(win(buff(y)));
% Convert complex FFT data to magnitude and phase.
ymag = abs(yfft);
yprevangle = yangle;
yangle = angle(yfft);
% Synthesis Phase Calculation
% The synthesis phase is calculated by computing the phase increments
% between successive frequency transforms, unwrapping them, and scaling
% them by the ratio between the analysis and synthesis hop sizes.
yunwrap = (yangle - yprevangle) - unwrapdata;
yunwrap = yunwrap - round(yunwrap/(2*pi))*2*pi;
yunwrap = (yunwrap + unwrapdata) * Hopratio;
if firsttime
ysangle = yangle;
firsttime = false;
else
ysangle = ysangle + yunwrap;
end
% Convert magnitude and phase to complex numbers.
ys = ymag .* complex(cos(ysangle), sin(ysangle));
% IST-FFT
ywin = win(idft(ys)); % Windowed IFFT
% Overlap-add operation
olapadd = [ywin(1:end-SynthesisLen,:) + yprevwin; ...
ywin(end-SynthesisLen+1:end,:)];
yistfft = olapadd(1:SynthesisLen,:);
yprevwin = olapadd(SynthesisLen+1:end,:);
% Compensate for the scaling that was introduced by the overlap-add
% operation
yistfft = yistfft * gain;
logger(yistfft); % Log signal
end
%% Release
% Here you call the release method on the System objects to close any open
% files and devices.
release(reader);
%% Play the Time-Stretched Signals
%
loggedSpeech = logger.Buffer(200:end)';
player = audioDeviceWriter('SampleRate', Fs, ...
'SupportVariableSizeInput', true, ...
'BufferSize', 512);
% Play time-stretched signal
disp('Playing time-stretched signal...');
player(loggedSpeech.');
%% Play the Pitch-Scaled Signals
%{
% The pitch-scaled signal is the time-stretched signal played at a higher
% sampling rate which produces a signal with a higher pitch.
Fs_new = Fs*(SynthesisLen/AnalysisLen);
player = audioDeviceWriter('SampleRate',Fs_new, ...
'SupportVariableSizeInput',true, ...
'BufferSize',1024);
disp('Playing pitch-scaled signal...');
player(loggedSpeech.');
%}
displayEndOfDemoMessage(mfilename)
...
i'm trying to run this code and getting the following error,
what does this error meas? and how can i fix it ??
Error using dsp.IFFT/parenReference
Changing the complexity (from real to complex) on input 1 is not allowed
without first calling the release() method.
Error in PhaseVocodeMATLAB003 (line 94)
ywin = win(idft(ys)); % Windowed IFFT
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio Processing Algorithm Design についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!