Skip to content

Commit 9d025ae

Browse files
committed
ruff
1 parent 60c9da8 commit 9d025ae

14 files changed

Lines changed: 236 additions & 265 deletions

File tree

python/art-tracker-mock/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from scapy.all import rdpcap, IP, UDP
99

10+
1011
@dataclass
1112
class Packet:
1213
payload: bytes
@@ -34,7 +35,7 @@ def _read_packets(pcap_file: Path, pcap_ip: ip_address, pcap_ports: list[int]) -
3435
if last_time is not None:
3536
delay = float(pkt.time) - last_time
3637
else:
37-
delay = 0.
38+
delay = 0.0
3839
res.append(Packet(payload, udp_layer.dport, delay))
3940
last_time = float(pkt.time)
4041
return res

python/ayf/audioio/ayfaudiobuf.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
21
import numpy as np
32
from enum import Enum
43

54
# ======================================================================
65
# ======================================================================
76

7+
88
class ProcessingType(Enum):
99
UNDEFINED = 0
10-
I_SINGLEBUF = 1 # interleaved, singlebuffer [0 0 0 1 1 1]
11-
NOI_SINGLEBUF = 2 # non-interleaved, singlebuffer [0 0 0 1 1 1]
12-
NOI_BUFARR = 3 # non-interleaved, buffer array [[0 0 0][1 1 1]]
10+
I_SINGLEBUF = 1 # interleaved, singlebuffer [0 0 0 1 1 1]
11+
NOI_SINGLEBUF = 2 # non-interleaved, singlebuffer [0 0 0 1 1 1]
12+
NOI_BUFARR = 3 # non-interleaved, buffer array [[0 0 0][1 1 1]]
13+
1314

1415
# ======================================================================
1516
# ======================================================================
16-
17-
class ayfaudio_buf_param:
1817

18+
19+
class ayfaudio_buf_param:
1920
def __init__(self):
2021
self.tp = ProcessingType.UNDEFINED
2122
self.chans = 0
2223
self.bs = 0
2324
self.sr = 0
2425

25-
def params_set(self, operation = ProcessingType.I_SINGLEBUF, chans = 1, bs = 1024, sr = 48000, arith = 'double'):
26-
26+
def params_set(self, operation=ProcessingType.I_SINGLEBUF, chans=1, bs=1024, sr=48000, arith="double"):
27+
2728
self.tp = operation
2829
self.chans = chans
2930
self.bs = bs
3031
self.sr = sr
3132
self.arith = arith
3233

33-
class ayfaudio_buf:
3434

35+
class ayfaudio_buf:
3536
def __init__(self):
36-
37+
3738
self.params = ayfaudio_buf_param()
3839

3940
self.c = 0
@@ -43,8 +44,8 @@ def __init__(self):
4344

4445
def allocate(self, operation, nChans, fsize, srate, arith):
4546

46-
self.params.params_set(chans = nChans, operation = operation, bs = fsize, sr = srate, arith = arith)
47-
47+
self.params.params_set(chans=nChans, operation=operation, bs=fsize, sr=srate, arith=arith)
48+
4849
match self.params.tp:
4950
case ProcessingType.I_SINGLEBUF:
5051
self.c = 1
@@ -65,8 +66,7 @@ def allocate(self, operation, nChans, fsize, srate, arith):
6566
self.fld = np.zeros(self.l, dtype=arith)
6667

6768
case _:
68-
assert(False)
69-
69+
assert False
7070

7171
def deallocate(self):
7272
self.params.tp = ProcessingType.UNDEFINED
@@ -78,23 +78,26 @@ def deallocate(self):
7878
self.fld = None
7979
self.fIdx = 0
8080

81+
8182
# ======================================================================
8283
# ======================================================================
8384

85+
8486
class ayfaudio_data:
85-
def __init__(self, srate = 48000, nChans = 2):
87+
def __init__(self, srate=48000, nChans=2):
8688
self.sampling_rate = srate
8789
self.nChans = nChans
88-
90+
91+
8992
# ======================================================================
9093
# ======================================================================
9194

92-
class ayfaudio_outbuf:
9395

94-
def __init__(self, maxLength = 48000, nChans = 2, fsize = 128):
96+
class ayfaudio_outbuf:
97+
def __init__(self, maxLength=48000, nChans=2, fsize=128):
9598
self.buf = None
9699
self.data = ayfaudio_data()
97-
self.duration_samples = 0
100+
self.duration_samples = 0
98101
self.maxLength = maxLength
99102
self.fsize = fsize
100103
self.nChans = nChans
@@ -103,40 +106,40 @@ def __init__(self, maxLength = 48000, nChans = 2, fsize = 128):
103106
def postprocess_oneBuf_noi_singlebuf(self, outBufHdl):
104107
cpToStart = 0
105108
idxStart = outBufHdl.fIdx * outBufHdl.bs
106-
idxStop = (outBufHdl.fIdx+1) * outBufHdl.bs
109+
idxStop = (outBufHdl.fIdx + 1) * outBufHdl.bs
107110
idxStart = min(idxStart, self.duration_samples)
108111
idxStop = min(idxStop, self.duration_samples)
109112
cpNum = idxStop - idxStart
110-
if(cpNum > 0):
113+
if cpNum > 0:
111114
for idxChan in range(0, self.nChans):
112-
self.buf[idxChan][idxStart:idxStart + cpNum] = outBufHdl.fld[cpToStart:cpToStart + cpNum]
115+
self.buf[idxChan][idxStart : idxStart + cpNum] = outBufHdl.fld[cpToStart : cpToStart + cpNum]
113116
cpToStart += outBufHdl.bs
114-
117+
115118
def postprocess_oneBuf_noi_bufarr(self, outBufHdl, idxFrame):
116-
assert(0)
119+
assert 0
117120

118121
def postprocess_single_frame(self, outBufHdl, idxFrame):
119122
match outBufHdl.tp:
120123
case ProcessingType.UNDEFINED:
121-
print('Error')
122-
assert(0)
124+
print("Error")
125+
assert 0
123126

124127
case ProcessingType.NOI_SINGLEBUF:
125128
self.postprocess_oneBuf_noi_singlebuf(outBufHdl)
126129

127130
case ProcessingType.NOI_BUFARR:
128131
self.postprocess_oneBuf_noi_bufarr(outBufHdl, idxFrame)
129-
132+
130133
self.fIdx = outBufHdl.fIdx
131134

132135
def param_get(self):
133136
return self.data
134137

135-
def start(self, arith, nFrames = -1):
136-
137-
if(nFrames > 0):
138+
def start(self, arith, nFrames=-1):
139+
140+
if nFrames > 0:
138141
self.duration_samples = nFrames * self.fsize
139142
else:
140143
self.duration_samples = self.maxLength * self.fsize
141144

142-
self.buf = np.empty((self.nChans, int(self.duration_samples)),dtype=arith)
145+
self.buf = np.empty((self.nChans, int(self.duration_samples)), dtype=arith)

python/ayf/audioio/ayfaudioif.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import numpy as np
21
from . import ayfaudiobuf as ayfbuf
32

3+
44
class ayfaudio_in:
55
# @abstractmethod
66
def prepare_data(self, formatSystem) -> None: ...
@@ -26,15 +26,17 @@ def progress(self, inBufHdl) -> float: ...
2626
# =============================================================================
2727
# =============================================================================
2828

29+
2930
class ayfaudio_processor:
3031
# @abstractmethod
31-
def prepare(self, numIn = 1, numOut = 1, bSize = 128, sRate = 48000) -> int: ...
32+
def prepare(self, numIn=1, numOut=1, bSize=128, sRate=48000) -> int: ...
3233

3334
# @abstractmethod
3435
def process(self, inBuf, outBuf) -> int: ...
3536

3637
# @abstractmethod
3738
def postprocess(self) -> int: ...
3839

40+
3941
# ======================================================================
4042
# ======================================================================
Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
import pathlib
21
import numpy as np
32
import math
4-
import audiofile as af
53

64
from . import ayfaudioif as ayfif
7-
from . import ayfaudioio as ayfio
85
from . import ayfaudiobuf as ayfbuf
96

7+
108
# ========================================================================
119
class ayfaudio_inbuffered(ayfif.ayfaudio_in):
12-
1310
def prepare_data(self, formatSystem):
14-
15-
if(formatSystem == "single"):
16-
if(self.buf.dtype == "float64"):
11+
12+
if formatSystem == "single":
13+
if self.buf.dtype == "float64":
1714
self.buf = np.float32(self.buf)
18-
elif(formatSystem == "double"):
19-
if(self.buf.dtype == "float32"):
15+
elif formatSystem == "double":
16+
if self.buf.dtype == "float32":
2017
self.buf = np.float64(self.buf)
2118
else:
22-
assert(False)
19+
assert False
2320

2421
self.fIdx = 0
2522

@@ -31,117 +28,117 @@ def clear_data(self):
3128

3229
def param_get(self):
3330
return self.data
34-
31+
3532
def prepare_oneBuf_noi_singlebuf(self, inBufHdl):
3633
inBufHdl.fld.fill(0)
3734
cpToStart = 0
38-
if(inBufHdl.fIdx * inBufHdl.bs >= self.duration_samples):
35+
if inBufHdl.fIdx * inBufHdl.bs >= self.duration_samples:
3936
return False
4037

4138
idxStart = inBufHdl.fIdx * inBufHdl.bs
42-
idxStop = (inBufHdl.fIdx+1) * inBufHdl.bs
43-
idxStop = min(idxStop, self.duration_samples)
39+
idxStop = (inBufHdl.fIdx + 1) * inBufHdl.bs
40+
idxStop = min(idxStop, self.duration_samples)
4441
cpNum = idxStop - idxStart
4542
chansLim = min(self.data.nChans, inBufHdl.chans)
4643
for idxChan in range(0, chansLim):
47-
inBufHdl.fld[cpToStart:cpToStart + cpNum] = self.buf[idxChan][idxStart:idxStart + cpNum]
48-
cpToStart += inBufHdl.bs
44+
inBufHdl.fld[cpToStart : cpToStart + cpNum] = self.buf[idxChan][idxStart : idxStart + cpNum]
45+
cpToStart += inBufHdl.bs
4946
return True
5047

51-
5248
def prepare_oneBuf_noi_bufarr(self, inBufHdl, frameIdx):
53-
assert(0)
49+
assert 0
5450

5551
def prepare_oneBuf_i_singlebuf(self, inBufHdl: ayfbuf.ayfaudio_buf):
56-
52+
5753
inBufHdl.fld.fill(0)
5854
nSamples = inBufHdl.params.bs * inBufHdl.params.chans
59-
55+
6056
# Only full frames. We need samples from frame 0 to frame 1 - therefore "+1"
61-
if((self.fIdx + 1) * nSamples >= self.duration_samples):
57+
if (self.fIdx + 1) * nSamples >= self.duration_samples:
6258
return False
63-
59+
6460
# Extract buffer here!
6561
idxStart = self.fIdx * nSamples
66-
idxStop = (self.fIdx+1) * nSamples
67-
idxStop = min(idxStop, (self.duration_samples * inBufHdl.params.chans))
62+
idxStop = (self.fIdx + 1) * nSamples
63+
idxStop = min(idxStop, (self.duration_samples * inBufHdl.params.chans))
6864
nSamples = idxStop - idxStart
69-
65+
7066
# Might be a 1D-array or a 2D-array
71-
firstBuf = self.buf
72-
if(len(self.buf) == 2):
67+
firstBuf = self.buf
68+
if len(self.buf) == 2:
7369
firstBuf = self.buf[0]
7470

7571
# Copy content and the frame
76-
inBufHdl.fld[0:nSamples] = firstBuf[idxStart:idxStop]
72+
inBufHdl.fld[0:nSamples] = firstBuf[idxStart:idxStop]
7773
inBufHdl.fIdx = self.fIdx
7874
return True
79-
75+
8076
def prepare_single_frame(self, inBufHdl, frameIdx):
8177
match inBufHdl.tp:
8278
case ayfbuf.ProcessingType.NOI_SINGLEBUF:
83-
retVal = self.prepare_oneBuf_noi_singlebuf(inBufHdl) # No frameindex required as it handles that internally
79+
retVal = self.prepare_oneBuf_noi_singlebuf(inBufHdl) # No frameindex required as it handles that internally
8480

8581
case ayfbuf.ProcessingType.NOI_BUFARR:
8682
retVal = self.prepare_oneBuf_noi_bufarr(inBufHdl, frameIdx)
8783

8884
case ayfbuf.ProcessingType.I_SINGLEBUF:
89-
retVal = self.prepare_oneBuf_i_singlebuf(inBufHdl) # No frameindex required as it handles that internally
85+
retVal = self.prepare_oneBuf_i_singlebuf(inBufHdl) # No frameindex required as it handles that internally
9086
case _:
91-
print('Error')
92-
assert(0)
87+
print("Error")
88+
assert 0
9389

94-
if(retVal == True):
90+
if retVal:
9591
inBufHdl.fIdx = self.fIdx
96-
self.fIdx = self.fIdx + 1
92+
self.fIdx = self.fIdx + 1
9793
return retVal
9894

9995
def start(self, inBufHdl):
100-
return math.ceil( self.duration_samples/inBufHdl.params.bs)
96+
return math.ceil(self.duration_samples / inBufHdl.params.bs)
10197

102-
def stop(self) -> int: ...
103-
# Do nothing
98+
def stop(self) -> int:
99+
...
100+
# Do nothing
104101

105102
def progress(self, inBufHdl: ayfbuf.ayfaudio_buf):
106-
return (self.fIdx* inBufHdl.params.bs)/ self.duration_samples
107-
103+
return (self.fIdx * inBufHdl.params.bs) / self.duration_samples
104+
105+
108106
# ===========================================================================
109107
# ===========================================================================
110108

111-
class ayfaudio_inpulse(ayfaudio_inbuffered):
112109

113-
def __init__(self, duration_secs = 10, samplerate = 48000, nChans = 1, format = 'double'):
110+
class ayfaudio_inpulse(ayfaudio_inbuffered):
111+
def __init__(self, duration_secs=10, samplerate=48000, nChans=1, format="double"):
114112

115113
self.data = ayfbuf.ayfaudio_data()
116114
self.data.sampling_rate = samplerate
117-
self.duration_samples = duration_secs * self.data.sampling_rate
115+
self.duration_samples = duration_secs * self.data.sampling_rate
118116
self.fIdx = 0
119117
self.buf = None
120118

121119
print("### AYFAUDIOINPULSE -- Creating pulse input.")
122120

123-
if(format == "single"):
124-
self.buf = np.zeros(nChans * self.duration_samples, dtype="float32")
121+
if format == "single":
122+
self.buf = np.zeros(nChans * self.duration_samples, dtype="float32")
125123

126-
elif(format == "double"):
127-
128-
# self.buf = np.float64(self.buf)
124+
elif format == "double":
125+
# self.buf = np.float64(self.buf)
129126
self.buf = np.zeros(nChans * self.duration_samples, dtype="float64")
130127
else:
131-
assert(False)
128+
assert False
132129

133130
# Fill very first sample to realize the pulse
134131
for idxChan in range(0, nChans):
135132
self.buf[idxChan] = 1.0
136-
137-
szArr = self.buf.shape
138-
if(len(szArr) == 2):
139133

134+
szArr = self.buf.shape
135+
if len(szArr) == 2:
140136
self.duration_samples = szArr[1]
141137
self.data.nChans = szArr[0]
142138
else:
143139
self.duration_samples = szArr[0]
144140
self.data.nChans = 1
145141

142+
146143
# ==========================================================================
147144
# ==========================================================================

0 commit comments

Comments
 (0)