def get_ixml(self): """Collects an iXML chunk string if the chunk is available. Attempt to get an iterator for an iXML chunk. If the generated chunk length is set, attempt to read the iXML chunk data and convert the chunk info pointer to a string. """ # set the chunk info struct chunk_info = _ffi.new("SF_CHUNK_INFO*") # set the chunk id to obtain chunk_info.id = b'iXML' chunk_info.id_size = 4; # get the chunk iterator iterator = _snd.sf_get_chunk_iterator(self._file, chunk_info) # get the chunk size to generate the data length err = _snd.sf_get_chunk_size(iterator, chunk_info) # if the chunk has data read it to a string if (chunk_info.datalen > 0): # allocate memory to the chunk data chunk_data = _ffi.new("char[]", 1024) chunk_info.data = chunk_data _snd.sf_get_chunk_data(iterator, chunk_info) #convert the chunk data pointer to a string self.ixml_info = _ffi.buffer(chunk_info.data, chunk_info.datalen)[:].decode()
def get_ixml(self): """Collects an iXML chunk string if the chunk is available. Attempt to get an iterator for an iXML chunk. If the generated chunk length is set, attempt to read the iXML chunk data and convert the chunk info pointer to a string. """ # set the chunk info struct chunk_info = _ffi.new("SF_CHUNK_INFO*") # set the chunk id to obtain chunk_info.id = b'iXML' chunk_info.id_size = 4 # get the chunk iterator iterator = _snd.sf_get_chunk_iterator(self._file, chunk_info) # get the chunk size to generate the data length err = _snd.sf_get_chunk_size(iterator, chunk_info) # if the chunk has data read it to a string if (chunk_info.datalen > 0): # allocate memory to the chunk data chunk_data = _ffi.new("char[]", 1024) chunk_info.data = chunk_data _snd.sf_get_chunk_data(iterator, chunk_info) #convert the chunk data pointer to a string self.ixml_info = _ffi.buffer(chunk_info.data, chunk_info.datalen)[:].decode()
def get_bext(self): """Retrieve the broadcast wave bext chunk metadata from a libsndfile command and return the converted data to a dict.""" info = _ffi.new("SF_BROADCAST_INFO*") _snd.sf_command(self._file, _snd.SFC_GET_BROADCAST_INFO, info, 1024) #return the broadcast wave metadata to a dict after formatting ffi bytes to strings, formatted seconds from midnight to time string self.bext_info = { "description": self.ffi_string(info.description), "originator": self.ffi_string(info.originator), "originator_reference": self.ffi_string(info.originator_reference), "origination_date": self.ffi_string(info.origination_date), "origination_time": self.ffi_string(info.origination_time), "timereference_translated": samples_to_time(info.time_reference_low, self.samplerate), "timereference": info.time_reference_low, "version": info.version, "umid": self.ffi_string(info.umid), "coding_history": self.ffi_string(info.coding_history) }