def __init__(self, pcm_frames, sample_rate):
     SameSample.__init__(self,
                         sample=0,
                         total_pcm_frames=pcm_frames,
                         sample_rate=sample_rate,
                         channels=2,
                         channel_mask=0x3,
                         bits_per_sample=24)
     self.pcm_frames = pcm_frames
     self.md5 = md5()
 def __init__(self, pcm_frames, sample_rate):
     SameSample.__init__(self,
                         sample=0,
                         total_pcm_frames=pcm_frames,
                         sample_rate=sample_rate,
                         channels=2,
                         channel_mask=0x3,
                         bits_per_sample=24)
     self.pcm_frames = pcm_frames
     self.md5 = md5()
Esempio n. 3
0
def BLANK_PCM_Reader(length,
                     sample_rate=44100,
                     channels=2,
                     bits_per_sample=16,
                     channel_mask=None):
    from audiotools.decoders import SameSample

    if channel_mask is None:
        channel_mask = int(audiotools.ChannelMask.from_channels(channels))

    return SameSample(sample=1,
                      total_pcm_frames=length * sample_rate,
                      sample_rate=sample_rate,
                      channels=channels,
                      channel_mask=channel_mask,
                      bits_per_sample=bits_per_sample)
Esempio n. 4
0
def EXACT_SILENCE_PCM_Reader(pcm_frames,
                             sample_rate=44100,
                             channels=2,
                             bits_per_sample=16,
                             channel_mask=None):
    from audiotools.decoders import SameSample

    if channel_mask is None:
        channel_mask = int(audiotools.ChannelMask.from_channels(channels))

    return SameSample(sample=0,
                      total_pcm_frames=pcm_frames,
                      sample_rate=sample_rate,
                      channels=channels,
                      channel_mask=channel_mask,
                      bits_per_sample=bits_per_sample)
 def reset(self):
     SameSample.reset(self)
     self.md5 = md5()
 def read(self, pcm_frames):
     framelist = SameSample.read(self, pcm_frames)
     self.md5.update(framelist.to_bytes(False, True))
     return framelist
 def reset(self):
     SameSample.reset(self)
     self.md5 = md5()
 def read(self, pcm_frames):
     framelist = SameSample.read(self, pcm_frames)
     self.md5.update(framelist.to_bytes(False, True))
     return framelist
Esempio n. 9
0
def accuraterip_checksum(progress, track, previous_track, next_track,
                         ar_matches):
    from audiotools import (transfer_data, PCMCat, PCMReaderHead,
                            PCMReaderDeHead, PCMReaderProgress)
    from audiotools.decoders import SameSample
    from audiotools.accuraterip import Checksum, match_offset

    # unify previous track, current track and next track into a single stream

    pcmreaders = []
    if previous_track is not None:
        frames_to_skip = previous_track.total_frames() - PREVIOUS_TRACK_FRAMES
        prev_pcmreader = previous_track.to_pcm()
        if hasattr(prev_pcmreader, "seek") and callable(prev_pcmreader.seek):
            frames_to_skip -= prev_pcmreader.seek(frames_to_skip)
        pcmreaders.append(PCMReaderDeHead(prev_pcmreader, frames_to_skip))
    else:
        pcmreaders.append(
            SameSample(sample=0,
                       total_pcm_frames=PREVIOUS_TRACK_FRAMES,
                       sample_rate=track.sample_rate(),
                       channels=track.channels(),
                       channel_mask=int(track.channel_mask()),
                       bits_per_sample=track.bits_per_sample()))

    pcmreaders.append(track.to_pcm())

    if next_track is not None:
        pcmreaders.append(PCMReaderHead(next_track.to_pcm(),
                                        NEXT_TRACK_FRAMES))
    else:
        pcmreaders.append(
            SameSample(sample=0,
                       total_pcm_frames=NEXT_TRACK_FRAMES,
                       sample_rate=track.sample_rate(),
                       channels=track.channels(),
                       channel_mask=int(track.channel_mask()),
                       bits_per_sample=track.bits_per_sample()))

    # feed stream to checksummer
    checksummer = Checksum(total_pcm_frames=track.total_frames(),
                           sample_rate=track.sample_rate(),
                           is_first=(previous_track is None),
                           is_last=(next_track is None),
                           pcm_frame_range=PREVIOUS_TRACK_FRAMES + 1 +
                           NEXT_TRACK_FRAMES,
                           accurateripv2_offset=PREVIOUS_TRACK_FRAMES)

    try:
        pcmreader = PCMReaderProgress(
            PCMCat(pcmreaders),
            PREVIOUS_TRACK_FRAMES + track.total_frames() + NEXT_TRACK_FRAMES,
            progress)
        audiotools.transfer_data(pcmreader.read, checksummer.update)
    except (IOError, ValueError) as err:
        return {
            "filename": audiotools.Filename(track.filename).__unicode__(),
            "error": str(err),
            "v1": {
                "checksum": None,
                "offset": None,
                "confidence": None
            },
            "v2": {
                "checksum": None,
                "offset": None,
                "confidence": None
            }
        }

    # determine checksum, confidence and offset from
    # the calculated checksums and possible AccurateRip matches
    (checksum_v2, confidence_v2,
     offset_v2) = match_offset(ar_matches,
                               checksums=[checksummer.checksum_v2()],
                               initial_offset=0)

    (checksum_v1, confidence_v1,
     offset_v1) = match_offset(ar_matches=ar_matches,
                               checksums=checksummer.checksums_v1(),
                               initial_offset=-PREVIOUS_TRACK_FRAMES)

    if len(ar_matches) == 0:
        return {
            "filename": audiotools.Filename(track.filename).__unicode__(),
            "error": None,
            "v1": {
                "checksum": checksum_v1,
                "offset": offset_v1,
                "confidence": AR_NOT_FOUND
            },
            "v2": {
                "checksum": checksum_v2,
                "offset": offset_v2,
                "confidence": AR_NOT_FOUND
            }
        }
    else:
        return {
            "filename": audiotools.Filename(track.filename).__unicode__(),
            "error": None,
            "v1": {
                "checksum":
                checksum_v1,
                "offset":
                offset_v1,
                "confidence": (confidence_v1 if
                               (confidence_v1 is not None) else AR_MISMATCH)
            },
            "v2": {
                "checksum":
                checksum_v2,
                "offset":
                offset_v2,
                "confidence": (confidence_v2 if
                               (confidence_v2 is not None) else AR_MISMATCH)
            }
        }