필터 지우기
필터 지우기

How can i read wave files to a column vector?

조회 수: 3 (최근 30일)
Áron Laczkovits
Áron Laczkovits 2013년 7월 8일
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

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by