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)
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)
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)
def test_genSequenceFromSampleIndices(self): startEndTimings = [ (10,15), (20,22) ] def gapGenFactory(): while True: yield 0 def eventGenFactory(): return [1,2,3,4,5,6,7,8,9,10,11,12] gs=genSequenceFromSampleIndices(startEndTimings, gapGenFactory, eventGenFactory) data=list(itertools.islice(gs, 0, 30)) self.assertEquals(data, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 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)