@@ -2319,11 +2319,10 @@ def wr_dat_file(
2319
2319
2320
2320
if fmt == "80" :
2321
2321
# 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 )
2327
2326
2328
2327
elif fmt == "212" :
2329
2328
# Each sample is represented by a 12 bit two's complement
@@ -2336,7 +2335,7 @@ def wr_dat_file(
2336
2335
# repeated for each successive pair of samples.
2337
2336
2338
2337
# 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
2340
2339
2341
2340
# Concatenate into 1D
2342
2341
d_signal = d_signal .reshape (- 1 )
@@ -2384,8 +2383,8 @@ def wr_dat_file(
2384
2383
# Convert to un_signed 8 bit dtype to write
2385
2384
b_write = b_write .astype ("uint8" )
2386
2385
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 )
2389
2388
# Split samples into separate bytes using binary masks
2390
2389
b1 = d_signal & [255 ] * tsamps_per_frame
2391
2390
b2 = (d_signal & [65280 ] * tsamps_per_frame ) >> 8
0 commit comments