Invalid Audio File, too many samples

Hi all,
I have tried to implement the following codes:
H = ones(16, 1);
siz = wavread('hello.wav', 'size');
tot_samples = siz(1); %/ 74539 samples
a=1;
while(a<tot_samples)
x = wavread('hello.wav', [a a+15]); %/ read 16 samples each time
y=H*x; %/ multiply together
a = a + 16;
end
sound(y); %/ plays all the y
I keep getting "Invalid Wave File. Reason: Sample limits out of range." How can i get solve this error?
Also, after multiplying, how can i add up all the "y" and play it as a single audio file?

 채택된 답변

Wayne King
Wayne King 2012년 9월 24일
편집: Wayne King 2012년 9월 24일

0 개 추천

I'm not sure why you want to multiply by H here since it is just a vector or ones, but ok. I have a file called test.wav that has 20,000 samples and this works for me. I read 10 samples at time because 10 divides 20,000.
H = ones(10,1);
k = 1;
a=1;
while(a<=(tot_samples-9))
x = wavread('test.wav', [a a+9]);
y(:,k) = H.*x;
a = a+10;
k = k+1;
end
At the end of the loop I have a matrix, y, which is 10x2000. Note that 10*2000 is the length of the original signal. You can create the signal with:
sig = reshape(y,size(y,1)*size(y,2),1);
now sig and the original signal from the .wav are the same length and in this case, identical.
If course, you can preallocate y because you know going in what size the matrix will be.

댓글 수: 5

Rick
Rick 2012년 9월 24일
편집: Rick 2012년 9월 24일
I see, what if I now use:
H = hadamard(16);
I have to change the size of matrix "x" to 16 by 16?
or H to 16 by 1?
That very much depends on what you are trying to do with the Hadamard matrix, if you just want the matrix-vector product of each sequence with the matrix use.
y(:,k) = H*x;
Rick
Rick 2012년 9월 24일
편집: Rick 2012년 9월 24일
I see, I am trying to achieve a speech scrambler with just
y =H*x;
where y is the output corresponding to the input, and x is the input in 16x1 speech vector.
EDIT:
i have put the output into a:
y(:,1) = H*x; %/ 1-channel
After the while loop:
i tried to listen to the output, all i have got is just a "tsk" sound. I believe that i am still listening to the last 15 samples of the output.
Is there anyway, where i can listen to the whole output instead of the last 15 samples?
Why are you doing it like this:
y(:,1) = H*x;
of course you are just getting the last samples, you simply keep replacing the first column of y with the latest H*x, that is why I did
k = 1; % outside loop
and then
y(:,k) = H*x;
k = k+1;
inside the loop.
then after the loop finished
sig = reshape(y,size(y,1)*size(y,2),1);
Rick
Rick 2012년 9월 24일
I see, thanks for the enlightenment. :)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Wayne King
Wayne King 2012년 9월 24일

1 개 추천

You cannot have the first sample being 0, MATLAB indexes from 1.

댓글 수: 4

Rick
Rick 2012년 9월 24일
I see, I have changed it to start from 1. But i still getting the error:
"Error using wavread (line 164) Invalid Wave File. Reason: Sample limits out of range."
Is it because I have 74539 samples and I'm adding in frames of 16? so for the last frame, there is not enough samples in the wav file?
How can i solve this?
Thomas
Thomas 2012년 9월 24일
look at the edits to my answer you have a couple of issues that are causing the problem..
Wayne King
Wayne King 2012년 9월 24일
편집: Wayne King 2012년 9월 24일
It also stands to reason that you cannot have your a variable, a, get closer to the end of the file than 15 samples, so your terminating condition should be
tot_samples-15
not while(a<tot_samples). And why did you pick a length that is not a divisor of the total file length?
Rick
Rick 2012년 9월 24일
I see.
Because I was given a project to use the given frame of 16 samples/frame.

댓글을 달려면 로그인하십시오.

Thomas
Thomas 2012년 9월 24일
편집: Thomas 2012년 9월 24일

1 개 추천

From, a cursory glance: you have initialized
i=0 There is no index of 0 in matlab and so it cannot play (0-15) range Also your way of calling ones is incorrect
try H=ones(16,1)
Try not to use 'i' as variable since it is in Matlab (complex function). In matlab the way to put comments is use '%' and not '*/'
EDIT
Also you are sampling upto tot_Sample when you have to until (tot-samples -15) otherwise you will run out of bounds again on the top end

댓글 수: 3

Rick
Rick 2012년 9월 24일
편집: Rick 2012년 9월 24일
I have changed to this:
while(i<tot_samples-15)
but won't this code skip the last 15 samples of the file? I think I should put the code as follows:
while(i<=tot_samples-15)
so that i do not miss the last 15 samples.
Lastly, when i use:
sound(y);
i hear nothing. I assumed that it was because the y that i used was the last 15 samples of the audio file. How do i make it such that after every multiplication, the out is added to the previous output?
Thomas
Thomas 2012년 9월 24일
편집: Thomas 2012년 9월 24일
your last iteration will go from
i=tot_samples-15
to
i+15
which is
tot_samples-15 +15
(i.e. the end)
You donot hear anything because 15 samples is too small to hear
try
siz=wavread('hello.wav','size');
tot_samples = siz(1); % 74539 samples
i=1;
for i=1:1000:tot_samples-1000
i
x = wavread('hello.wav', [i i+1000]); % read 1000 samples
sound(x);
end
Rick
Rick 2012년 9월 24일
while(i<tot_samples-15) & while(i<=tot_samples-15) will not have a difference do they? Because, i increment in steps of 16.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

질문:

2012년 9월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by