Filter löschen
Filter löschen

How can i read wave files to a column vector?

3 Ansichten (letzte 30 Tage)
Áron Laczkovits
Áron Laczkovits am 8 Jul. 2013
Hi All!
I would like to read many wave files to a column vector, where i can reach each of them anytime. Pls help me to do this.
Here is my source code:
clear; clc;
myFolder = 'C:\Users\Aron\Samples\proba';
if exist(myFolder, 'dir') ~= 7
Message = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(Message));
return;
end
filePattern = fullfile(myFolder, '*.wav');
wavFiles = dir(filePattern);
for k = 1:length(wavFiles)
baseFileName = wavFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
[sampleArray, Fs] = wavread(fullFileName);
end
%sound(sampleArray, Fs);
In this case i can only reach the last sample, because of the loop. How can i play the chosen sample???If for example there are 80 samples that folder and i just want to play the 50th sample.
Thx in advance

Akzeptierte Antwort

Ken Atwell
Ken Atwell am 8 Jul. 2013
Rather than having sampleArray hold only the most recently read WAV file, make sampleArray a cell array of all of them. You would also need make Fs a vector of all sample rates. Your code would look something like this (written from memory, untested):
sampleArray = cell(length(wavFiles),1);
Fs = zeros(size(sampleArray));
for k = 1:length(wavFiles)
baseFileName = wavFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
[sampleArray{k}, Fs(k)] = wavread(fullFileName);
end
To play the 50th sample:
sound(sampleArray{50}, Fs(50));
Keep your eye on your application's memory usage. If you have lots of long WAV files in memory, your application will potentially use a lot of memory.
  1 Kommentar
Áron Laczkovits
Áron Laczkovits am 9 Jul. 2013
Thank you Ken, Its working, if i will have more question, can i ask u? The aim is to program the simplest sampler.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by