Browse Source

p_ac.py, p_ac.yml : Changes to support Steinway D calibration.

master
kevin 3 years ago
parent
commit
648e29c4c4
2 changed files with 69 additions and 47 deletions
  1. 41
    19
      p_ac.py
  2. 28
    28
      p_ac.yml

+ 41
- 19
p_ac.py View File

@@ -58,10 +58,12 @@ class AttackPulseSeq:
58 58
         self.eventTimeL = [[0,0]  for _ in range(len(pulseUsL))] # initialize the event time         
59 59
         self.beginMs    = ms
60 60
         self.playOnlyFl = playOnlyFl
61
-
62
-
61
+                    
63 62
         # kpl if not playOnlyFl:
64 63
         self.audio.record_enable(True)   # start recording audio
64
+
65
+        print("Hold Delay from end of attack:",cfg.defaultHoldDelayUsecs)                    
66
+        self.api.set_hold_delay(pitch,cfg.defaultHoldDelayUsecs)
65 67
         
66 68
         self.tick(ms)                    # play the first note
67 69
         
@@ -123,17 +125,10 @@ class AttackPulseSeq:
123 125
         
124 126
     def _get_duty_cycle( self, pulseUsec ):
125 127
         return self.holdDutyPctD[ pulseUsec ]
126
-    
127
-        dutyPct = self.holdDutyPctL[0][1]
128
-        for refUsec,refDuty in self.holdDutyPctL:
129
-            if pulseUsec < refUsec:
130
-                break
131
-            dutyPct = refDuty
132
-
133
-        return dutyPct
134 128
             
135 129
     def _set_duty_cycle( self, pitch, pulseUsec ):
136 130
 
131
+        
137 132
         dutyPct = self._get_duty_cycle( pulseUsec )
138 133
 
139 134
         if dutyPct != self.prevHoldDutyPct:
@@ -267,14 +262,18 @@ class CalibrateKeys:
267 262
                 #self.pulseUsL,_,_ = form_resample_pulse_time_list( outDir, self.cfg.analysisArgs )
268 263
                 self.pulseUsL = get_resample_points_wrap( baseDir, pitch, self.cfg.analysisArgs )
269 264
 
265
+
270 266
             holdDutyPctL = self.cfg.calibrateArgs['holdDutyPctD'][pitch]
271 267
             
268
+            
272 269
             if playOnlyFl:
273
-                self.pulseUsL,_,holdDutyPctL = form_final_pulse_list( outDir,  pitch,  self.cfg.analysisArgs, take_id=None )
270
+
271
+                self.pulseUsL,_,holdDutyPctL = form_final_pulse_list( baseDir,  pitch,  self.cfg.analysisArgs, take_id=None )
274 272
 
275 273
                 noteN = cfg.analysisArgs['auditionNoteN']
276 274
                 self.pulseUsL   = [ self.pulseUsL[ int(round(i*126.0/(noteN-1)))] for i in range(noteN) ]
277 275
 
276
+                
278 277
             else:
279 278
                 outDir = os.path.join( outDir, str(outDir_id) )
280 279
 
@@ -339,6 +338,7 @@ class App:
339 338
                 self.audio_dev_list(0)
340 339
             
341 340
         else:
341
+            print("The cfg file has no audio stanza. No audio device will be initialized.")
342 342
             self.audioDev = None
343 343
 
344 344
         if True:
@@ -368,7 +368,7 @@ class App:
368 368
                 self.calibrate = None #Calibrate( cfg.calibrateArgs, self.audioDev, self.midiDev, self.api )
369 369
 
370 370
                 self.midiFilePlayer = MidiFilePlayer( cfg, self.api, self.midiDev, cfg.midiFileFn )
371
-    
371
+
372 372
         return res
373 373
 
374 374
     def tick( self, ms ):
@@ -389,11 +389,13 @@ class App:
389 389
             self.midiFilePlayer.tick(ms)
390 390
 
391 391
     def audio_dev_list( self, ms ):
392
-        portL = self.audioDev.get_port_list( True )
393
-
394
-        for port in portL:
395
-            print("chs:%4i label:%s" % (port['chN'],port['label']))
396 392
 
393
+        if self.audioDev is not None:
394
+            portL = self.audioDev.get_port_list( True )
395
+        
396
+            for port in portL:
397
+                print("chs:%4i label:%s" % (port['chN'],port['label']))
398
+        
397 399
     def midi_dev_list( self, ms ):
398 400
         d = self.midiDev.get_port_list( True )
399 401
 
@@ -411,7 +413,7 @@ class App:
411 413
         self.cal_keys.start(  ms, pitchL, cfg.full_pulseL )
412 414
 
413 415
     def play_keys_start( self, ms, pitchRangeL ):
414
-        chordL = [ [pitch]  for pitch in range(pitchRangeL[0], pitchRangeL[1]+1)]
416
+        chordL = [ pitch  for pitch in range(pitchRangeL[0], pitchRangeL[1]+1)]
415 417
         self.cal_keys.start(  ms, chordL, cfg.full_pulseL, playOnlyFl=True )
416 418
 
417 419
     def keyboard_start_pulse_idx( self, ms, argL ):
@@ -709,10 +711,30 @@ def parse_args():
709 711
     return ap.parse_args()
710 712
     
711 713
             
712
-    
714
+def create_logger():
715
+    import multiprocessing, logging
716
+    logger = multiprocessing.get_logger()
717
+    logger.setLevel(logging.INFO)
718
+    formatter = logging.Formatter(\
719
+        '[%(asctime)s| %(levelname)s| %(processName)s] %(message)s')
720
+    handler = logging.FileHandler('/home/kevin/temp/p_ac_log.txt')
721
+    handler.setFormatter(formatter)
722
+
723
+    # this bit will make sure you won't have 
724
+    # duplicated messages in the output
725
+    if not len(logger.handlers): 
726
+        logger.addHandler(handler)
727
+    return logger
728
+
713 729
 if __name__ == "__main__":
730
+
731
+
732
+    from multiprocessing import Pool
733
+    logger = create_logger()
734
+    logger.info('Starting pooling')
735
+    #p = Pool()
714 736
     
715
-    logging.basicConfig()
737
+    #logging.basicConfig()
716 738
 
717 739
     #mplog = multiprocessing.log_to_stderr()
718 740
     #mplog.setLevel(logging.INFO)

+ 28
- 28
p_ac.yml View File

@@ -25,10 +25,10 @@
25 25
     prescaler_usec: 16,
26 26
     pwm_div: 5,
27 27
     serial_sync_timeout_ms: 10000,
28
-
28
+    
29 29
 
30 30
     # MeasureSeq args
31
-    outDir: "~/temp/p_ac_3_oe",
31
+    outDir: "~/temp/p_ac_3_of",
32 32
     noteDurMs: 500,
33 33
     pauseDurMs: 500,
34 34
     reversePulseListFl: True,
@@ -37,6 +37,8 @@
37 37
     silentNoteMaxPulseUs: 15000,
38 38
     silentNoteMinDurMs: 180, #250,
39 39
 
40
+    defaultHoldDelayUsecs: 1000,
41
+
40 42
     # Midi file player
41 43
     midiFileFn: "/home/kevin/media/audio/midi/txt/round4.txt",
42 44
     
@@ -87,14 +89,12 @@
87 89
 
88 90
     full_pulse20L: [  1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000, 3250, 3500, 3750, 4000, 4250, 4500, 4750, 5000, 5250, 5500, 5750, 6000, 6250, 6500, 6750, 7000, 7250, 7500, 7750, 8000, 8250, 8500, 8750, 9000, 9250, 9500, 9750, 10000, 10250, 10500, 10750, 11000, 11250, 11500, 11750, 12000, 12250, 12500, 12750, 13000, 13500, 14000, 14500, 15000, 15500 ],
89 91
 
90
-    # 60,72
91 92
     full_pulse21L: [  1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000, 3250, 3500, 3750, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000 ],
92 93
 
93
-    # 48,36,85
94 94
     full_pulse22L: [  3500, 3750, 4000, 4250, 4500, 4750, 5000, 5250, 5500, 5750, 6000, 6250, 6500, 6750, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 10500, 11000, 12000, 12500, 13000, 14000, 15000, 16000, 17000, 18000, 19000 ],
95 95
 
96
-    # 84
97
-    full_pulseL: [  2000, 2250, 2500,2750, 3000, 3250, 3500, 3750, 4000, 4250, 4500, 4750, 5000, 5250, 5500, 5750, 6000, 6250, 6500, 6750, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 10500, 11000, 12000, 12500, 13000, 14000, 15000, 16000  ],
96
+    # 60,72,84    
97
+    full_pulseL: [  2000, 2250, 2500,2750, 3000, 3250, 3500, 3750, 4000, 4250, 4500, 4750, 5000, 5250, 5500, 5750, 6000, 6250, 6500, 6750, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 10500, 11000, 11500, 12000, 12500, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 22000  ],
98 98
 
99 99
     # RMS analysis args
100 100
     analysisArgs: {
@@ -249,7 +249,7 @@
249 249
           minMeasDurMs: 140,             # minimum candidate note duration
250 250
           tolDbPct: 2.0,                 # tolerance as a percent of targetDb above/below used to form match db window
251 251
           maxPulseUs: 45000,             # max. allowable pulse us
252
-          minPulseUs:  8000,             # min. allowable pulse us
252
+          minPulseUs:  2000,             # min. allowable pulse us
253 253
           initPulseUs: 15000,            # pulseUs for first note
254 254
           minMatchN: 3,                  # at least 3 candidate notes must be within tolDbPct to move on to a new targetDb
255 255
           maxAttemptN: 30,               # give up if more than 20 candidate notes fail for a given targetDb
@@ -269,7 +269,7 @@
269 269
           33: [[0, 40]],
270 270
           34: [[0, 40]],
271 271
           35: [[0, 40]],
272
-          36: [[0, 45]],
272
+          36: [[0, 40]],
273 273
           37: [[0, 40]],
274 274
           38: [[0, 40]],
275 275
           39: [[0, 40]],
@@ -292,12 +292,12 @@
292 292
           56: [[0, 40]],
293 293
           57: [[0, 40]],
294 294
           58: [[0, 40]],
295
-          59: [[0, 40]],
296
-          60: [[0, 50]],
297
-          61: [[0, 43]],
298
-          62: [[0, 43]],
299
-          63: [[0, 43]],
300
-          64: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
295
+          59: [[0, 45]],
296
+          60: [[0, 40],[10000,50]],
297
+          61: [[0, 40],[10000,50]],
298
+          62: [[0, 40],[10000,50]],
299
+          63: [[0, 40],[10000,50]],
300
+          64: [[0, 40],[10000,50]],
301 301
           65: [[0, 99]],              
302 302
           66: [[0, 40]],
303 303
           67: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
@@ -305,20 +305,20 @@
305 305
           69: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
306 306
           70: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
307 307
           71: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
308
-          72: [[0, 45],[11000, 65] ],
309
-          73: [[0, 45],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
310
-          74: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
311
-          75: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
312
-          76: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
313
-          77: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
314
-          78: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
315
-          79: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
316
-          80: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
317
-          81: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
318
-          82: [[0, 40],[14000,45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
319
-          83: [[0, 42]],
320
-          84: [[0, 42],[10000,50],[11000,60]], 
321
-          85: [[0, 42],[9000,45],[10000,50],[11000,60]],
308
+          72: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
309
+          73: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
310
+          74: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
311
+          75: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
312
+          76: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
313
+          77: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
314
+          78: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
315
+          79: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
316
+          80: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
317
+          81: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
318
+          82: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
319
+          83: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
320
+          84: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
321
+          85: [[0, 42],[8000,44],[9000,46],[10000, 48],[11000,50],[12000,52],[13000,54],[14000,56],[15000,58],[16000,60],[17000,60],[18000,60],[19000,60],[20000,60] ],
322 322
           86: [[0, 40]],
323 323
           87: [[0, 40]],
324 324
           88: [[0, 40]],

Loading…
Cancel
Save