Filter löschen
Filter löschen

Invalid Audio File, too many samples

2 Ansichten (letzte 30 Tage)
Rick
Rick am 24 Sep. 2012
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?

Akzeptierte Antwort

Wayne King
Wayne King am 24 Sep. 2012
Bearbeitet: Wayne King am 24 Sep. 2012
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 Kommentare
Wayne King
Wayne King am 24 Sep. 2012
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 am 24 Sep. 2012
I see, thanks for the enlightenment. :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Wayne King
Wayne King am 24 Sep. 2012
You cannot have the first sample being 0, MATLAB indexes from 1.
  4 Kommentare
Wayne King
Wayne King am 24 Sep. 2012
Bearbeitet: Wayne King am 24 Sep. 2012
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 am 24 Sep. 2012
I see.
Because I was given a project to use the given frame of 16 samples/frame.

Melden Sie sich an, um zu kommentieren.


Thomas
Thomas am 24 Sep. 2012
Bearbeitet: Thomas am 24 Sep. 2012
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 Kommentare
Thomas
Thomas am 24 Sep. 2012
Bearbeitet: Thomas am 24 Sep. 2012
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 am 24 Sep. 2012
while(i<tot_samples-15) & while(i<=tot_samples-15) will not have a difference do they? Because, i increment in steps of 16.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by