示例#1
0
 def test_eq_gain_type(self):
     gd1 = GainData(0, 0, 0, GainType.TP_TRACK)
     gd2 = GainData(0, 0, 0, GainType.TP_TRACK)
     gd3 = GainData(0, 0, 0, GainType.TP_ALBUM)
     gd4 = GainData(0, 0, 0)
     self.assertEqual(gd1, gd2)
     self.assertNotEqual(gd1, gd3)
     self.assertNotEqual(gd1, gd4)
     self.assertNotEqual(gd3, gd4)
示例#2
0
 def test_str(self):
     self.assertEqual(
         str(GainData(-1.2)),
         "gain=-1.20 dB; peak=1.00000000; reference-level=89 dB"
     )
     self.assertEqual(
         str(GainData(-1.2, 0.6, 88, GainType.TP_ALBUM)),
         "gain=-1.20 dB; peak=0.60000000; reference-level=88 dB"
     )
示例#3
0
 def test_repr(self):
     self.assertEqual(
         repr(GainData(-1.2)),
         "GainData(-1.2, 1.0, 89, GainType.TP_UNDEFINED)",
     )
     self.assertEqual(
         repr(GainData(-1.2, 0.6, 88, GainType.TP_ALBUM)),
         "GainData(-1.2, 0.6, 88, GainType.TP_ALBUM)",
     )
示例#4
0
 def _read_gain_data(self, tags, gain_tag, peak_tag):
     if gain_tag in tags:
         gain = parse_db(tags[gain_tag][0])
         if gain is None:
             return None
         gaindata = GainData(gain)
         if peak_tag in tags:
             peak = parse_peak(tags[peak_tag][0])
             if peak is not None:
                 gaindata.peak = peak
     else:
         gaindata = None
     return gaindata
示例#5
0
    def __init__(self, files, force=False, ref_lvl=89):
        super().__init__()
        self.files = files
        self.ref_lvl = ref_lvl

        # TODO: force is apparently unused now. Should remove it in a cleanup.

        self._setup_pipeline()
        self._setup_rg_elem()

        self._files_iter = iter(self.files)

        # this holds all track gain data
        self.track_data = {}
        self.album_data = GainData(0,
                                   ref_level=self.ref_lvl,
                                   gain_type=GainType.TP_ALBUM)
示例#6
0
    def _process_tags(self, msg):
        """Process a tag message."""
        tags = msg.parse_tag()
        trackdata = self.track_data.setdefault(
            self._current_file,
            GainData(0, ref_level=self.ref_lvl, gain_type=GainType.TP_TRACK))

        def handle_tag(taglist, tag, userdata):
            if tag == Gst.TAG_TRACK_GAIN:
                _, trackdata.gain = taglist.get_double(tag)
            elif tag == Gst.TAG_TRACK_PEAK:
                _, trackdata.peak = taglist.get_double(tag)
            elif tag == Gst.TAG_REFERENCE_LEVEL:
                _, trackdata.ref_level = taglist.get_double(tag)

            elif tag == Gst.TAG_ALBUM_GAIN:
                _, self.album_data.gain = taglist.get_double(tag)
            elif tag == Gst.TAG_ALBUM_PEAK:
                _, self.album_data.peak = taglist.get_double(tag)

        tags.foreach(handle_tag, None)
示例#7
0
 def test_eq(self):
     gd1 = GainData(-5, 0.5, 80)
     gd2 = GainData(-5, 0.5, 80)
     self.assertTrue(gd1 == gd2)
     self.assertFalse(gd1 != gd2)
示例#8
0
 def test_bad_type(self):
     gd1 = GainData(-5, 0.6, 89)
     gd2 = "not GainData"
     self.assertTrue(gd1 != gd2)
     self.assertFalse(gd1 == gd2)
示例#9
0
def clamp_gain_data(gain_data):
    if gain_data is None:
        return None
    else:
        return GainData(clamp_rva2_gain(gain_data.gain),
                        clamp_rva2_peak(gain_data.peak), gain_data.ref_level)