@@ -2319,11 +2319,10 @@ def wr_dat_file(
23192319
23202320 if fmt == "80" :
23212321 # convert to 8 bit offset binary form
2322- d_signal = d_signal + 128
2323- # Concatenate into 1D
2324- d_signal = d_signal .reshape (- 1 )
2325- # Convert to un_signed 8 bit dtype to write
2326- b_write = d_signal .astype ("uint8" )
2322+ d_signal += 128
2323+
2324+ # Convert to unsigned 8 bit dtype to write (and flatten if necessary)
2325+ b_write = d_signal .astype ("uint8" ).reshape (- 1 )
23272326
23282327 elif fmt == "212" :
23292328 # Each sample is represented by a 12 bit two's complement
@@ -2336,7 +2335,7 @@ def wr_dat_file(
23362335 # repeated for each successive pair of samples.
23372336
23382337 # convert to 12 bit two's complement
2339- d_signal [d_signal < 0 ] = d_signal [ d_signal < 0 ] + 4096
2338+ d_signal [d_signal < 0 ] += 4096
23402339
23412340 # Concatenate into 1D
23422341 d_signal = d_signal .reshape (- 1 )
@@ -2384,8 +2383,8 @@ def wr_dat_file(
23842383 # Convert to un_signed 8 bit dtype to write
23852384 b_write = b_write .astype ("uint8" )
23862385 elif fmt == "24" :
2387- # convert to 24 bit two's complement
2388- d_signal [ d_signal < 0 ] = d_signal [ d_signal < 0 ] + 16777216
2386+ # convert to 32 bit two's complement (as int24 not an option)
2387+ d_signal = d_signal . astype ( np . uint32 )
23892388 # Split samples into separate bytes using binary masks
23902389 b1 = d_signal & [255 ] * tsamps_per_frame
23912390 b2 = (d_signal & [65280 ] * tsamps_per_frame ) >> 8
0 commit comments