release() system object error in PhaseVocoder implementation

23 views (last 30 days)
I was recently checking out this implementation of a PhaseVocoder:
you can access, edit and use the code calling:
edit dspPhaseVocoder
I set it all up with only some minor changes, such as inserting some better variable namings, taking out the stream sound playing and varied function in- and output. The problem starts when I try to get it running, because the script will only process certain files without any understandable reason.
The unprocessable files produce the following error:
Error using dsp.IFFT/step
Changing the complexity (from real to complex) on input
1 is not allowed without first calling the release()
method.
Error in PhaseVoc (line 71)
dataWindow = step(window, step(ifft, dataS));
When debugging the code I've noticed that each but the last chunk read from the AudioFileReader system object is an all zeros vector which of course doesn't make sense. I have tried to use a copy paste version of the above link, but got the same error. Like I said, for some files in works, for others not.
Can anyone reproduce and/or help solve this error? Here's my version of the code:
% PhaseVoc.m
% following example shows how to increase pitch without shortening the signal
% signal stretched by 1.5 & sampling rate increased by 1.5
% [data, fs] = PhaseVoc('subdir/filename.wav', 1.5);
% sound(data,fs);
function [dataPhaseVoc, fsPhaseVoc] = PhaseVoc(path, factor)
%%general config params
WindowLen = 1000;
AnalysisLen = 100;
SynthesisLen = round(AnalysisLen * factor);
Hopratio = SynthesisLen/AnalysisLen;
source = dsp.AudioFileReader(path, 'SamplesPerFrame', AnalysisLen);
player = dsp.AudioPlayer('SampleRate', source.SampleRate);
%%ST-FFT system objects
% buffer object
buffer = dsp.Buffer(WindowLen, WindowLen - AnalysisLen);
% create window sys obj for st-fft used to window buffer data
% used for smooth transitioning between steps
window = dsp.Window( 'Hanning', 'Sampling', 'Periodic' );
%%FFT & IFFT system objects
fft = dsp.FFT;
ifft = dsp.IFFT( 'ConjugateSymmetricInput', true, ...
'Normalize', false );
%%system objects for original signal
fs = source.SampleRate;
% sys obj used for logging data
dataLog = dsp.SignalSink;
%%variables for processing loop
dataPrevWin = zeros(WindowLen - SynthesisLen, 1);
gain = 1 / (WindowLen * sum(hanning(WindowLen, 'periodic').^2) / SynthesisLen);
unwrapData = 2 * pi * AnalysisLen * (0 : WindowLen-1)' / WindowLen;
dataAngle = zeros(WindowLen, 1);
firstTime = true;
%%processing loop
while ~isDone(source)
audio = step(source);
% st-ftt
% fft of a windowed buffered signal
dataFFT = step(fft, step(window, step(buffer, audio)));
% convert complex data from fft to magnitude and phase
dataMagnitude = abs(dataFFT);
dataPrevAngle = dataAngle;
dataAngle = angle(dataFFT);
% 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 = (dataAngle - dataPrevAngle) - unwrapData;
yUnwrap = yUnwrap - round(yUnwrap / (2*pi)) * 2*pi;
yUnwrap = (yUnwrap + unwrapData) * Hopratio;
if firstTime
dataAngleS = dataAngle;
firstTime = false;
else
dataAngleS = dataAngleS + yUnwrap;
end
% convert magnitude and phase to complex numbers
dataS = dataMagnitude .* complex( cos(dataAngleS), sin(dataAngleS) );
% inverse windowed fft (ist-fft)
dataWindow = step(window, step(ifft, dataS));
% overlap-add result
overlapAdd = [ dataWindow(1 : end-SynthesisLen , :) + dataPrevWin; ...
dataWindow(end-SynthesisLen+1 : end , :)];
dataIST_FFT = overlapAdd(1:SynthesisLen , :);
dataPrevWin = overlapAdd(SynthesisLen+1 : end , :);
% compensate for scaling introduced by overlap-add
dataIST_FFT = dataIST_FFT * gain;
step(dataLog, dataIST_FFT); % log signal
step(player, audio); % playback original signal
end
%%create output from logged signal
dataPhaseVoc = dataLog.Buffer(200:end)';
fsPhaseVoc = fs*factor;
%%Release all system objects
release(source);
release(player);
release(buffer);
release(window);
release(fft);
release(ifft);
release(dataLog);
end

Answers (2)

Juan Gremes
Juan Gremes on 21 May 2015
I believe simply adding:
release(ifft);
right before the line:
dataWindow = step(window, step(ifft, dataS));
will solve the problem.
I used the code found in that website you mentioned and added
release(hifft);
and it worked fine.

Faisal Nadeem
Faisal Nadeem on 11 Mar 2019
Error using comm.LDPCEncoder/step
Changing the size or datatype on input 1 is not allowed without first calling the release() method.
Use following
release(hEnc)
Code_word_temp= step(hEnc, (decoded_msj2t2));

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!