I'm creating my own midi player, so when I press c4 on my midi keyboard it goes into a sound bank (mp3 files) selects the c4.mp3 and plays it. If I release the note it stops, it also stops if c4.mp3 is over even though I didn't release the note. All of this so far is normal.

I use Reason software to play the piano most of the time. In Reason what you can do is press the sustain pedal and the note will keep playing infinitely. While listening closely I think I figured out that there is some kind of looping going on behind the scene but I can't exactly pin point where, what, how.

I'm no sound engineer so I'm not sure how to tackle this problem.

2 Answers 2


Firstly you have to work out exactly what you want this function to do. If you press a "sustain" pedal on a keyboard it has a well known and defined function - on a piano, it prevents the dampers from dampening the strings, so the string continues to vibrate, but with an MP3 you don't have any strings or dampers so you need to figure out exactly what you want it to do. An Mp3 could be any sound at all - possibly not even a single tone or timbre, so you may have issues here. I could suggest that the "sustain" pedal causes your note-on message to continue past the note-off message, and thus the mp3 continues to play. Or, you could implement a looping function where a short section of the mp3 continues to loop until the pedal is released. There are a number of options. You need to decide what you want it to do.


You're right: with a sample-based performance there is indeed looping going on. In Reason, if you look at the NN-XT Advanced Sampler for instance, you'll see there are settings per sample for where you want the loop to begin and end, and whether you want the sample to play forward/reverse or forward only etc. ("Play Mode").

You can achieve a great deal in this sampler so you might consider using that instead of creating your own bespoke sample player. Here's a tutorial that might give non-Reason users an insight into what it can do.

However, sound files themselves can include looping information in their meta-data. I don't know for sure that the mp3 format can support this, as I've been working with wav files for this. I can open them in my sound editor (Sound Forge) and view the loop editor. This gives me very fine control over where to begin and end the sustain loop, down to the wave form and sample level so that the "join" between the loop end and its beginning can be arranged with the minimum of noise (e.g. make the wave continue its slope smoothly without adding sudden jumps that might create a click). It looks like a simple job but depending on the sound it can be quite tricky to ensure that sound continues without a noticeable change in timbre etc. Anyway, having edited the sustain loop in the wav I can then load that into the sampler and it recognises the data and performs that loop according to pedal control etc. Here's a tutorial on editing loops.

So, if you want to implement a sustain in your mp3 player, you probably need to understand whether mp3 can indeed include sustain data and then whether or not you can control the playback according to that; then you need a means of creating / editing the loop in your sample. I suspect that mp3 might not support looping and my brief search for such information has not revealed anything to the contrary. Please do update this item if you find it does - I shall be very interested to hear more about your project! Good luck!

  • Thank you for your answer, I didn't know which one to accept, you or the other one. Since he answered earlier... Sorry for that. Anyway I'll let you know when my project is done, I think I'll have to have two files 1 the piano sound mp3 and 2 some loop.
    – Ced
    Dec 9, 2016 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.