/
realtime_testing.m
53 lines (46 loc) · 1.86 KB
/
realtime_testing.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
%% Real-Time Audio Stream Processing
%
% The Audio System Toolbox provides real-time, low-latency processing of
% audio signals using the System objects audioDeviceReader and
% audioDeviceWriter.
%
% This example shows how to use our vocal harmonizer functions in real time
% to output harmonies
%constants, the larger the window size, the more the delay
WINDOW_SIZE = 6000;
SAMPLE_RATE = 44100;
%% Create input and output objects
deviceReader = audioDeviceReader;
deviceReader.SampleRate = SAMPLE_RATE;
deviceReader.SamplesPerFrame = WINDOW_SIZE;
deviceWriter = audioDeviceWriter('SampleRate',deviceReader.SampleRate);
disp('Begin Signal Input...')
%simple counter to hold state if we have had previous state or not
counter = 0;
%initialize variables to hold current and previous signal. We need the
%previous signal to do the overlapping windows!
mySignal = zeros(WINDOW_SIZE, 1);
myProcessedSignal = zeros(WINDOW_SIZE + WINDOW_SIZE/2, 1);
prevSignal = zeros(WINDOW_SIZE, 1);
prevProcessedSignal = zeros(WINDOW_SIZE + WINDOW_SIZE/2, 1);
tic
while toc<100
if counter > 1
%populate mySignal with the new buffer
mySignal = deviceReader();
%call the realtime_prototype function that takes in the signals and
%outputs the peakshifts
myProcessedSignal = realtime_prototype([prevSignal(length(prevSignal)/2 + 1:end); mySignal], WINDOW_SIZE, SAMPLE_RATE);
%take the appropriate output from the end of the previous Signal
%and the first part of the new signal, and write to the output
%buffer
metaOutput = ([prevProcessedSignal(WINDOW_SIZE+1:end); zeros(WINDOW_SIZE, 1)] + myProcessedSignal) * 0.5;
deviceWriter(metaOutput(1:WINDOW_SIZE));
end
prevSignal = mySignal;
prevProcessedSignal = myProcessedSignal;
counter = counter + 1;
end
disp('End Signal Input')
release(deviceReader)
release(deviceWriter)