-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
In the FileDecoder class _write_callback method when sf.SoundFile object is created subtype is not specified. SoundFile's default subtype for the WAV format is PCM_16. This means for a 32-bit FLAC file, it is decoded properly but written as a 16-bit wave. Even though data is of type np.int32. I implemented the quick fix show below to get me by. I will leave the proper fix to someone more familiar with this project.
def _write_callback(self, data: np.ndarray, sample_rate: int, num_channels: int, num_samples: int):
"""
Internal callback to write the decoded data to a WAV file.
"""
if self.__output is None:
#Need to add subtype argument to SoundFile. If data is of type np.int32 it will be truncated by
#SoundFile's default subtype 'PCM_16' for the WAV format and the lower 16-bits of the sample are dropped.
if data.dtype == np.int32:
sub_type = 'PCM_32'
else:
sub_type = 'PCM_16'
self.__output = sf.SoundFile(
self.__output_file, mode='w', channels=num_channels,
samplerate=sample_rate, subtype=sub_type
)
self.__output.write(data)
joetoddsonos
Metadata
Metadata
Assignees
Labels
No labels