필터 지우기
필터 지우기

Invalid Audio File, too many samples

조회 수: 3 (최근 30일)
Rick
Rick 2012년 9월 24일
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일
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
Wayne King
Wayne King 2012년 9월 24일
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일
You cannot have the first sample being 0, MATLAB indexes from 1.
  댓글 수: 4
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일
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
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.

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

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by