Hi, I’ve been playing around with the daisy seed and built it into a hothouse enclosure. I’m wanting to make a sample player that would play a sample when I hit a note on guitar. For example I play a note and it takes the guitar input and plays a sample of a dog barking or something. I have a lot of coding experience, so I’m not worried about that part, but I have no digital signal processing experience, so I’m not sure where to even begin on coding this. I’ve played around with the examples, but none of them are close to what I’m wanting. If someone could give me a simple outline of the steps I should follow, or a similar example that I could follow that would be great. Thanks
I only skimmed the examples but the seed/WavPlayer seems like a good start for the sample playing part. You need to analyze the incoming audio from the guitar to detect if you are strumming and from there trigger the sample player.
I’m sure there is quite a bit more to it
.
Thinking a bit more on this.
What the WavPlayer simplifies seems to be getting hold of samples from an sdcard.
Another, simpler, solution is if you put your sample in a c-array and keep track of the current playback point in that array. In which case the sample player isn’t needed.
E.g:
- put a sample in a c-array
- make an algorithm for detecting if you are strumming.
- run the algorithm on in the incoming audio in the callback
- if noise is detected start sending the sample on the outgoing audio in the callback, sample for sample.
A simple algorithm for strum-detection. Collect a number of samples (maybe 100), add their ABS values together, if the result is above a threshold (trial and error to find a good threshold value) a strum has occurred.
Awesome thanks for your help and breaking down some of the steps to follow. That definitely makes it seem more manageable and gives me a place to start. When you say put the sample in a c-array are you talking about an actual array data structure from the C/C++ language? Or something else?
Yes a c/c++ array with float vales. I’m not 100% sure but I think the input and output arguments for the callback want floats with range -1.0 to +1.0. So the samples in the array should be in that range.
Also, remember that the callback is a callback ;). Meaning that it will be triggered from the hardware each time a new buffer is filled with input samples. I think the examples in the DaisyExamples git use buffers with 4 samples. So when sending you need to send the samples one buffer at a time and keep track between calls which samples to send next.
Hope that makes sense. There’s a lot of learning to do in trying the examples.
There are three reasons you may want to take a look a my hobby project Molysynth.
Firstly, you can develop it off-line dead simple.
Secondly, it is a monophonic pitch tracker that can tell you when to bark and also the pitch. Play the bark faster for higher pitch, haha. The synth is clearly separated so you can replace it with barking.
Thirdly, it demonstrates how to use C only. Feedback welcome, even harshly.
Awesome, this looks pretty similar to what I’m trying to do so I’ll test it out. Thanks! I didn’t even think about needing to do pitch detection. So your code will currently detect the pitch and play the sample at that pitch?
Yes, you get trig events with pitch (or rather wave length) and volume.
Great. I’ve been having fun playing around with it. It’s a cool project. I have a couple questions about it and I’m not sure if this is the best place to do it so I can message you somewhere else if that’s easier. Anyways, is the wav file you have included just for testing the synth? Because I don’t see it referenced in the code anywhere. Also, where does the actual synth get generated? Is it in the synthesizer() function? If so, how would I go about replacing that with a prerecorded sound sample?