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_genSequenceStartEnds(self): centreTimes = [ 1.0, 2.0, 5.0 ] unitsPerSecond = 1.0 beepDuration = 0.2 sampleRate = 1000 expectedTimings = [ (900, 1100), (1900, 2100), (4900, 5100) ] timings = genSequenceStartEnds(centreTimes, beepDuration, unitsPerSecond, sampleRate) timings = list(timings) self.assertEquals(timings, expectedTimings)
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)