Invalid Audio File, too many samples
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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
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);
更多回答(2 个)
Wayne King
2012-9-24
You cannot have the first sample being 0, MATLAB indexes from 1.
4 个评论
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?
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
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Code Generation and Deployment 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!