Hello! I make an application in which you will need to play a sound when you press a key. As on the piano: while the key is pressed, the sound plays if released. the sound turns off. How can this be realized, any thoughts, tips? There is no code yet, since I haven’t been able to do anything.

The idea was the following: we have a sound file of some kind. With a long press of a key, we will simply wind off the audio a little back, that is, we will get a synth, zing. The audio will sound cyclically.

    2 answers 2

    The synthesis of sound is creative. Start with this article.

    Short:

    there are synthesizers

    • FM - generate sine-cosines, combine, filter and get a new album Stereolab

    • Wavetable - contain banks of pre-recorded samples that reproduce by changing the height (what you roughly offer). Cheap sounds lousy, go to any pub with live music, you will hear just that.

    • Sampling - In the studio, they roll up a real Stenway grand piano, arrange with microphones and record each key with a bunch of options. They sound indistinguishable from the present Stenvey, they stand - like a half Stenway.

    • Thank you for the article. These examples were very useful :) - Reaget

    Topikstarter note.

    A musical instrument, for example, a guitar or a piano when extracting a single note, in addition to the main harmonic, contains many higher harmonics (multiple of the main one) and many non-multiple timbres and so on.

    You can pinch the string in many ways, the attack of sound will change, the sustained strings are strongly influenced by the installed strings, even the sharpening of the nails is drastically affected. Fundamentally the direction of impact on the string.

    Tirando and apojando differ very much (although it is necessary to strive to make them sound similar). The sound of the thumb sliding when changing the position of the barre is a separate song. A legato of two notes is not at all the same as two notes one after another.

    With the brass and keyboard all the same, do not think that this is only a guitar.

    If all this does not happen - the sound will be very unnatural. Get rid of a sinusoid does not work.

    I do not discourage writing a program. I do not propose specific algorithms. Just showing that a task in good performance will be much more difficult than it seems to you at first glance. Or you can immediately tune yourself to the fact that the application will be completely toy, educational.

    Judging by the javascript tag, it really will be quite a conditional application.

    • @AK, Thank you for your reply. The application, in principle, is necessary for yourself to learn something new. :) - Reaget pm