Azzera filtri
Azzera filtri

How can i read wave files to a column vector?

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Ken Atwell
Ken Atwell il 8 Lug 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 Commento
Áron Laczkovits
Áron Laczkovits il 9 Lug 2013
Thank you Ken, Its working, if i will have more question, can i ask u? The aim is to program the simplest sampler.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by