get_audio.m 588 Bytes
Newer Older
Martin Karlsson's avatar
hej  
Martin Karlsson committed
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
function signal = get_audio()

global bass;


persistent lastLastIndex;
persistent lastIndex;
persistent fs;
persistent p;


if isempty(fs)
    p = bass.Audio();
    fs = p.Audio.sampleRate;
    lastLastIndex = 0;
    lastIndex = 0;
    
end
p = bass.Audio();



pause(0.1)
lastIndex = p.Audio.lastFrameIndex;
diffIndex = lastIndex - lastLastIndex;
tempLeft = cell2mat(p.Audio.left);
tempLeft = tempLeft(max(end-diffIndex+1,1):end);

tempRight = cell2mat(p.Audio.right);
tempRight = tempRight(max(end-diffIndex+1,1):end);


lastLastIndex = lastIndex;

signal = [tempLeft; tempRight];

end