-1

Can anyone tell me how to stop Handel's Hallelujah playing every time I load a different sound sample.

I am new to Matlab and was working on sample code that loaded it as a .mat file and I don't know how stop it from overriding everything else.

Dee61
  • 3
  • 1
  • 5
  • 7
    It would be much more helpful for you to post your actual code. – Suever Mar 08 '17 at 19:44
  • http://stackoverflow.com/questions/18773349/batch-reading-wav-files-in-matlab-to-create-a-matrix-for-neural-network-training , see the solution to this question – Dee61 Mar 08 '17 at 19:49

1 Answers1

3

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.


Edit: Using code from https://stackoverflow.com/a/18773521/3303546

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
Community
  • 1
  • 1
Cecilia
  • 4,512
  • 3
  • 32
  • 75
  • I have removed the load handel.mat and loaded another m file [p,Fs] = audioread('a01.wav'); sound(p,Fs) even this plays handel in college i had to change machine. – Dee61 Mar 08 '17 at 20:00
  • Did you accidentally save the sample into the file 'a01.wav1'? If you play it with another program, does it contain the correct sound? – Cecilia Mar 08 '17 at 20:05
  • looks like i somehow overwritten 3 samples in my workstation, i deleted them and replaced them and everything playing normally. Thanks – Dee61 Mar 08 '17 at 20:27
  • That would do it. :) – Cecilia Mar 08 '17 at 20:27