Skip to content

Commit

Permalink
Merge pull request #520 from happycube/chad071920
Browse files Browse the repository at this point in the history
add direct path for float32
  • Loading branch information
happycube committed Jul 28, 2020
2 parents ac82e50 + dccc889 commit 0397ed8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lddecode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def make_loader(filename, inputfreq=None):
return load_packed_data_4_40
elif filename.endswith('.r30'):
return load_packed_data_3_32
elif filename.endswith('.rf'):
return load_unpacked_data_float32
elif filename.endswith('.r16') or filename.endswith('.s16'):
return load_unpacked_data_s16
elif filename.endswith('.r8') or filename.endswith('.u8'):
Expand All @@ -156,7 +158,9 @@ def load_unpacked_data(infile, sample, readlen, sampletype):
infile.seek(sample * sampletype, 0)
inbuf = infile.read(readlen * sampletype)

if sampletype == 2:
if sampletype == 4:
indata = np.fromstring(inbuf, 'float32', len(inbuf) // 4) * 32768
elif sampletype == 2:
indata = np.fromstring(inbuf, 'int16', len(inbuf) // 2)
else:
indata = np.fromstring(inbuf, 'uint8', len(inbuf))
Expand All @@ -172,6 +176,9 @@ def load_unpacked_data_u8(infile, sample, readlen):
def load_unpacked_data_s16(infile, sample, readlen):
return load_unpacked_data(infile, sample, readlen, 2)

def load_unpacked_data_float32(infile, sample, readlen):
return load_unpacked_data(infile, sample, readlen, 4)

# This is for the .r30 format I did in ddpack/unpack.c. Depricated but I still have samples in it.
def load_packed_data_3_32(infile, sample, readlen):
start = (sample // 3) * 4
Expand Down Expand Up @@ -782,4 +789,4 @@ def write_json(ldd, outname):
os.rename(outname + '.tbc.json.tmp', outname + '.tbc.json')

if __name__ == "__main__":
print("Nothing to see here, move along ;)")
print("Nothing to see here, move along ;)")

0 comments on commit 0397ed8

Please sign in to comment.