def decode_file(file_name): opened_data = SndFileLoaderBase.open_file(file_name) handle = opened_data["handle"] info = opened_data["info"] data = numpy.zeros(info.frames * info.channels, dtype=numpy.int16) libsndfile().sf_readf_short(handle, data.ctypes.data_as(POINTER(c_short)), info.frames) libsndfile().sf_close(handle) logging.info("Loaded " + file_name + ": " + info.str_format() + ", " + str(info.frames) + " samples at " + str(info.samplerate) + " Hz with " + str(info.channels) + " channels") return {"data": data, "sampling_rate": info.samplerate, "samples": info.frames, "channels": info.channels, "name": file_name}
def decode_file(file_name): opened_data = SndFileLoaderBase.open_file(file_name) handle = opened_data["handle"] info = opened_data["info"] data = numpy.zeros(info.frames * info.channels, dtype=numpy.int16) libsndfile().sf_readf_short(handle, data.ctypes.data_as(POINTER(c_short)), info.frames) libsndfile().sf_close(handle) logging.info("Loaded " + file_name + ": " + info.str_format() + ", " + str(info.frames) + " samples at " + str(info.samplerate) + " Hz with " + str(info.channels) + " channels") return { "data": data, "sampling_rate": info.samplerate, "samples": info.frames, "channels": info.channels, "name": file_name }
def open_file(file_name): info = SF_INFO() info.format = 0 handle = libsndfile().sf_open( c_char_p(file_name.encode()), libsndfile.SFM_READ, byref(info)) if not handle: raise error.BadFormatError( "Audio file %s does not exist or is in an unsupported format" % file_name) if info.channels > 2: raise error.BadFormatError("Audio file " + file_name + " has more than two channels. " "Only mono or stereo are allowed.") return {"handle": handle, "samples": info.frames, "sampling_rate": info.samplerate, "channels": info.channels, "info": info}
def open_file(file_name): info = SF_INFO() info.format = 0 handle = libsndfile().sf_open(c_char_p(file_name.encode()), libsndfile.SFM_READ, byref(info)) if not handle: raise error.BadFormatError( "Audio file %s does not exist or is in an unsupported format" % file_name) if info.channels > 2: raise error.BadFormatError("Audio file " + file_name + " has more than two channels. " "Only mono or stereo are allowed.") return { "handle": handle, "samples": info.frames, "sampling_rate": info.samplerate, "channels": info.channels, "info": info }
def close_file(opened_data): libsndfile().sf_close(opened_data["handle"])