get_audio_loop.m 839 Bytes
Newer Older
Martin Karlsson's avatar
hej    
Martin Karlsson committed
1
2
3
4
5
addpath(genpath('~/openrobots/lib/matlab/'));
client = genomix.client('turtlebot1-wifi:8080');
bass = client.load('bass');


Martin Karlsson's avatar
update    
Martin Karlsson committed
6
figure;
Martin Karlsson's avatar
Martin Karlsson committed
7

Martin Karlsson's avatar
update    
Martin Karlsson committed
8
9
allAudioLeft = [];
allAudioRight = [];
Martin Karlsson's avatar
Martin Karlsson committed
10
11
12
lastLastIndex = 0;
lastIndex = 0;
count = 0;
Martin Karlsson's avatar
update    
Martin Karlsson committed
13
while count < 50
Martin Karlsson's avatar
Martin Karlsson committed
14
15
16
17
    p = bass.Audio();
    if count == 0
        fs = p.Audio.sampleRate;
    end
Martin Karlsson's avatar
update    
Martin Karlsson committed
18
    pause(0.1)
Martin Karlsson's avatar
Martin Karlsson committed
19
20
    lastIndex = p.Audio.lastFrameIndex;
    diffIndex = lastIndex - lastLastIndex;
Martin Karlsson's avatar
update    
Martin Karlsson committed
21
22
23
24
25
26
27
    tempLeft = cell2mat(p.Audio.left);
    tempLeft = tempLeft(max(end-diffIndex+1,1):end);
    allAudioLeft = [allAudioLeft; tempLeft];
    
    tempRight = cell2mat(p.Audio.right);
    tempRight = tempRight(max(end-diffIndex+1,1):end);
    allAudioRight = [allAudioRight; tempRight];
Martin Karlsson's avatar
Martin Karlsson committed
28
29
30
    
    lastLastIndex = lastIndex;
    count = count+1
Martin Karlsson's avatar
update    
Martin Karlsson committed
31
32
33
34
35
36
    
    plot(tempLeft);
    set(gca,'ylim',[-2^16/2 2^16/2])
    drawnow
    
end