Exemplo n.º 1
0
    def __truediv__(self, other) -> Tuple['AudioSequence', 'AudioSequence']:
        if other != 2:
            raise ValueError("Can only split audio sequence in two tracks!")

        left, right = StereoDemuxer()(self.audio)
        if not list(right):
            right = left.copy()
        return self.new(left), self.new(right)
Exemplo n.º 2
0
    def testRegression(self):
        size = 10
        input = array([[size-i, i] for i in range(size)])
        left, right = StereoDemuxer()(input)

        self.assertEqualVector(left, [size-i for i in range(size)])
        self.assertEqualVector(right , [i for i in range(size)])
Exemplo n.º 3
0
def essFalsestereoDetector(x: list,
                           frameSize=1024,
                           hopSize=512,
                           correlationThreshold=0.98,
                           percentageThreshold=90,
                           channels=2,
                           **kwargs):
    """Computes the correlation and consideres if the information in the two channels is the same

    Args:
        x: (list) input signal
        frameSize: (int) frame size for the analysis in falseStereoDetector
        hopSize: (int) hop_size for the analysis in falseStereoDetector
        correlationthreshold: (float) lower limit to decide if a file has correlation problems

    Returns:
        final_bool: (bool) True if the information is the same in both channels, False otherwise
        percentace: (float) How many frames were false stereo over all the frames
    """
    if channels < 2:
        return 1, False, True

    rx, lx = StereoDemuxer()(x)
    mux = StereoMuxer()
    falseStereoDetector = FalseStereoDetector(
        correlationThreshold=correlationThreshold, **kwargs)

    lfg = FrameGenerator(lx,
                         frameSize=frameSize,
                         hopSize=hopSize,
                         startFromZero=True)
    rfg = FrameGenerator(rx,
                         frameSize=frameSize,
                         hopSize=hopSize,
                         startFromZero=True)

    problematicFrames = sum([
        falseStereoDetector(mux(frameL, frameR))[0]
        for frameL, frameR in zip(lfg, rfg)
    ])
    # problematicFrames = []
    # for frameL, frameR in zip(lfg, rfg):
    #     res, corr = falseStereoDetector(mux(frameL, frameR))
    #     problematicFrames.append(res)

    falseStereoDetector.reset()

    conf = float(sum(problematicFrames)) / float(lfg.num_frames())

    return conf, conf > percentageThreshold / 100, False
Exemplo n.º 4
0
def outofPhaseDetector(x: list,
                       frameSize=1024,
                       hopSize=512,
                       correlationThreshold=-0.8,
                       percentageThreshold=90,
                       channels=2,
                       **kwargs):
    """Computes the correlation and flags the file if the file has a 90% of frames out of phase

    Args:
        x: (list) input signal
        frameSize: (int) frame size for the analysis in falseStereoDetector
        hopSize: (int) hop_size for the analysis in falseStereoDetector
        correlationthreshold: (float) higher limit to decide if a file has correlation problems

    Returns:
        final_bool: (bool) True if the information is the same in both channels, False otherwise
        percentace: (float) How many frames were false stereo over all the frames
    """
    if channels < 2:
        return 1, False, True

    rx, lx = StereoDemuxer()(x)
    mux = StereoMuxer()
    falseStereoDetector = FalseStereoDetector(**kwargs)

    lfg = FrameGenerator(lx,
                         frameSize=frameSize,
                         hopSize=hopSize,
                         startFromZero=True)
    rfg = FrameGenerator(rx,
                         frameSize=frameSize,
                         hopSize=hopSize,
                         startFromZero=True)

    problematicFrames = 0
    for frameL, frameR in zip(lfg, rfg):
        _, corr = falseStereoDetector(mux(frameL, frameR))
        problematicFrames += corr < correlationThreshold
    falseStereoDetector.reset()

    conf = problematicFrames / lfg.num_frames()

    return conf, conf > percentageThreshold / 100, False
Exemplo n.º 5
0
 def testEmpty(self):
     filename = join(testdata.audio_dir, 'generated', 'empty', 'empty.aiff')
     audio, _, _, _, _, _ = AudioLoader(filename=filename)()
     left, right = StereoDemuxer()(audio)
     self.assertEqualVector(left , [])
     self.assertEqualVector(right , [])
Exemplo n.º 6
0
 def to_stereo(audio: np.array) -> tuple:
     left, right = StereoDemuxer()(audio)
     if not [r for r in right if r != 0]:
         right = left.copy()
     return left, right