Real-time read and buffer serial data while playing previous buffer using dsp.audioplayer /soundsc

2 vues (au cours des 30 derniers jours)
I am working on a real-time EEG Audification project.
I have all the reading/parsing/plotting, etc. completed. My task now is to audify the signal. For this I am using the phase vocoder from the link below. http://www.ee.columbia.edu/ln/rosa/matlab/pvoc/
It works as desired when I read in a buffer then playback the buffer. The phase vocoder is set up so that the audio is the same length of time as the serial data (i.e. 10 seconds of serial data = 10 seconds of audio). My code runs until the user presses any key on the pop-up figure.
Here is a pseudo-code version:
Fs = 256;
FsAudio = 8000;
while ~keyPress
% Fill Buffer
for j=0:(numberOfBlocksInBuffer-1)
rawData((0:(samples - 1)) + j*samples + 1) = fread(comEEGSMT, samples, 'uchar');
end
% Parse data and Filter data
...... .... ... 17 Byte packet, eeg data stored in byte 4 and 5.
outputChannel = FilterOutput; % which results in an array of size (length(buffer)/17, 1)
channel2Audio = pvoc(parameters);
channel2AudioNormalised = -1 + 2.*(channel2Audio - min(channel2Audio))./(max(channel2Audio) - min(channel2Audio));
% audiowrite('eegAudio2.wav',channel2AudioNormalised,FsAudio)
% step(audioPlayer,channel2AudioNormalised);
soundsc(channel2AudioNormalised,FsAudio);
StripChart('Update',Plot1,outputChannel2) % Update Stripchart
end
This results in matlab reading from the serial port, matlab playing the audio, matlab reading, matlab playing, reading, playing,etc.
However, I need the program to read the next buffer while playing the previous buffer (both operations take the same amount of time as set by my pvoc parameters).
Am I right in thinking the only option is to use multithreading? I need to read in a buffer pass this to the audio player and while the audio player is playing that buffer, I need to read in my next buffer simultaneously? In order to perform multithreading in Matlab I need to create a Mex file from my understanding and use the parfor (parallel for loop) function? I don't have the Parallel Computing Toolbox in case someone suggests that.
Is there any alternative to trying to multithread as I would prefer not to go into such depth.
Any help/suggestions is hugely appreciated.
Mark

Réponses (0)

Catégories

En savoir plus sur EEG/MEG/ECoG dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by