-
Notifications
You must be signed in to change notification settings - Fork 1
/
Scope.py
205 lines (143 loc) · 6.22 KB
/
Scope.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env python
from __future__ import division
"""
Scope to visualize signal and test AMVU application
Copyright (C) 2015
Arthur Fages - Loic Fagot - Vincent Labourdette - Thomas Lamant - Guillaume Loizeau
Arts et Metiers ParisTech, centre de Bordeaux-Talence
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# Version 1.0
# Last update : 06/05/2015
import pyqtgraph as pg
import sys
from PyQt4 import Qt
from PyQt4 import QtCore
from PyQt4 import Qwt5 as Qwt
from Signal import Signal
from SignalFrame import SignalFrame
class Scope(Qt.QMainWindow):
def __init__(self, signalFrame, rate, size, *args):
Qt.QMainWindow.__init__(self)
self.signalFrame = signalFrame
def displaySignal(self):
#print "[Oh yeah, I display]"
# get the data to display
dataToDisplay = self.signalFrame.signalList[SCOPE.signalFrame.currentSignal].getLastSignalRecordedPart()
rate = self.signalFrame.signalList[SCOPE.signalFrame.currentSignal].rate
#print dataToDisplay
# display it
self.signalFrame.timeScope.update(dataToDisplay, rate)
# signal to display
#self.a1 = T[0]
#self.a2 = T[1]
# display
#l=len(self.a1)
#self.curve1.setData([0.0,0.0], [0.0,0.0])
#self.curve2.setData(self.ti[0:l], self.a2[:l])
#self.replot()
def updateDisplay():
#print "[Oh yeah, I update]"
# test if there is a new portion of signal
# to display
if (SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].newAudio and not(SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].threadsDieNow)) :
# get signal and display it
#T = SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].getLastSignalRecordedPart()
#print "[Display signal]"
SCOPE.displaySignal()
# this portion of signal have been displayed
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].newAudio = False
def seeRecord():
# stop current signal acquisition
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].threadsDieNow = True
# display recorded signal
signalToDisplay = SIGNAL.getWellFormattedTimeSignal()[0]
print "[Display recorded signal]"
pg.plot(signalToDisplay)
def launchTrigger():
# set the default value for the trigger
triggerStep = 12222
# launch the trigger
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].startTrigger(triggerStep, 4)
def exportFile():
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].exportWavFormat()
def startRecord():
# restart current signal acquisition
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].threadsDieNow = False
# restart signal recording
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].startRecording() # signal SR = current sound card record
# at any time
#SR.startTrigger()
# display continuous signal
timer = QtCore.QTimer()
timer.start(1.0)
SCOPE.connect(timer, QtCore.SIGNAL('timeout()'), updateDisplay)
if __name__ == "__main__" :
""" Test of Signal class """
# signal properties
rate = 8192 #44100
size = 2048 #4096
# create a scope window
app = Qt.QApplication(sys.argv)
# create a new signal ready to be displayed in the scope
SIGNAL = Signal(rate, size)
signalFrame = SignalFrame()
#signalFrame.consider(SIGNAL)
# create the scope
SCOPE = Scope(signalFrame, rate, size)
# affect a first signal to this scope
SCOPE.signalFrame.consider(SIGNAL)
SCOPE.signalFrame.displayLastSignal() # initialize 2 plot for freq and time
print "----------------------------------"
print SCOPE.signalFrame.timeScope
print SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal]
startRecord()
#SCOPE.signalFrame.timeScope # qwtplot
#SCOPE.signalFrame.freqScope # qwtplot
#SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal]
# create a button to continue recording the signal
button2 = Qt.QPushButton("Continue record")
button2.clicked.connect(startRecord)
button2.show()
# create a button to start with a trigger
button1 = Qt.QPushButton("Start trigger")
button1.clicked.connect(launchTrigger)
button1.show()
# create a button to display recorded signal
button = Qt.QPushButton("See recorded signal")
button.clicked.connect(seeRecord)
button.show()
# create a button to export signal in wave file
button3 = Qt.QPushButton("Export .wav")
button3.clicked.connect(exportFile)
button3.show()
# display this buttons on a toolbar
toolBar = Qt.QToolBar()
toolBar.addWidget(button)
toolBar.addWidget(button1)
toolBar.addWidget(button2)
toolBar.addWidget(button3)
SCOPE.addToolBar(toolBar)
# display continuous signal
timer = QtCore.QTimer()
timer.start(1.0)
SCOPE.connect(timer, QtCore.SIGNAL('timeout()'), updateDisplay)
#show all the graphical stuff
#SCOPE.setCentralWidget(SCOPE.signalFrame.timeScope)
SCOPE.setCentralWidget(signalFrame.timeScope)
#signalFrame.show()
SCOPE.show()
SCOPE.signalFrame.timeScope.show()
app.exec_()
# close the signal
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].threadsDieNow = True
SCOPE.signalFrame.signalList[SCOPE.signalFrame.currentSignal].stopSignalStream()