Guest User

Untitled

a guest
Mar 8th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1.     CHANNELS = 16
  2.     SAMPLE_LENGTH = CHANNELS // 8
  3.     BYTES_PER_SAMPLE = CHANNELS // SAMPLE_LENGTH
  4.     BUFFER = 16386
  5.     PROCNUM = 4
  6.    
  7.     vals = {}
  8.     for i in range(2**16):
  9.         vals[struct.pack('H', i)] = tuple(b'1' if e == '1' else b'0' for e in list("{:016b}".format(i)))
  10.        
  11.     with open('largefile.dat', 'rb') as f:
  12.         data = f.read()
  13.     size = len(data)
  14.     print("Data size: %d" % size)
  15.    
  16.     out_file = open('largefile_dump2.dat', 'wb')
  17.     out_list = [out_file]*CHANNELS
  18.    
  19.     samples = []
  20.    
  21.     for i in range(0, size // 8, SAMPLE_LENGTH):
  22.         # if i % (1024**2) == 0: print("i = %d" % i)
  23.         samples.append(vals[data[i:i+2]])
  24.         if len(samples) >= BUFFER:
  25.             samples = np.matrix(samples).transpose().tolist() # comment if no numpy
  26.             for channel in range(CHANNELS):
  27.                 s = b''.join(samples[channel])                # comment if no numpy
  28.                 # s = b''.join(r[channel] for r in samples)   # uncomment if no numpy, don't forget to change the buffer to 256, otherwise slooow.
  29.                 out_list[channel].write(s)
  30.             samples = []
  31.    
  32.     if samples:
  33.         for channel in range(CHANNELS):
  34.             s = b'\n'.join(r[channel] for r in samples)
  35.             out_list[channel].write(s)
  36.  
  37.     out_file.close()
Advertisement
Add Comment
Please, Sign In to add comment