0

I am trying to read data from a .wav file from position X to Y specified by user. The code compiles file but for some reason the wavread function is not reading from the specified positions. It returns zero in the y vector. If I don't do like [y,fs]=wavread('Kalimba.wav', [StartingTime EndingTime]); , then the code works fine and returns non zero data.

Why is this happening and how can I solve this?

Here is the code:

 function PlayFromXtoY(StartingTime,EndingTime)

% converting the startingTime and EndingTime to minutes

if StartingTime == 0
    disp('Zero')
    StartingTime=1;

elseif StartingTime < 1
         disp('Start <1')
         StartingTime=StartingTime*10;

    elseif StartingTime >= 1
            disp('Start >=1');
            StartingTime=StartingTime*60;
end

if EndingTime < 1
    disp('End <1');
    EndingTime=EndingTime*10;

elseif EndingTime >= 1
        disp('End >=1');
        EndingTime=EndingTime*60;
end

[y,fs]=wavread('Kalimba.wav', [StartingTime EndingTime]); % returning 0 in y for some reason

wavplay(y,fs);

Regards

1 Answer 1

0

Your first problem is that you perform very strange modifications of your start time and stop time before you invoke wavread. It could help to disp those times just before the call and if hese really make sense.

Most importantly, however, you consider these limits as times while to wavread they are not. According to he documentation, the limits you pass are supposed to be sample numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.