I have a task whose job it is to read input from a gpio. Then I have a second task whose job it is to play audio. I want the 'gpio task's' work to affect that of the playback task: so when, say, a user moves a slider, they hear audio playback in response. The gpio task affects the audio play back in realtime (lets say it adjusts pitch of the audio).
What I'm having trouble picturing is how to manage the timing between these two things. Some timing facts I know:
- The GPIO task runs at 100hz - so I have new data from it every 10 ms.
- The i2s channel is configured to run at 44.1 KHz
I think what I want to do is:
- Measure my GPIO
- Indicate this measurement somewhere (queue? What other mechanisms should I consider for this?)
- When the audio task sees that new information is available, it grabs it, processes it, then sends out an audio buffer over i2s. This audio buffer should last juuuuust long enough so that it's finishing up right as a new GPIO value comes available. <---this is the part I don't understand how to manage.
- When the audio task is near the end of its playback, it indicates its ready for new GPIO data?
I'm curious if anyone could give me any pointers? I'm happy to do more learning, just not sure what direction to look in.