Skip to content

Less jitter with spin_sleep() #7

@ghost

Description

For anyone who is interested. I built sequencer based on aiotone that is sync-master and drives my DAW. I had quite some jitter compared to other midi-sequencers. Using spin_sleep() in the main loop, there is much less jitter. Of course there is a tradeoff: higher CPU load.

sleep_resolution is platform dependent. On linux 0.001s should be a good value. I am not aware of a good way to detect sleep_resolution.

import asyncio
from time import time

sleep_resolution = 0.001


async def spin_sleep(sleep_time):
    deadline = sleep_time + time()
    await asyncio.sleep(sleep_time - sleep_resolution)
    while deadline > time():
        await asyncio.sleep(0)

Currently my code isn't in a state for sharing, but I will put it on github soonish.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions