Changeset 6059ec7 in ammosreader


Ignore:
Timestamp:
06/28/22 19:22:31 (3 years ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
AmmosSource, guix
Children:
b41e975
Parents:
72b50cd
Message:

accessors added - AmmosAudioDataBlock added

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • ammosreader/AmmosAudioReader.py

    r72b50cd r6059ec7  
    99from ammosreader.AmmosSingleFrame import AmmosSingleFrame
    1010from ammosreader.AmmosContainer import AmmosContainer
     11from ammosreader.AmmosAudioDataBlock import AmmosAudioDataBlock
    1112
    1213
     
    146147            return None
    147148        # print([hex(c) for c in byte_string])
    148         return byte_string
     149        return AmmosAudioDataBlock(byte_string, channel_count, sample_count, sample_size)
    149150
    150151    def read_next_global_frame_body(self, global_frame_header):
     
    199200        ammos_single_frame = AmmosSingleFrame(global_frame_header, global_frame_body)
    200201        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  
    44
    55    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
    921
    1022    def add_tag(self, tag):
    11         self.tags.append(tag)
     23        self.__tags.append(tag)
    1224
    1325    def add_frame(self, frame):
    14         self.global_frames.append(frame)
     26        self.__global_frames.append(frame)
    1527
    1628    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])
    1830
    1931    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)))
    2133
    2234    def __str__(self):
    23         start_time = self.global_frames[0].global_frame_body.data_header.timestamp
    24         end_time = self.global_frames[-1].global_frame_body.data_header.timestamp
     35        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
    2537
    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)
    2739
    2840        return ("Start time: " + str(start_time) +
    2941                "\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  
    22
    33    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
    622
    723    def data_bytes_only(self):
     
    1329                print("Block is nil")
    1430
    15             byte_string += each_block.if_data
     31            byte_string += each_block.data
    1632
    1733        return byte_string
  • ammosreader/AmmosSingleFrame.py

    r72b50cd r6059ec7  
    22
    33    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
    614
    715    def data(self):
  • sample_scripts/audio_reader.py

    r72b50cd r6059ec7  
    11import sys
    22import os
     3import io
     4from pydub import AudioSegment
     5from pydub.playback import play
     6
    37sys.path.append('../src/')
    48
     
    1721
    1822    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.