Changeset 6059ec7 in ammosreader
- Timestamp:
- 06/28/22 19:22:31 (3 years ago)
- Branches:
- AmmosSource, guix
- Children:
- b41e975
- Parents:
- 72b50cd
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ammosreader/AmmosAudioReader.py
r72b50cd r6059ec7 9 9 from ammosreader.AmmosSingleFrame import AmmosSingleFrame 10 10 from ammosreader.AmmosContainer import AmmosContainer 11 from ammosreader.AmmosAudioDataBlock import AmmosAudioDataBlock 11 12 12 13 … … 146 147 return None 147 148 # print([hex(c) for c in byte_string]) 148 return byte_string149 return AmmosAudioDataBlock(byte_string, channel_count, sample_count, sample_size) 149 150 150 151 def read_next_global_frame_body(self, global_frame_header): … … 199 200 ammos_single_frame = AmmosSingleFrame(global_frame_header, global_frame_body) 200 201 return ammos_single_frame 202 203 def pcm_for_channel(self, a_channel): 204 return b"".join([each.global_frame_body.data_body.pcm_for_channel(a_channel) for each in self.container.global_frames]) -
ammosreader/AmmosContainer.py
r72b50cd r6059ec7 4 4 5 5 def __init__(self, name, frames): 6 self.name = name 7 self.global_frames = frames 8 self.tags = [] 6 self.__name = name 7 self.__global_frames = frames 8 self.__tags = [] 9 10 @property 11 def name(self): 12 return self.__name 13 14 @name.setter 15 def name(self, a_name): 16 self.__name = a_name 17 18 @property 19 def global_frames(self): 20 return self.__global_frames 9 21 10 22 def add_tag(self, tag): 11 self. tags.append(tag)23 self.__tags.append(tag) 12 24 13 25 def add_frame(self, frame): 14 self. global_frames.append(frame)26 self.__global_frames.append(frame) 15 27 16 28 def size(self): 17 return sum([each.global_frame_header.frame_length for each in self. global_frames])29 return sum([each.global_frame_header.frame_length for each in self.__global_frames]) 18 30 19 31 def frequencies(self): 20 return set(list(filter(lambda frame: frame.global_frame_body.data_header.frequency, self. global_frames)))32 return set(list(filter(lambda frame: frame.global_frame_body.data_header.frequency, self.__global_frames))) 21 33 22 34 def __str__(self): 23 start_time = self. global_frames[0].global_frame_body.data_header.timestamp24 end_time = self. global_frames[-1].global_frame_body.data_header.timestamp35 start_time = self.__global_frames[0].global_frame_body.data_header.timestamp 36 end_time = self.__global_frames[-1].global_frame_body.data_header.timestamp 25 37 26 frq = str(self. global_frames[0].global_frame_body.data_header.frequency)38 frq = str(self.__global_frames[0].global_frame_body.data_header.frequency) 27 39 28 40 return ("Start time: " + str(start_time) + 29 41 "\nEnd time : " + str(end_time) + "\nFrequencies: " + frq) 42 43 def data_only(self): 44 return [each.global_frame_body.data_body.data for each in self.__global_frames] -
ammosreader/AmmosGlobalFrameBody.py
r72b50cd r6059ec7 2 2 3 3 def __init__(self, data_header, data_body): 4 self.data_header = data_header 5 self.data_body = data_body 4 self.__data_header = data_header 5 self.__data_body = data_body 6 7 @property 8 def data_header(self): 9 return self.__data_header 10 11 @data_header.setter 12 def data_header(self, a_data_header): 13 self.__data_header = a_data_header 14 15 @property 16 def data_body(self): 17 return self.__data_body 18 19 @data_body.setter 20 def data_body(self, data_bytes): 21 self.__data_body = data_bytes 6 22 7 23 def data_bytes_only(self): … … 13 29 print("Block is nil") 14 30 15 byte_string += each_block. if_data31 byte_string += each_block.data 16 32 17 33 return byte_string -
ammosreader/AmmosSingleFrame.py
r72b50cd r6059ec7 2 2 3 3 def __init__(self, global_frame_header, global_frame_body): 4 self.global_frame_header = global_frame_header 5 self.global_frame_body = global_frame_body 4 self.__global_frame_header = global_frame_header 5 self.__global_frame_body = global_frame_body 6 7 @property 8 def global_frame_header(self): 9 return self.__global_frame_header 10 11 @property 12 def global_frame_body(self): 13 return self.__global_frame_body 6 14 7 15 def data(self): -
sample_scripts/audio_reader.py
r72b50cd r6059ec7 1 1 import sys 2 2 import os 3 import io 4 from pydub import AudioSegment 5 from pydub.playback import play 6 3 7 sys.path.append('../src/') 4 8 … … 17 21 18 22 dat_file.read_all_frames_left() 19 print(dat_file.container.size()) 23 print("Sample rate:", dat_file.container.global_frames[0].global_frame_body.data_header.sample_rate) 24 print("Container size:", dat_file.container.size()) 25 pcm_data = dat_file.pcm_for_channel(0) 26 print("PCM data size total:", len(pcm_data)) 27 data = AudioSegment.from_raw(io.BytesIO(pcm_data), 28 sample_width=2, 29 frame_rate=22050, 30 channels=1) 31 play(data)
Note:
See TracChangeset
for help on using the changeset viewer.