So I am trying to make a drum machine with gstreamer. For those who are not familiar with a drum machine have a look at:
https://www.youtube.com/watch?v=KC7UaUD5rEA
Basically you have a specific sample loaded to a track. Each track has 16 steps which you can enable or disable. When you press play the drum machine will loop over the steps and when a step is enabled it will play that sound.
I got it working with the current setup: 8 x (filesrc | wavparse | audioconvert | volume) | audiomixer | alsasink
I put the pipeline in play state and each step I perform a seek_simple back to the start of the pipeline. To trigger the sound I mute and demute the wav each step according to the wanted rhythm/pattern.
The issue: By performing the seek back to the start the tail of the wav sample/sound is cut off and this makes a choppy sound. Ideally I'd like to re-trigger a wav sample but the previous one should continue to play until done.
The question: How can I re trigger a sound without cutting of it's tail?
Ps: I've tried to play with the seek flags "flush", "keep_unit", ... but without success.
My loop:
def run(self):
startTime = time.time()
while True:
if self.running:
self.player.set_state(Gst.State.NULL)
self.player.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, 0)
for track in self.tracks:
track.step()
self.player.set_state(Gst.State.PLAYING)
time.sleep(self.delayBmp -
((time.time() - startTime) % self.delayBmp))
Thanks in advance
I managed to achieve my goal by using this C library: https://soundprogramming.net/programming/tutorial-using-sdl2-and-sdl_mixer-to-play-samples/
This example gives a way to play multiple sound simultaneously. I then made a python wrapper around it and push a wav file to it. Follow this tutorial:
https://docs.python.org/3/extending/index.html
Feel free to post the gstreamer solution.
thx