瀏覽代碼

broadcast now uses samephase, client can clip

Graham Northup 7 年之前
父節點
當前提交
5c205fd148
共有 3 個文件被更改,包括 11 次插入6 次删除
  1. 1 1
      broadcast.py
  2. 7 3
      client.py
  3. 3 2
      mkiv.py

+ 1 - 1
broadcast.py

@@ -614,7 +614,7 @@ for fname in args:
                         if options.clamp:
                             amp = max(min(amp, 1.0), 0.0)
                         flags = 0
-                        if note.get('parent', None):
+                        if note.get('par', None):
                             flags |= PLF.SAMEPHASE
                         for cl in cls:
                             s.sendto(str(Packet(CMD.PLAY, int(pl_dur), int((pl_dur*1000000)%1000000), int(440.0 * 2**((pitch-69)/12.0)), amp, cl[2], flags)), cl[:2])

+ 7 - 3
client.py

@@ -56,6 +56,7 @@ UID = options.uid
 LAST_SAMPS = [0] * STREAMS
 LAST_SAMPLES = []
 FREQS = [0] * STREAMS
+REAL_FREQS = [0] * STREAMS
 PHASES = [0] * STREAMS
 RATE = options.rate
 FPB = 64
@@ -142,7 +143,7 @@ def pygame_notes():
         else:
             gap = WIDTH / STREAMS
             for i in xrange(STREAMS):
-                FREQ = FREQS[i]
+                FREQ = REAL_FREQS[i]
                 AMP = AMPS[i]
                 if FREQ > 0:
                     bgcol = rgb_for_freq_amp(FREQ, float(AMP) / MAX)
@@ -154,7 +155,7 @@ def pygame_notes():
         bgrwin.scroll(-1, 0)
         bgrwin.fill((0, 0, 0), (BGR_WIDTH - 1, 0, 1, HEIGHT))
         for i in xrange(STREAMS):
-            FREQ = FREQS[i]
+            FREQ = REAL_FREQS[i]
             AMP = AMPS[i]
             if FREQ > 0:
                 try:
@@ -163,7 +164,7 @@ def pygame_notes():
                     pitch = 0
             else:
                 pitch = 0
-            col = [int((AMP / MAX) * 255)] * 3
+            col = [min(max(int((AMP / MAX) * 255), 0), 255)] * 3
             bgrwin.fill(col, (BGR_WIDTH - 1, HEIGHT - pitch * PFAC - PFAC, 1, PFAC))
 
         sampwin.scroll(-len(LAST_SAMPLES), 0)
@@ -491,6 +492,7 @@ def gen_data(data, frames, tm, status):
             midi = 12 * math.log(FREQ / 440.0, 2) + 69
             midi += options.vibrato * math.sin(time.time() * 2 * math.pi * options.vibrato_freq + i * 2 * math.pi / STREAMS)
             FREQ = 440.0 * 2 ** ((midi - 69) / 12)
+        REAL_FREQS[i] = FREQ
         LAST_SAMP = LAST_SAMPS[i]
         AMP = AMPS[i]
         EXPIRATION = EXPIRATIONS[i]
@@ -583,6 +585,8 @@ while True:
         print '\x1b[1;32mPLAY',
         print '\x1b[1;38;2;{};{};{}mVOICE'.format(*vrgb), '{:03}'.format(voice),
         print '\x1b[1;38;2;{};{};{}mFREQ'.format(*frgb), '{:04}'.format(pkt.data[2]), 'AMP', '%08.6f'%pkt.as_float(3),
+        if pkt.data[5] & PLF.SAMEPHASE:
+            print '\x1b[1;37mSAMEPHASE',
         if pkt.data[0] == 0 and pkt.data[1] == 0:
             print '\x1b[1;35mSTOP!!!'
         else:

+ 3 - 2
mkiv.py

@@ -43,6 +43,7 @@ parser.add_option('--string-threshold', dest='stringthres', type='float', help='
 parser.add_option('--tempo', dest='tempo', help='Adjust interpretation of tempo (try "f1"/"global", "f2"/"track")')
 parser.add_option('--epsilon', dest='epsilon', type='float', help='Don\'t consider overlaps smaller than this number of seconds (which regularly happen due to precision loss)')
 parser.add_option('--slack', dest='slack', type='float', help='Inflate the duration of events by this much when scheduling them--this is for clients which need time to release their streams')
+parser.add_option('--real-slack', dest='real_slack', type='float', help='Add this much time to each real note with the intent of causing small overlaps, allowing clients to maintain phase consistency at high event rates')
 parser.add_option('--vol-pow', dest='vol_pow', type='float', help='Exponent to raise volume changes (adjusts energy per delta volume)')
 parser.add_option('-0', '--keep-empty', dest='keepempty', action='store_true', help='Keep (do not cull) events with 0 duration in the output file')
 parser.add_option('--no-text', dest='no_text', action='store_true', help='Disable text streams (useful for unusual text encodings)')
@@ -53,7 +54,7 @@ parser.add_option('--wav-window', dest='wav_window', type='int', help='Size of t
 parser.add_option('--wav-streams', dest='wav_streams', type='int', help='Number of output streams to generate for the interval file')
 parser.add_option('--wav-log-width', dest='wav_log_width', type='float', help='Width of the correcting exponent--positive prefers high frequencies, negative prefers lower')
 parser.add_option('--wav-log-base', dest='wav_log_base', type='float', help='Base of the logarithm used to scale low frequencies')
-parser.set_defaults(tracks=[], perc='GM', deviation=2, tempo='global', modres=0.005, modfdev=2.0, modffreq=8.0, modadev=0.5, modafreq=8.0, stringres=0, stringmax=1024, stringrateon=0.7, stringrateoff=0.4, stringthres=0.02, epsilon=1e-12, slack=0.0, vol_pow=2, wav_winf='ones', wav_frames=512, wav_window=2048, wav_streams=16, wav_log_width=0.0, wav_log_base=2.0)
+parser.set_defaults(tracks=[], perc='GM', deviation=2, tempo='global', modres=0.005, modfdev=2.0, modffreq=8.0, modadev=0.5, modafreq=8.0, stringres=0, stringmax=1024, stringrateon=0.7, stringrateoff=0.4, stringthres=0.02, epsilon=1e-12, slack=0.0, real_slack=0.001, vol_pow=2, wav_winf='ones', wav_frames=512, wav_window=2048, wav_streams=16, wav_log_width=0.0, wav_log_base=2.0)
 options, args = parser.parse_args()
 if options.tempo == 'f1':
     options.tempo == 'global'
@@ -782,7 +783,7 @@ for fname in args:
                             ivnote.set('vel', str(int(note.ampl * 127.0)))
                             ivnote.set('ampl', str(note.ampl))
                             ivnote.set('time', str(note.abstime))
-                            ivnote.set('dur', str(note.real_duration))
+                            ivnote.set('dur', str(note.real_duration + options.real_slack))
                             if note.par:
                                 ivnote.set('par', str(id(note.par)))