示例#1
0
文件: au.py 项目: gmontcheuil/sppas
def au_header(sample_rate,
              channels,
              bits_per_sample,
              total_pcm_frames):
    """given a set of integer stream attributes,
    returns header string of entire Au header

    may raise ValueError if the total size of the file is too large"""

    from audiotools.bitstream import build

    if ((channels *
         (bits_per_sample // 8) *
         total_pcm_frames) >= 2 ** 32):
        raise ValueError("PCM data too large for Sun AU file")
    else:
        return build("4b 5*32u",
                     False,
                     (b".snd",
                      24,
                      (channels *
                       (bits_per_sample // 8) *
                       total_pcm_frames),
                      {8: 2, 16: 3, 24: 4}[bits_per_sample],
                      sample_rate,
                      channels))
示例#2
0
def au_header(sample_rate, channels, bits_per_sample, total_pcm_frames):
    """given a set of integer stream attributes,
    returns header string of entire Au header

    may raise ValueError if the total size of the file is too large"""

    from audiotools.bitstream import build

    if ((channels * (bits_per_sample // 8) * total_pcm_frames) >= 2**32):
        raise ValueError("PCM data too large for Sun AU file")
    else:
        return build("4b 5*32u", False,
                     (".snd", 24,
                      (channels * (bits_per_sample // 8) * total_pcm_frames), {
                          8: 2,
                          16: 3,
                          24: 4
                      }[bits_per_sample], sample_rate, channels))
    def build(self, mp3_file):
        """given an MP3 file positioned at the file's end, generate a tag"""

        from audiotools.bitstream import build

        def encode_string(u, max_chars):
            s = u.encode("ascii", "replace")
            if len(s) >= max_chars:
                return s[0:max_chars]
            else:
                return s + b"\x00" * (max_chars - len(s))

        mp3_file.write(
            build("3b 30b 30b 30b 4b 28b 8p 8u 8u", False,
                  (b"TAG", encode_string(self.__track_name__, 30),
                   encode_string(self.__artist_name__,
                                 30), encode_string(self.__album_name__, 30),
                   encode_string(self.__year__, 4),
                   encode_string(self.__comment__,
                                 28), self.__track_number__, self.__genre__)))
示例#4
0
    def build(self, mp3_file):
        """given an MP3 file positioned at the file's end, generate a tag"""

        from audiotools.bitstream import build

        def encode_string(u, max_chars):
            s = u.encode("ascii", "replace")
            if len(s) >= max_chars:
                return s[0:max_chars]
            else:
                return s + b"\x00" * (max_chars - len(s))

        mp3_file.write(
            build("3b 30b 30b 30b 4b 28b 8p 8u 8u",
                  False,
                  (b"TAG",
                   encode_string(self.__track_name__, 30),
                   encode_string(self.__artist_name__, 30),
                   encode_string(self.__album_name__, 30),
                   encode_string(self.__year__, 4),
                   encode_string(self.__comment__, 28),
                   self.__track_number__,
                   self.__genre__)))