How to generate and play audio in real time with dsp toolbox

9 ビュー (過去 30 日間)
Luke Plausin
Luke Plausin 2013 年 3 月 11 日
Hi everybody,
I am writing an application which must simultaneously analyse video frames and generate & play an audio stream. I am trying to use a dsp.AudioPlayer object to do this but I'm having lag issues. Without code writing to the dsp.AudioPlayer object I'm achieving 30-40 fps, with audio output I get less than 1. After profiling I can see most of the time is going into a for loop which pushes samples from a buffer to the audio object with the step function.
obj.hap = dsp.AudioPlayer;
sc_samples = 0:(1/obj.sc_sample_rate):path.tof; % Time samples
sc_voltage = interp1(path.pixelt, real(path.direct), sc_samples, 'linear');
% Sound wave stored in sc_voltage, with time base sc_samples
% sample rate is 8000hz
tic
for samp = 1:length(sc_samples)
step(obj.hap, sc_voltage(samp));
end
time = toc
Is there any way to copy the whole buffer at once? Would this boost performance? I am aware of sound outputs in the data acquisition toolbox but this isn't compatible with 64 bit versions of Matlab.
Thanks for your help

回答 (2 件)

yeshwanth manhcuri
yeshwanth manhcuri 2013 年 5 月 21 日
try with wavread and wavwrite functions....audio player will show some time lag/..............

Luke Plausin
Luke Plausin 2013 年 5 月 21 日
Audio had to be computed on the fly so precomputing to wav files was not an option. In the end I rewrote my code in C++ with port audio. Thanks for looking anyway

カテゴリ

Help Center および File ExchangeCode Generation and Deployment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by