def worker(gens, tick):
        while time.time() < started + (60 * 15):
            dsp.delay(dsp.stf(dsp.rand(2, 20)))

            if dsp.rand(0, 100) > 50:
                if dsp.rand(0, 100) > 80:
                    voice_id, generator_name = settings.add_voice("pp re qu")
                    dsp.log("")
                    dsp.log("starting pulsar voice %s" % voice_id)
                elif dsp.rand(0, 100) > 50:
                    voice_id, generator_name = settings.add_voice("ch re qu")
                    dsp.log("")
                    dsp.log("starting chirp voice %s" % voice_id)
                else:
                    voice_id, generator_name = settings.add_voice("bo re qu")
                    dsp.log("")
                    dsp.log("starting boone voice %s" % voice_id)

                playback_process = mp.Process(name=voice_id, target=rt.out, args=(gens[generator_name], tick))
                playback_process.start()

                dsp.delay(dsp.stf(dsp.rand(6, 35)))

                dsp.log("")
                dsp.log("stopping voice %s" % voice_id)
                settings.voice(voice_id, "loop", 0)
Exemple #2
0
def render(play, voice_id, once, uno, bufs):
    os.nice(10)
    current = mp.current_process()

    out = play(voice_id)

    if once == True:
        settings.voice(voice_id, 'once', False)

    settings.buf(voice_id, value=out, bufs=bufs)
Exemple #3
0
    def worker(gens, tick):
        while time.time() < started + (60 * 9):
            dsp.delay(dsp.stf(dsp.rand(2, 20)))

            if dsp.rand(0, 100) > 60:
                if dsp.rand(0, 100) > 60:
                    voice_id, generator_name = settings.add_voice('sh re qu')
                    dsp.log('')
                    dsp.log('starting shimmer voice %s' % voice_id)
                else:
                    voice_id, generator_name = settings.add_voice('dr re qu')
                    dsp.log('')
                    dsp.log('starting drone voice %s' % voice_id)


                playback_process = mp.Process(name=voice_id, target=rt.out, args=(gens[generator_name], tick))
                playback_process.start()

                dsp.delay(dsp.stf(dsp.rand(6, 35)))

                dsp.log('')
                dsp.log('stopping voice %s' % voice_id)
                settings.voice(voice_id, 'loop', 0)
Exemple #4
0
def out(generator, tick, bufs):
    """ Master playback process spawned by play()
        Manages render and playback processes  

        Params are collapsed to a key-value dict,
        where the value is translated to the target 
        data type, and the key is expanded to the param
        full name.
        """

    voice_id = str(mp.current_process().name)

    # Spawn a render process which will write generator output
    # into the buf for this voice
    r = mp.Process(name='r' + str(voice_id), target=render, args=(generator.play, voice_id, False, False, bufs))
    r.start()
    r.join()

    def openpcm(device):
        try:
            out = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NORMAL, device)
        except:
            print 'Could not open an ALSA connection.'
            return False

        out.setchannels(2)
        out.setrate(44100)
        out.setformat(alsaaudio.PCM_FORMAT_S16_LE)
        out.setperiodsize(10)

        return out

    # Open a connection to an ALSA PCM device
    device = getattr(generator, 'device', 'default')
    out = openpcm(device)

    # On start of playback, check to see if we should be regenerating 
    # the sound. If so, spawn a new render thread.
    # If there is a fresher render available, use that instead.
    cooking             = False # Flag set to true if a render subprocess has been spawned
    volume              = 1.0
    next                = False

    buf = settings.buf(voice_id, bufs=bufs)
    while settings.voice(voice_id, 'loop') == True:
        regenerate    = settings.voice(voice_id, 'regenerate')
        once          = settings.voice(voice_id, 'once')
        uno           = settings.voice(voice_id, 'uno')
        quantize      = settings.voice(voice_id, 'quantize')
        target_volume = settings.voice(voice_id, 'target_volume')

        if uno == True:
            settings.voice(voice_id, 'loop', False)

        if regenerate == True or once == True:
            reload(generator)
            device = getattr(generator, 'device', 'default')
            out = openpcm(device)

            r = mp.Process(name='r' + str(voice_id), target=render, args=(generator.play, voice_id, False, False, bufs))
            try:
                r.start()
                r.join()
                buf = settings.buf(voice_id, bufs=bufs)
            except OSError:
                dsp.log('failed to regenerate voice %s' % voice_id)

        if quantize != False:
            tick.wait()

        dsp_loop(out, buf, voice_id)

    settings.remove_voice(voice_id)
Exemple #5
0
def dsp_loop(out, buf, voice_id):
    os.nice(0)

    plays = int(settings.voice(voice_id, 'plays')) + 1
    settings.voice(voice_id, 'plays', plays)

    target_volume = settings.voice(voice_id, 'target_volume')
    post_volume   = settings.voice(voice_id, 'post_volume')

    buf = dsp.split(buf, 500)

    for chunk in buf:
        if target_volume != post_volume:
            if target_volume > post_volume:
                post_volume += 0.01
            elif post_volume > target_volume:
                post_volume -= 0.01

            chunk = dsp.amp(chunk, post_volume)

        out.write(chunk)

        if post_volume < 0.002:
            settings.voice(voice_id, 'loop', False)
            settings.voice(voice_id, 'post_volume', post_volume)
            break

    settings.voice(voice_id, 'post_volume', post_volume)