-
Notifications
You must be signed in to change notification settings - Fork 0
/
RealTimeAudio_audioPlayRecord.m
58 lines (50 loc) · 1.66 KB
/
RealTimeAudio_audioPlayRecord.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
close all; clear all; clc;
addpath('./audio');
frameSize = 512;
%frameSize = 2048;
bufferSize = frameSize;
fileReader = dsp.AudioFileReader('guitar.wav', ...
'SamplesPerFrame',frameSize);
% fs = fileReader.SampleRate;
[dvn,fs] = audioread("dvn_01_decay.wav");
fileWriter = dsp.AudioFileWriter('guitar-PlaybackRecorded.wav', ...
'SampleRate',fs);
%aPR = audioPlayerRecorder('SampleRate',fs);
aPR = audioPlayerRecorder('SampleRate',fs,'SupportVariableSize',true,'BufferSize',bufferSize);
% if windows computer, open asio settings
asiosettings(aPR.Device);
reverb = reverberator( ... %<--- new lines of code
'SampleRate',fileReader.SampleRate, ... %<---
'PreDelay',0.5, ... %<---
'WetDryMix',0.4);
% %%
% frameSize = 512;
% addpath('./audio');
% [dvn,fs] = audioread("dvn_01_decay.wav");
lastAudioRecorded = rand([frameSize, 1])*0.2;
lastAudioRecorded = zeros(frameSize, 1);
% IR = dvn;
% convolver = BlockConvolver_DSP(frameSize,1,length(IR));
% convolver.setIRs(IR);
%%
tic
while toc < 15
% while ~isDone(fileReader)
disp(size(lastAudioRecorded));
audioToPlay = reverb(lastAudioRecorded);
% reverberated = convolver.process(lastAudioRecorded(:,1));
% audioToPlay = [reverberated reverberated];
[audioRecorded,nUnderruns,nOverruns] = aPR(audioToPlay);
lastAudioRecorded = audioRecorded;
fileWriter(audioRecorded)
if nUnderruns > 0
fprintf('Audio player queue was underrun by %d samples.\n',nUnderruns);
end
if nOverruns > 0
fprintf('Audio recorder queue was overrun by %d samples.\n',nOverruns);
end
end
release(reverb)
release(fileReader)
release(fileWriter)
release(aPR)