Quellcode durchsuchen

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

master
kevin vor 3 Jahren
Ursprung
Commit
648e29c4c4
2 geänderte Dateien mit 69 neuen und 47 gelöschten Zeilen
  1. 41
    19
      p_ac.py
  2. 28
    28
      p_ac.yml

+ 41
- 19
p_ac.py Datei anzeigen

58
         self.eventTimeL = [[0,0]  for _ in range(len(pulseUsL))] # initialize the event time         
58
         self.eventTimeL = [[0,0]  for _ in range(len(pulseUsL))] # initialize the event time         
59
         self.beginMs    = ms
59
         self.beginMs    = ms
60
         self.playOnlyFl = playOnlyFl
60
         self.playOnlyFl = playOnlyFl
61
-
62
-
61
+                    
63
         # kpl if not playOnlyFl:
62
         # kpl if not playOnlyFl:
64
         self.audio.record_enable(True)   # start recording audio
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
         self.tick(ms)                    # play the first note
68
         self.tick(ms)                    # play the first note
67
         
69
         
123
         
125
         
124
     def _get_duty_cycle( self, pulseUsec ):
126
     def _get_duty_cycle( self, pulseUsec ):
125
         return self.holdDutyPctD[ pulseUsec ]
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
     def _set_duty_cycle( self, pitch, pulseUsec ):
129
     def _set_duty_cycle( self, pitch, pulseUsec ):
136
 
130
 
131
+        
137
         dutyPct = self._get_duty_cycle( pulseUsec )
132
         dutyPct = self._get_duty_cycle( pulseUsec )
138
 
133
 
139
         if dutyPct != self.prevHoldDutyPct:
134
         if dutyPct != self.prevHoldDutyPct:
267
                 #self.pulseUsL,_,_ = form_resample_pulse_time_list( outDir, self.cfg.analysisArgs )
262
                 #self.pulseUsL,_,_ = form_resample_pulse_time_list( outDir, self.cfg.analysisArgs )
268
                 self.pulseUsL = get_resample_points_wrap( baseDir, pitch, self.cfg.analysisArgs )
263
                 self.pulseUsL = get_resample_points_wrap( baseDir, pitch, self.cfg.analysisArgs )
269
 
264
 
265
+
270
             holdDutyPctL = self.cfg.calibrateArgs['holdDutyPctD'][pitch]
266
             holdDutyPctL = self.cfg.calibrateArgs['holdDutyPctD'][pitch]
271
             
267
             
268
+            
272
             if playOnlyFl:
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
                 noteN = cfg.analysisArgs['auditionNoteN']
273
                 noteN = cfg.analysisArgs['auditionNoteN']
276
                 self.pulseUsL   = [ self.pulseUsL[ int(round(i*126.0/(noteN-1)))] for i in range(noteN) ]
274
                 self.pulseUsL   = [ self.pulseUsL[ int(round(i*126.0/(noteN-1)))] for i in range(noteN) ]
277
 
275
 
276
+                
278
             else:
277
             else:
279
                 outDir = os.path.join( outDir, str(outDir_id) )
278
                 outDir = os.path.join( outDir, str(outDir_id) )
280
 
279
 
339
                 self.audio_dev_list(0)
338
                 self.audio_dev_list(0)
340
             
339
             
341
         else:
340
         else:
341
+            print("The cfg file has no audio stanza. No audio device will be initialized.")
342
             self.audioDev = None
342
             self.audioDev = None
343
 
343
 
344
         if True:
344
         if True:
368
                 self.calibrate = None #Calibrate( cfg.calibrateArgs, self.audioDev, self.midiDev, self.api )
368
                 self.calibrate = None #Calibrate( cfg.calibrateArgs, self.audioDev, self.midiDev, self.api )
369
 
369
 
370
                 self.midiFilePlayer = MidiFilePlayer( cfg, self.api, self.midiDev, cfg.midiFileFn )
370
                 self.midiFilePlayer = MidiFilePlayer( cfg, self.api, self.midiDev, cfg.midiFileFn )
371
-    
371
+
372
         return res
372
         return res
373
 
373
 
374
     def tick( self, ms ):
374
     def tick( self, ms ):
389
             self.midiFilePlayer.tick(ms)
389
             self.midiFilePlayer.tick(ms)
390
 
390
 
391
     def audio_dev_list( self, ms ):
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
     def midi_dev_list( self, ms ):
399
     def midi_dev_list( self, ms ):
398
         d = self.midiDev.get_port_list( True )
400
         d = self.midiDev.get_port_list( True )
399
 
401
 
411
         self.cal_keys.start(  ms, pitchL, cfg.full_pulseL )
413
         self.cal_keys.start(  ms, pitchL, cfg.full_pulseL )
412
 
414
 
413
     def play_keys_start( self, ms, pitchRangeL ):
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
         self.cal_keys.start(  ms, chordL, cfg.full_pulseL, playOnlyFl=True )
417
         self.cal_keys.start(  ms, chordL, cfg.full_pulseL, playOnlyFl=True )
416
 
418
 
417
     def keyboard_start_pulse_idx( self, ms, argL ):
419
     def keyboard_start_pulse_idx( self, ms, argL ):
709
     return ap.parse_args()
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
 if __name__ == "__main__":
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
     #mplog = multiprocessing.log_to_stderr()
739
     #mplog = multiprocessing.log_to_stderr()
718
     #mplog.setLevel(logging.INFO)
740
     #mplog.setLevel(logging.INFO)

+ 28
- 28
p_ac.yml Datei anzeigen

25
     prescaler_usec: 16,
25
     prescaler_usec: 16,
26
     pwm_div: 5,
26
     pwm_div: 5,
27
     serial_sync_timeout_ms: 10000,
27
     serial_sync_timeout_ms: 10000,
28
-
28
+    
29
 
29
 
30
     # MeasureSeq args
30
     # MeasureSeq args
31
-    outDir: "~/temp/p_ac_3_oe",
31
+    outDir: "~/temp/p_ac_3_of",
32
     noteDurMs: 500,
32
     noteDurMs: 500,
33
     pauseDurMs: 500,
33
     pauseDurMs: 500,
34
     reversePulseListFl: True,
34
     reversePulseListFl: True,
37
     silentNoteMaxPulseUs: 15000,
37
     silentNoteMaxPulseUs: 15000,
38
     silentNoteMinDurMs: 180, #250,
38
     silentNoteMinDurMs: 180, #250,
39
 
39
 
40
+    defaultHoldDelayUsecs: 1000,
41
+
40
     # Midi file player
42
     # Midi file player
41
     midiFileFn: "/home/kevin/media/audio/midi/txt/round4.txt",
43
     midiFileFn: "/home/kevin/media/audio/midi/txt/round4.txt",
42
     
44
     
87
 
89
 
88
     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 ],
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
     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
     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
     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 ],
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
     # RMS analysis args
99
     # RMS analysis args
100
     analysisArgs: {
100
     analysisArgs: {
249
           minMeasDurMs: 140,             # minimum candidate note duration
249
           minMeasDurMs: 140,             # minimum candidate note duration
250
           tolDbPct: 2.0,                 # tolerance as a percent of targetDb above/below used to form match db window
250
           tolDbPct: 2.0,                 # tolerance as a percent of targetDb above/below used to form match db window
251
           maxPulseUs: 45000,             # max. allowable pulse us
251
           maxPulseUs: 45000,             # max. allowable pulse us
252
-          minPulseUs:  8000,             # min. allowable pulse us
252
+          minPulseUs:  2000,             # min. allowable pulse us
253
           initPulseUs: 15000,            # pulseUs for first note
253
           initPulseUs: 15000,            # pulseUs for first note
254
           minMatchN: 3,                  # at least 3 candidate notes must be within tolDbPct to move on to a new targetDb
254
           minMatchN: 3,                  # at least 3 candidate notes must be within tolDbPct to move on to a new targetDb
255
           maxAttemptN: 30,               # give up if more than 20 candidate notes fail for a given targetDb
255
           maxAttemptN: 30,               # give up if more than 20 candidate notes fail for a given targetDb
269
           33: [[0, 40]],
269
           33: [[0, 40]],
270
           34: [[0, 40]],
270
           34: [[0, 40]],
271
           35: [[0, 40]],
271
           35: [[0, 40]],
272
-          36: [[0, 45]],
272
+          36: [[0, 40]],
273
           37: [[0, 40]],
273
           37: [[0, 40]],
274
           38: [[0, 40]],
274
           38: [[0, 40]],
275
           39: [[0, 40]],
275
           39: [[0, 40]],
292
           56: [[0, 40]],
292
           56: [[0, 40]],
293
           57: [[0, 40]],
293
           57: [[0, 40]],
294
           58: [[0, 40]],
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
           65: [[0, 99]],              
301
           65: [[0, 99]],              
302
           66: [[0, 40]],
302
           66: [[0, 40]],
303
           67: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
303
           67: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
305
           69: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
305
           69: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
306
           70: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
306
           70: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
307
           71: [[0, 40],[14000, 45],[15000,50],[16000,55],[17000,60],[18000,65],[19000,55]],
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
           86: [[0, 40]],
322
           86: [[0, 40]],
323
           87: [[0, 40]],
323
           87: [[0, 40]],
324
           88: [[0, 40]],
324
           88: [[0, 40]],

Laden…
Abbrechen
Speichern