read audio signal. How to choose the right number of input channels???

2 次查看(过去 30 天)
I'm trying to read audio from a file, and these are the properties:
>> PhaseVocoderMATLAB002
reader =
dsp.AudioFileReader with properties:
Filename: '/Users/FatimAlansari/Documents/MATLAB/Examples/signal/ResamplingALinearSequenceExample/HelloWorld.wav'
PlayCount: 1
SamplesPerFrame: 64
OutputDataType: 'double'
SampleRate: 44100
ReadRange: [1 Inf]
buff =
dsp.Buffer with properties:
Length: 256
OverlapLength: 192
InitialConditions: 0
win =
dsp.Window with properties:
WindowFunction: 'Hanning'
WeightsOutputPort: false
Sampling: 'Periodic'
Show all properties
Fs =
44100
player =
audioDeviceWriter with properties:
Device: 'Default'
SampleRate: 44100
Show all properties
player =
audioDeviceWriter with properties:
Device: 'Default'
SampleRate: 44100
Show all properties
and a got the following error when coming to Play time-stretched signal...
Error using audioDeviceWriter/setup
The number of input channels must be less than or equal to 255.
Error in audioDeviceWriter/setupImpl
Error in PhaseVocoderMATLAB002 (line 150)
player(loggedSpeech.');
i replace the number of channel with 255 and still get the same error.
how can i choose the right number of channel to fix this error
  2 个评论
Jan
Jan 2018-12-13
Please show us the code instead of its output. It sounds like setting te number of channels to 255 did not work, so we need to see the code to find the error.
fatima alansari
fatima alansari 2018-12-13
%% Pitch Shifting and Time Dilation Using a Phase Vocoder in MATLAB
% This example shows how to implement a phase vocoder to time stretch and
% pitch scale an audio signal.
WindowLen = 256;
AnalysisLen = 64;
SynthesisLen = 90;
Hopratio = SynthesisLen/AnalysisLen;
%%
% Create a System object to read in the input speech signal from an audio
% file.
%'SpeechDFT-16-8-mono-5secs.wav'
%
reader = dsp.AudioFileReader('HelloWorld.wav', ...
'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 = 44100 %<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
player = audioDeviceWriter('SampleRate',Fs, ...
'SupportVariableSizeInput',true, ...
'BufferSize',512) %<<<<<<< i replaced 512 with 255
% 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.
while ~isDone(reader)
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', 255) %<<<<<<< i replaced 512 with 255 and still have the same error
% Play time-stretched signal
disp('Playing time-stretched signal...');
player(loggedSpeech.');
%% Summary
% This example shows the implementation of a phase vocoder to perform time
% stretching and pitch scaling of a speech signal. You can hear these
% time-stretched and pitch-scaled signals when you run the example.
%% References
% A. D. Gotzen, N. Bernardini and D. Arfib, "Traditional Implementations of
% a Phase-Vocoder: The Tricks of the Trade," Proceedings of the COST G-6
% Conference on Digital Audio Effects (DAFX-00), Verona, Italy, December
% 7-9, 2000.
displayEndOfDemoMessage(mfilename)
i got the following error....
Error using audioDeviceWriter/setup
The number of input channels must be less than or
equal to 255.
Error in audioDeviceWriter/setupImpl
Error in PhaseVocoderMATLAB002 (line 156)
player(loggedSpeech.');

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by