Example #1
0
def genFlashSequence(flashCentreTimesSecs, idealFlashDurationSecs, sequenceDurationSecs, frameRate, gapValue=(0,0,0), flashValue=(1.0,1.0,1.0)):
    """\
    Generates the pixel colour values needed for each frame to render flashes corresponding to the timings specified.
    
    :param beepCentreTimeSecs: A list or iterable of the centre times of each beep (in seconds since the beginning of the sequence)
    :param idealFlashDurationSecs: ideal duration of a flash in seconds
    :param sequenceDurationSecs: total sequence duration in seconds
    :param sampleRateHz: The final output sample rate in Hz
    :param gapValue: The value for non flash pixels
    :param flashValue: The value for flash pixels
    
    :returns: An iterable that generates the pixel colours for each frame starting with the first frame
    """
    flashDurationSamples = calcNearestDurationForExactNumberOfCycles(idealFlashDurationSecs, frameRate)
    
    flashStartEndSamples = genSequenceStartEnds(flashCentreTimesSecs, flashDurationSamples, 1.0, frameRate)

    nSamples = sequenceDurationSecs * frameRate
    
    def gapGen():
        while True:
            yield gapValue
        
    def flashGen():
        while True:
            yield flashValue

    seqIter = genSequenceFromSampleIndices(flashStartEndSamples, gapGen, flashGen)
    
    return itertools.islice(seqIter, 0, nSamples)
Example #2
0
def genBeepSequence(beepCentreTimesSecs, idealBeepDurationSecs, sequenceDurationSecs, sampleRateHz, toneHz, amplitude):
    """\
    Generates the audio sample values needed to create audio data containing beeps corresponding to the timings specified.
    
    :param beepCentreTimeSecs: A list or iterable of the centre times of each beep (in seconds since the beginning of the sequence)
    :param idealBeepDurationSecs: ideal duration of a beep in seconds
    :param sequenceDurationSecs: total sequence duration in seconds
    :param sampleRateHz: The final output sample rate in Hz
    :param toneHz: The tone frequence in Hz for the beeps
    :param amplitude: The peak amplitude for the beeps
    
    :returns: An iterable that generates the sample values starting with the first sample value
    """
    beepDurationSamples = calcNearestDurationForExactNumberOfCycles(idealBeepDurationSecs, toneHz)
    
    beepStartEndSamples = genSequenceStartEnds(beepCentreTimesSecs, beepDurationSamples, 1.0, sampleRateHz)

    nSamples = sequenceDurationSecs * sampleRateHz

    def toneGenFactory():
        return GenTone(sampleRateHz, amplitude, toneHz, 0.0)
        
    def silenceGen():
        while True:
            yield 0.0
        
    seqIter = genSequenceFromSampleIndices(beepStartEndSamples, silenceGen, toneGenFactory)
    
    return itertools.islice(seqIter, 0, nSamples)
Example #3
0
def genBeepSequence(beepCentreTimesSecs, idealBeepDurationSecs,
                    sequenceDurationSecs, sampleRateHz, toneHz, amplitude):
    """\
    Generates the audio sample values needed to create audio data containing beeps corresponding to the timings specified.
    
    :param beepCentreTimeSecs: A list or iterable of the centre times of each beep (in seconds since the beginning of the sequence)
    :param idealBeepDurationSecs: ideal duration of a beep in seconds
    :param sequenceDurationSecs: total sequence duration in seconds
    :param sampleRateHz: The final output sample rate in Hz
    :param toneHz: The tone frequence in Hz for the beeps
    :param amplitude: The peak amplitude for the beeps
    
    :returns: An iterable that generates the sample values starting with the first sample value
    """
    beepDurationSamples = calcNearestDurationForExactNumberOfCycles(
        idealBeepDurationSecs, toneHz)

    beepStartEndSamples = genSequenceStartEnds(beepCentreTimesSecs,
                                               beepDurationSamples, 1.0,
                                               sampleRateHz)

    nSamples = sequenceDurationSecs * sampleRateHz

    def toneGenFactory():
        return GenTone(sampleRateHz, amplitude, toneHz, 0.0)

    def silenceGen():
        while True:
            yield 0.0

    seqIter = genSequenceFromSampleIndices(beepStartEndSamples, silenceGen,
                                           toneGenFactory)

    return itertools.islice(seqIter, 0, nSamples)
Example #4
0
def genFlashSequence(flashCentreTimesSecs,
                     idealFlashDurationSecs,
                     sequenceDurationSecs,
                     frameRate,
                     gapValue=(0, 0, 0),
                     flashValue=(1.0, 1.0, 1.0)):
    """\
    Generates the pixel colour values needed for each frame to render flashes corresponding to the timings specified.

    :param beepCentreTimeSecs: A list or iterable of the centre times of each beep (in seconds since the beginning of the sequence)
    :param idealFlashDurationSecs: ideal duration of a flash in seconds
    :param sequenceDurationSecs: total sequence duration in seconds
    :param sampleRateHz: The final output sample rate in Hz
    :param gapValue: The value for non flash pixels
    :param flashValue: The value for flash pixels

    :returns: An iterable that generates the pixel colours for each frame starting with the first frame
    """
    flashDurationSamples = calcNearestDurationForExactNumberOfCycles(
        idealFlashDurationSecs, frameRate)

    flashStartEndSamples = genSequenceStartEnds(flashCentreTimesSecs,
                                                flashDurationSamples, 1.0,
                                                frameRate)

    nSamples = sequenceDurationSecs * frameRate

    def gapGen():
        while True:
            yield gapValue

    def flashGen():
        while True:
            yield flashValue

    seqIter = genSequenceFromSampleIndices(flashStartEndSamples, gapGen,
                                           flashGen)

    return itertools.islice(seqIter, 0, nSamples)
Example #5
0
 def test_simple(self):
 
     self.assertEquals(1,       calcNearestDurationForExactNumberOfCycles(1.0,     500))
     self.assertEquals(2.0/3.0, calcNearestDurationForExactNumberOfCycles(0.5,       3))
     self.assertEquals(0.0335,  calcNearestDurationForExactNumberOfCycles(1.0/30, 2000))