matlab的handel,无论我加载什么样的声音,Matlab都在演奏Handel的哈利路亚[关闭](Matlab playing Handel's Hallelujah no matter wha...

Matlab includes a demo sample of Handel's Hallelujah Chorus. If you run

load handel;

The sample will be stored in the variable y. If you then create an audio player, you can use play to play the sample.

player = audioplayer(y, Fs);

play(player);

My guess (without seeing your code) is that your sample code loads and plays the handel sample as above.

Solution: You need to find the offending lines and comment them out.

In a comment, you say you are using the code from this answer. On itsown, this code does not play any sounds. However, here are the possible locations where you might have added a play function.

Spot 1:

The first block creates two files: 'handel1.wav' and 'handel2.wav'

% create some data (write waves)

load handel.mat; %predifined sound in matlab stored in .mat

audiowrite('handel1.wav',y,Fs); %write the first wave file

audiowrite('handel2.wav',y,Fs); %write the second

clear y Fs %clear the data

As I described above, you can use y to play the sample at any point before the clear command. After the clear command and before any further code, it is not possible to play the sample.

Spot 2:

% reading section

filedir = dir('*.wav'); %list the current folder content for .wav file

Y = cell(1,length(filedir)); %pre-allocate Y in memory (edit from @ Werner)

FS = Y; %pre-allocate FS in memory (edit from @ Werner)

for ii = 1:length(filedir) %loop through the file names

%read the .wav file and store them in cell arrays

[Y{ii,1}, FS{ii,1}] = audioread(filedir(ii).name);

end

In or after the for-loop, you can play the sample with

player = audioplayer(Y{ind_wav,1}, Fs);

play(player);

Where ind_wav is either 1 or 2

Spot 3:

If you have run this code previously, the Y variable may still be in your workspace.

To remove it, run

clear Y

你可能感兴趣的:(matlab的handel)