1- import pathlib
21import numpy as np
32import math
4- import audiofile as af
53
64from . import ayfaudioif as ayfif
7- from . import ayfaudioio as ayfio
85from . import ayfaudiobuf as ayfbuf
96
7+
108# ========================================================================
119class 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