Ejemplo n.º 1
0
    def from_wave(cls, filename, wave_filename, compression=None,
                  block_size=256):
        """Encodes a new AudioFile from an existing .wav file.

        Takes a filename string, wave_filename string
        of an existing WaveAudio file
        and an optional compression level string.
        Encodes a new audio file from the wave's data
        at the given filename with the specified compression level
        and returns a new ShortenAudio object."""

        wave = WaveAudio(wave_filename)

        if (wave.bits_per_sample() not in (8, 16)):
            raise UnsupportedBitsPerSample()

        (head, tail) = wave.pcm_split()
        if (len(tail) > 0):
            blocks = [head, None, tail]
        else:
            blocks = [head, None]

        import audiotools.encoders

        try:
            audiotools.encoders.encode_shn(filename=filename,
                                           pcmreader=wave.to_pcm(),
                                           block_size=block_size,
                                           verbatim_chunks=blocks)

            return cls(filename)
        except IOError, err:
            cls.__unlink__(filename)
            raise EncodingError(str(err))
Ejemplo n.º 2
0
    def from_wave(cls, filename, wave_filename, compression=None, block_size=256, progress=None):
        """encodes a new AudioFile from an existing .wav file

        takes a filename string, wave_filename string
        of an existing WaveAudio file
        and an optional compression level string
        encodes a new audio file from the wave's data
        at the given filename with the specified compression level
        and returns a new ShortenAudio object"""

        wave = WaveAudio(wave_filename)

        if wave.bits_per_sample() not in (8, 16):
            raise UnsupportedBitsPerSample(filename, wave.bits_per_sample())

        (head, tail) = wave.pcm_split()

        from .encoders import encode_shn

        try:
            if len(tail) == 0:
                encode_shn(
                    filename=filename,
                    pcmreader=to_pcm_progress(wave, progress),
                    is_big_endian=False,
                    signed_samples=wave.bits_per_sample() == 16,
                    header_data=head,
                    block_size=block_size,
                )
            else:
                encode_shn(
                    filename=filename,
                    pcmreader=to_pcm_progress(wave, progress),
                    is_big_endian=False,
                    signed_samples=wave.bits_per_sample() == 16,
                    header_data=head,
                    footer_data=tail,
                    block_size=block_size,
                )

            return cls(filename)
        except IOError, err:
            cls.__unlink__(filename)
            raise EncodingError(str(err))
Ejemplo n.º 3
0
    def from_wave(cls, filename, wave_filename, compression=None):
        wave = WaveAudio(wave_filename)

        if (wave.bits_per_sample() not in (8,16)):
            raise UnsupportedBitsPerSample()

        (head,tail) = wave.pcm_split()
        if (len(tail) > 0):
            blocks = [head,None,tail]
        else:
            blocks = [head,None]

        import audiotools.encoders

        try:
            audiotools.encoders.encode_shn(filename=filename,
                                           pcmreader=wave.to_pcm(),
                                           block_size=256,
                                           verbatim_chunks=blocks)

            return cls(filename)
        except IOError:
            raise EncodingError("shn")
Ejemplo n.º 4
0
    def from_wave(cls, filename, wave_filename, compression=None,
                  block_size=256, progress=None):
        """Encodes a new AudioFile from an existing .wav file.

        Takes a filename string, wave_filename string
        of an existing WaveAudio file
        and an optional compression level string.
        Encodes a new audio file from the wave's data
        at the given filename with the specified compression level
        and returns a new ShortenAudio object."""

        wave = WaveAudio(wave_filename)

        if (wave.bits_per_sample() not in (8, 16)):
            raise UnsupportedBitsPerSample(filename, wave.bits_per_sample())

        (head, tail) = wave.pcm_split()
        if (len(tail) > 0):
            blocks = [head, None, tail]
        else:
            blocks = [head, None]

        import audiotools.encoders

        try:
            audiotools.encoders.encode_shn(
                filename=filename,
                pcmreader=to_pcm_progress(wave, progress),
                block_size=block_size,
                file_type={8: 2,
                           16: 5}[wave.bits_per_sample()],
                verbatim_chunks=blocks)

            return cls(filename)
        except IOError, err:
            cls.__unlink__(filename)
            raise EncodingError(str(err))