当前位置: 首页>>代码示例>>Python>>正文


Python audiotools.ChannelMask类代码示例

本文整理汇总了Python中audiotools.ChannelMask的典型用法代码示例。如果您正苦于以下问题:Python ChannelMask类的具体用法?Python ChannelMask怎么用?Python ChannelMask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ChannelMask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, aiff_file,
                 sample_rate, channels, channel_mask, bits_per_sample,
                 chunk_length, process=None):
        """aiff_file should be rewound to the start of the SSND chunk."""

        alignment = AiffAudio.SSND_ALIGN.parse_stream(aiff_file)
        PCMReader.__init__(self,
                           file=__capped_stream_reader__(
                aiff_file,
                chunk_length - AiffAudio.SSND_ALIGN.sizeof()),
                           sample_rate=sample_rate,
                           channels=channels,
                           channel_mask=channel_mask,
                           bits_per_sample=bits_per_sample,
                           process=process,
                           signed=True,
                           big_endian=True)
        self.ssnd_chunk_length = chunk_length - 8
        standard_channel_mask = ChannelMask(self.channel_mask)
        aiff_channel_mask = AIFFChannelMask(standard_channel_mask)
        if (channels in (3, 4, 6)):
            self.channel_order = [aiff_channel_mask.channels().index(channel)
                                  for channel in
                                  standard_channel_mask.channels()]
        else:
            self.channel_order = None
开发者ID:bspeice,项目名称:Melodia,代码行数:26,代码来源:__aiff__.py

示例2: __init__

    def __init__(self, aiff_file,
                 sample_rate, channels, channel_mask, bits_per_sample,
                 total_frames, process=None):
        """aiff_file should be a file-like object of aiff data

        sample_rate, channels, channel_mask and bits_per_sample are ints."""

        self.file = aiff_file
        self.sample_rate = sample_rate
        self.channels = channels
        self.channel_mask = channel_mask
        self.bits_per_sample = bits_per_sample
        self.remaining_frames = total_frames
        self.bytes_per_frame = self.channels * self.bits_per_sample / 8

        self.process = process

        from .bitstream import BitstreamReader

        #build a capped reader for the ssnd chunk
        aiff_reader = BitstreamReader(aiff_file, 0)
        try:
            (form, aiff) = aiff_reader.parse("4b 32p 4b")
            if (form != 'FORM'):
                raise InvalidAIFF(_(u"Not an AIFF file"))
            elif (aiff != 'AIFF'):
                raise InvalidAIFF(_(u"Invalid AIFF file"))

            while (True):
                (chunk_id, chunk_size) = aiff_reader.parse("4b 32u")
                if (chunk_id == 'SSND'):
                    #adjust for the SSND alignment
                    aiff_reader.skip(64)
                    break
                else:
                    aiff_reader.skip_bytes(chunk_size)
                    if (chunk_size % 2):
                        aiff_reader.skip(8)
        except IOError:
            self.read = self.read_error

        #handle AIFF unusual channel order
        standard_channel_mask = ChannelMask(self.channel_mask)
        aiff_channel_mask = AIFFChannelMask(standard_channel_mask)
        if (channels in (3, 4, 6)):
            self.channel_order = [aiff_channel_mask.channels().index(channel)
                                  for channel in
                                  standard_channel_mask.channels()]
        else:
            self.channel_order = None
开发者ID:bluemutedwisdom,项目名称:python-audio-tools,代码行数:50,代码来源:__aiff__.py

示例3: from_pcm

    def from_pcm(cls, filename, pcmreader,
                 compression=None, total_pcm_frames=None):
        """encodes a new file from PCM data

        takes a filename string, PCMReader object,
        optional compression level string and
        optional total_pcm_frames integer
        encodes a new audio file from pcmreader's data
        at the given filename with the specified compression level
        and returns a new MP2Audio object"""

        from audiotools import (PCMConverter,
                                BufferedPCMReader,
                                ChannelMask,
                                __default_quality__,
                                EncodingError)
        from audiotools.encoders import encode_mp2
        import bisect

        if (((compression is None) or
             (compression not in cls.COMPRESSION_MODES))):
            compression = __default_quality__(cls.NAME)

        if pcmreader.sample_rate in (32000, 48000, 44100):
            sample_rate = pcmreader.sample_rate
        else:
            sample_rate = [32000,
                           32000,
                           44100,
                           48000][bisect.bisect([32000,
                                                 44100,
                                                 48000],
                                                pcmreader.sample_rate)]

        if total_pcm_frames is not None:
            from audiotools import CounterPCMReader
            pcmreader = CounterPCMReader(pcmreader)

        try:
            encode_mp2(filename,
                       PCMConverter(pcmreader,
                                    sample_rate=sample_rate,
                                    channels=min(pcmreader.channels, 2),
                                    channel_mask=ChannelMask.from_channels(
                                        min(pcmreader.channels, 2)),
                                    bits_per_sample=16),
                       int(compression))

            if ((total_pcm_frames is not None) and
                (total_pcm_frames != pcmreader.frames_written)):
                from audiotools.text import ERR_TOTAL_PCM_FRAMES_MISMATCH
                cls.__unlink__(filename)
                raise EncodingError(ERR_TOTAL_PCM_FRAMES_MISMATCH)

            return MP2Audio(filename)
        except (ValueError, IOError) as err:
            cls.__unlink__(filename)
            raise EncodingError(str(err))
        finally:
            pcmreader.close()
开发者ID:brigittebigi,项目名称:sppas,代码行数:60,代码来源:mp3.py

示例4: channel_mask

    def channel_mask(self):
        """Returns a ChannelMask object of this track's channel layout."""

        if (self.channels() <= 2):
            return ChannelMask.from_channels(self.channels())
        else:
            return ChannelMask(0)
开发者ID:mr-robot,项目名称:python-audio-tools,代码行数:7,代码来源:__au__.py

示例5: channel_mask

    def channel_mask(self):
        from audiotools import ChannelMask

        """returns a ChannelMask object of this track's channel layout"""

        if self.channels() <= 2:
            return ChannelMask.from_channels(self.channels())
        else:
            return ChannelMask(0)
开发者ID:gmontcheuil,项目名称:sppas,代码行数:9,代码来源:au.py

示例6: __populate_metadata__

    def __populate_metadata__(self):
        #set up some default values
        self.__bits_per_sample__ = 16
        self.__channels__ = 2
        self.__channel_mask__ = 0x3
        self.__sample_rate__ = 44100
        self.__total_frames__ = 0
        self.__blocks__ = []
        self.__format__ = None

        #grab a few pieces of technical metadata from the Shorten file itself
        #which requires a dry-run through the decoder
        try:
            decoder = audiotools.decoders.SHNDecoder(self.filename)
            try:

                self.__bits_per_sample__ = decoder.bits_per_sample
                self.__channels__ = decoder.channels
                (self.__total_frames__,
                 self.__blocks__) = decoder.metadata()
            finally:
                decoder.close()

            try:
                self.__channel_mask__ = ChannelMask.from_channels(
                    self.__channels__)
            except ValueError:
                self.__channel_mask__ = 0
        except (ValueError, IOError):
            #if we hit an error in SHNDecoder while reading
            #technical metadata, the default values will have to do
            return

        #the remainder requires parsing the file's VERBATIM blocks
        #which may contain Wave, AIFF or Sun AU info
        if (self.__blocks__[0] is not None):
            header = cStringIO.StringIO(self.__blocks__[0])
            for format in WaveAudio, AiffAudio:
                header.seek(0, 0)
                if (format.is_type(header)):
                    self.__format__ = format
                    break
            if (self.__format__ is WaveAudio):
                for (chunk_id, chunk_data) in self.__wave_chunks__():
                    if (chunk_id == 'fmt '):
                        fmt_chunk = WaveAudio.FMT_CHUNK.parse(chunk_data)
                        self.__sample_rate__ = fmt_chunk.sample_rate
                        if (fmt_chunk.compression == 0xFFFE):
                            self.__channel_mask__ = \
                                WaveAudio.fmt_chunk_to_channel_mask(
                                fmt_chunk.channel_mask)
            elif (self.__format__ is AiffAudio):
                for (chunk_id, chunk_data) in self.__aiff_chunks__():
                    if (chunk_id == 'COMM'):
                        comm_chunk = AiffAudio.COMM_CHUNK.parse(chunk_data)
                        self.__sample_rate__ = comm_chunk.sample_rate
开发者ID:bspeice,项目名称:Melodia,代码行数:56,代码来源:__shn__.py

示例7: channel_mask

    def channel_mask(self):
        """Returns a ChannelMask object of this track's channel layout."""

        #this unusual arrangement is taken from the AIFF specification
        if (self.channels() <= 2):
            return ChannelMask.from_channels(self.channels())
        elif (self.channels() == 3):
            return ChannelMask.from_fields(
                front_left=True, front_right=True, front_center=True)
        elif (self.channels() == 4):
            return ChannelMask.from_fields(
                front_left=True, front_right=True,
                back_left=True, back_right=True)
        elif (self.channels() == 6):
            return ChannelMask.from_fields(
                front_left=True, side_left=True,
                front_center=True, front_right=True,
                side_right=True, back_center=True)
        else:
            return ChannelMask(0)
开发者ID:bspeice,项目名称:Melodia,代码行数:20,代码来源:__aiff__.py

示例8: channel_mask

    def channel_mask(self):
        """Returns a ChannelMask object of this track's channel layout."""

        # M4A seems to use the same channel assignment
        # as old-style RIFF WAVE/FLAC
        if self.channels() == 1:
            return ChannelMask.from_fields(front_center=True)
        elif self.channels() == 2:
            return ChannelMask.from_fields(front_left=True, front_right=True)
        elif self.channels() == 3:
            return ChannelMask.from_fields(front_left=True, front_right=True, front_center=True)
        elif self.channels() == 4:
            return ChannelMask.from_fields(front_left=True, front_right=True, back_left=True, back_right=True)
        elif self.channels() == 5:
            return ChannelMask.from_fields(
                front_left=True, front_right=True, front_center=True, back_left=True, back_right=True
            )
        elif self.channels() == 6:
            return ChannelMask.from_fields(
                front_left=True,
                front_right=True,
                front_center=True,
                back_left=True,
                back_right=True,
                low_frequency=True,
            )
        else:
            return ChannelMask(0)
开发者ID:mr-robot,项目名称:python-audio-tools,代码行数:28,代码来源:__m4a__.py

示例9: from_pcm

    def from_pcm(cls, filename, pcmreader, compression=None):
        """Encodes a new file from PCM data.

        Takes a filename string, PCMReader object
        and optional compression level string.
        Encodes a new audio file from pcmreader's data
        at the given filename with the specified compression level
        and returns a new SpeexAudio object."""

        import bisect

        if ((compression is None) or
            (compression not in cls.COMPRESSION_MODES)):
            compression = __default_quality__(cls.NAME)

        if ((pcmreader.bits_per_sample not in (8, 16)) or
            (pcmreader.channels > 2) or
            (pcmreader.sample_rate not in (8000, 16000, 32000, 44100))):
            pcmreader = PCMConverter(
                pcmreader,
                sample_rate=[8000, 8000, 16000, 32000, 44100][bisect.bisect(
                    [8000, 16000, 32000, 44100], pcmreader.sample_rate)],
                channels=min(pcmreader.channels, 2),
                channel_mask=ChannelMask.from_channels(
                    min(pcmreader.channels, 2)),
                bits_per_sample=min(pcmreader.bits_per_sample, 16))

        BITS_PER_SAMPLE = {8: ['--8bit'],
                           16: ['--16bit']}[pcmreader.bits_per_sample]

        CHANNELS = {1: [], 2: ['--stereo']}[pcmreader.channels]

        devnull = file(os.devnull, "ab")

        sub = subprocess.Popen([BIN['speexenc'],
                                '--quality', str(compression),
                                '--rate', str(pcmreader.sample_rate),
                                '--le'] + \
                               BITS_PER_SAMPLE + \
                               CHANNELS + \
                               ['-', filename],
                               stdin=subprocess.PIPE,
                               stderr=devnull,
                               preexec_fn=ignore_sigint)

        try:
            transfer_framelist_data(pcmreader, sub.stdin.write)
        except (IOError, ValueError), err:
            sub.stdin.close()
            sub.wait()
            cls.__unlink__(filename)
            raise EncodingError(str(err))
开发者ID:bspeice,项目名称:Melodia,代码行数:52,代码来源:__speex__.py

示例10: to_pcm

    def to_pcm(self):
        """Returns a PCMReader object containing the track's PCM data."""

        devnull = file(os.devnull, 'ab')
        sub = subprocess.Popen([BIN['speexdec'], self.filename, '-'],
                               stdout=subprocess.PIPE,
                               stderr=devnull)
        return PCMReader(
            sub.stdout,
            sample_rate=self.sample_rate(),
            channels=self.channels(),
            channel_mask=int(ChannelMask.from_channels(self.channels())),
            bits_per_sample=self.bits_per_sample(),
            process=sub)
开发者ID:bspeice,项目名称:Melodia,代码行数:14,代码来源:__speex__.py

示例11: channel_mask

    def channel_mask(self):
        """Returns a ChannelMask object of this track's channel layout."""

        if ((self.__channels__ == 1) or (self.__channels__ == 2)):
            return ChannelMask.from_channels(self.__channels__)
        else:
            for (block_id, nondecoder, data) in self.sub_frames():
                if ((block_id == 0xD) and not nondecoder):
                    mask = 0
                    for byte in reversed(map(ord, data[1:])):
                        mask = (mask << 8) | byte
                    return ChannelMask(mask)
            else:
                return ChannelMask(0)
开发者ID:bspeice,项目名称:Melodia,代码行数:14,代码来源:__wavpack__.py

示例12: channel_mask

    def channel_mask(self):
        """returns a ChannelMask object of this track's channel layout"""

        if self.channels() == 1:
            return ChannelMask.from_fields(front_center=True)
        elif self.channels() == 2:
            return ChannelMask.from_fields(front_left=True, front_right=True)
        elif self.channels() == 3:
            return ChannelMask.from_fields(front_left=True, front_right=True, front_center=True)
        elif self.channels() == 4:
            return ChannelMask.from_fields(front_left=True, front_right=True, back_left=True, back_right=True)
        elif self.channels() == 5:
            return ChannelMask.from_fields(
                front_left=True, front_right=True, front_center=True, back_left=True, back_right=True
            )
        elif self.channels() == 6:
            return ChannelMask.from_fields(
                front_left=True,
                front_right=True,
                front_center=True,
                back_left=True,
                back_right=True,
                low_frequency=True,
            )
        elif self.channels() == 7:
            return ChannelMask.from_fields(
                front_left=True,
                front_right=True,
                front_center=True,
                side_left=True,
                side_right=True,
                back_center=True,
                low_frequency=True,
            )
        elif self.channels() == 8:
            return ChannelMask.from_fields(
                front_left=True,
                front_right=True,
                side_left=True,
                side_right=True,
                back_left=True,
                back_right=True,
                front_center=True,
                low_frequency=True,
            )
        else:
            return ChannelMask(0)
开发者ID:atempcode1,项目名称:python-audio-tools,代码行数:47,代码来源:__vorbis__.py

示例13: to_pcm

    def to_pcm(self):
        """returns a PCMReader object containing the track's PCM data"""

        BIG_ENDIAN = sys.byteorder == 'big'

        sub = subprocess.Popen([BIN["mpg123"], "-qs", self.filename],
                               stdout=subprocess.PIPE,
                               stderr=file(os.devnull, "a"))

        return PCMReader(sub.stdout,
                         sample_rate=self.sample_rate(),
                         channels=self.channels(),
                         bits_per_sample=16,
                         channel_mask=int(ChannelMask.from_channels(
                    self.channels())),
                         process=sub,
                         big_endian=BIG_ENDIAN)
开发者ID:XiaonuoGantan,项目名称:python-audio-tools,代码行数:17,代码来源:__mp3__.py

示例14: channel_mask

    def channel_mask(self):
        """Returns a ChannelMask object of this track's channel layout."""

        if (self.channels() == 1):
            return ChannelMask.from_fields(
                front_center=True)
        elif (self.channels() == 2):
            return ChannelMask.from_fields(
                front_left=True, front_right=True)
        elif (self.channels() == 3):
            return ChannelMask.from_fields(
                front_left=True, front_right=True,
                front_center=True)
        elif (self.channels() == 4):
            return ChannelMask.from_fields(
                front_left=True, front_right=True,
                back_left=True, back_right=True)
        elif (self.channels() == 5):
            return ChannelMask.from_fields(
                front_left=True, front_right=True,
                front_center=True,
                back_left=True, back_right=True)
        elif (self.channels() == 6):
            return ChannelMask.from_fields(
                front_left=True, front_right=True,
                front_center=True,
                back_left=True, back_right=True,
                low_frequency=True)
        elif (self.channels() == 7):
            return ChannelMask.from_fields(
                front_left=True, front_right=True,
                front_center=True,
                side_left=True, side_right=True,
                back_center=True, low_frequency=True)
        elif (self.channels() == 8):
            return ChannelMask.from_fields(
                front_left=True, front_right=True,
                side_left=True, side_right=True,
                back_left=True, back_right=True,
                front_center=True, low_frequency=True)
        else:
            return ChannelMask(0)
开发者ID:bspeice,项目名称:Melodia,代码行数:42,代码来源:__vorbis__.py

示例15: parse_comm

def parse_comm(comm):
    """given a COMM chunk (without the 8 byte name/size header)
    returns (channels, total_sample_frames, bits_per_sample,
             sample_rate, channel_mask)
    where channel_mask is a ChannelMask object and the rest are ints
    may raise IOError if an error occurs reading the chunk"""

    (channels,
     total_sample_frames,
     bits_per_sample) = comm.parse("16u 32u 16u")
    sample_rate = int(parse_ieee_extended(comm))

    if (channels <= 2):
        channel_mask = ChannelMask.from_channels(channels)
    else:
        channel_mask = ChannelMask(0)

    return (channels, total_sample_frames, bits_per_sample,
            sample_rate, channel_mask)
开发者ID:XiaonuoGantan,项目名称:python-audio-tools,代码行数:19,代码来源:__aiff__.py


注:本文中的audiotools.ChannelMask类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。