We have a requirement to manipulate audio, specifically WAV files in
Matlab.
The idea is to allow the user to select all or part of a file and
only play that particular section of the file. Being a complete
newbie to matlab, I have absolutely no idea on how to go about this
and would appreciate any assistance, URL links or code examples that
would help with this.
I'm currently at the stage where I can read in and write new files
with the wavread/wavwrite commands.
Cheers
B.Smith
You can join wav files together using square brackets.
try the following code: (file 1 and file 2 should be the same sample
rate and bit depth)
[y1,fs,bits] = wavread('file1.wav');
[y2] = wavread('file2.wav');
y3 = [y1; y2];
% To Listen:
sound(y3,fs);
% To Write to WAV:
wavwrite(y3,fs,bits,'file3.wav');
Thanks for the info. I guess my major problem is that I need to able
to 'insert' one wav file inside of the other one - it isn't simply a
case of joining them together. For example, if I'm using the standard
windows soundset - tada.wav and chord.wav, I would need to be able to
play the 'ta <insert chordhere> da'
Again, any help appreciated and thanks for your input so far.
Ok, no problem - you can read specific sections of a wave file into
matlab using:
wavread('filename',[1 5000]);
where the values in the square brackets indicate the start and end
samples you want to extract.
Alternatively if you read the entire wav file into matlab you can do
the same thing:
[y1,fs,bits] = wavread('file1.wav');
[y2,fs,bits] = wavread('file2.wav');
% Extract first 500 samples from y1,
% Then attach y2,
% Then extract the remaining samples
% ans stick them on the end.
y3 = [y1(1:500,:); y2; y1(501:end)];
wavwrite(y,fs,bits,'file3.wav');
Nice one Rich.