Changeset 008dcb7 in ammosreader
- Timestamp:
- 05/28/23 09:21:31 (2 years ago)
- Branches:
- AmmosSource
- Children:
- 0c6fd4c
- Parents:
- d2736bb
- Location:
- ammosreader
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
ammosreader/AbstractAmmosReader.py
rd2736bb r008dcb7 13 13 """I implement a base class for specialized AmmosReaders.""" 14 14 15 def __init__(self, file_name):15 def __init__(self, source): 16 16 """ 17 17 I am the standard constructor for Ammos Readers. … … 19 19 Additional information about the file can be added as key/value pairs in tags 20 20 21 :param file_name: The file to read Ammos data from22 :type file_name: str21 :param source: The source to read Ammos data from 22 :type source: AmmosSource 23 23 """ 24 self.__file_name = file_name 25 self.__ammos_file = open(self.file_name, "rb") 26 self.__container = AmmosContainer(self.file_name, []) 24 self.__source = source 25 self.__container = AmmosContainer(self.__source.name, []) 27 26 self.__tags = {} 28 27 29 28 @property 30 def file_name(self): 31 """I return the name of the original file.""" 32 return self.__file_name 33 34 @property 35 def ammos_file(self): 36 """I return the file to read the data from.""" 37 return self.__ammos_file 29 def source(self): 30 """I return the source of this reader.""" 31 return self.__source 38 32 39 33 @property … … 51 45 assert a_key not in self.__tags 52 46 self.__tags[a_key] = a_value 53 54 def rewind_to_start(self):55 """I set the file pointer to the beginning of the file for the next operation."""56 self.ammos_file.seek(0)57 47 58 48 def read_all_frames_left(self): … … 85 75 header_size = AmmosGlobalFrameHeader.HEADER_SIZE 86 76 87 in_bytes = self. ammos_file.read(header_size)77 in_bytes = self.__source.read_bytes(header_size) 88 78 logger.info("Reading next global frame header") 89 79 if ((not in_bytes) or (len(in_bytes) < header_size)): … … 99 89 return current_global_frame_header 100 90 91 def read_bytes(self, bytes_to_read): 92 """My descendents have to implement this.""" 93 return self.__source.read_bytes(bytes_to_read) 94 101 95 @abstractmethod 102 96 def read_next_global_frame_body(self, data_header_length): -
ammosreader/AmmosAudioReader.py
rd2736bb r008dcb7 23 23 header_size = AmmosAudioDataHeader.HEADER_SIZE 24 24 25 in_bytes = self. ammos_file.read(header_size)25 in_bytes = self.source.read_bytes(header_size) 26 26 27 27 logger.info("\nReading global frame body standard data header\n") … … 40 40 header_size = AmmosExtendedAudioDataHeader.HEADER_SIZE 41 41 42 in_bytes = self. ammos_file.read(header_size)42 in_bytes = self.source.read_bytes(header_size) 43 43 44 44 if ((not in_bytes) or (len(in_bytes) < header_size)): … … 65 65 total = number_of_samples*number_of_channels*sample_size 66 66 67 byte_string = self. ammos_file.read(total)67 byte_string = self.source.read_bytes(total) 68 68 69 69 if len(byte_string) != total: … … 113 113 :rtype: bytes 114 114 """ 115 return (b"".join([each.global_frame_body.data_body.pcm_for_channel(a_channel) 116 for each in self.container.global_frames])) 115 return self.__container.pcm_for_channel(a_channel) -
ammosreader/AmmosAudioSocketReader.py
rd2736bb r008dcb7 103 103 ammos_global_header_buffer.append(self.__get_next_data(20)) 104 104 # while len(b''.join(ammos_global_header_buffer)) < 24: 105 # 105 # ammos_global_header_buffer.append(self.__socket.recv(24 - len(b''.join(ammos_global_header_buffer)))) 106 106 107 107 ammos_global_header = AmmosGlobalFrameHeader.from_bytes(b''.join(ammos_global_header_buffer)) -
ammosreader/AmmosContainer.py
rd2736bb r008dcb7 56 56 "\nEnd time : " + str(end_time) + "\nFrequencies: " + frq) 57 57 58 def data_only(self):58 def payload(self): 59 59 return [each.global_frame_body.data_body.data for each in self.__global_frames] 60 61 def pcm_for_channel(self, a_channel): 62 """ 63 I return the raw pcm audio data for a given channel. 64 65 :param a_channel: the channel I have to extract 66 :type a_channel: int 67 68 :rtype: bytes 69 """ 70 return (b"".join([each.global_frame_body.data_body.pcm_for_channel(a_channel) 71 for each in self.global_frames]))
Note:
See TracChangeset
for help on using the changeset viewer.