Trills originated as simple ornaments. When we are reaching a V - I cadence (e.g. G Major -> C Major in the key of C) at the end of a piece or section, that the most important note is the 'leading tone' or the 3rd of the chord (B, in the case of G Major). The B then should always proceed to the C. If a D descends to a C at the same time, it increases this motion, and if an F descends to an E, it creates a particular dissonance that accents the motion.
The most basic thing to do then, as a solo instrument, might be to play D then B over the G chord, then proceed to C. Another option would be to start on a C half-note while playing the G chord, then descend to B in the 2nd half note, then return to C when we reach the C chord. This we call a 'Neighbor Tone', and is a sense, the ancestor of the trill.
One can have more fun than this! Quickly alternate between C and B over the G chord, then resolve to the C rather than (boring!) hold them each a half-note, and you have created extra tension and motion. Motion around cadences adds excitement and contrast- when the cadence resolves, motion ceases or slows, creating a 'sigh'-like feeling, like fluttering butterflies in your heart calming. Because the trill was originally essentially an elaborate ornament, it typically had a phase of rapid, but in-time ("measured"- either 16th or 32nd notes depending on speed of the piece) alternation, between a note in the chord, and one outside of the chord (typically a half step or a whole step), then a small ornament. Trills in many cases start on the note that is "out" and rapidly "resolve" to the note that is "in", but there are no fixed rules that are clearly visible across all periods- for example, in early music, it is common (even in a preliminary sense, a 'rule') that the trill will start on an upper note, while in modern music, trills in many cases start on the lower note.
https://youtu.be/2s31pmhyVh4?t=246
Basically, if you had a G chord in 4/4, you might play in the Baroque period, as sixteenths:
CBCB CBCB CBCB CBAB | C--- ---- ---- ----
In some cases, the first note will be a leap from the previous measure, and thus emphasized and/or accented, as it is an Appoggitura.
Nowadays the ornamenty bit at the end is often left out, and trills can occur starting both on the upper and the lower tone. The largest change is that the trill no longer so much performs a harmonic function, but rather an emotional function. Examine, for example, Golden Age Hollywood scores, or the works of threater/Broadway from that time- endless use of major 2nd flute trills.
In addition, we also find the use of "unmeasured" trills and tremolos, where the repetition is not normal and is simply the fastest alternation that can be done or that fits with the mood of the work. Historically, a trill or tremolo was almost always "more or less" a 16th-note pattern (or in the case of a particularly fast piece, 8th notes, or particularly slow, 32nd notes)- although a performer obviously has to "milk" it and play rubato (starting slower and speeding up in most cases) and in a shape that will lead the listener to the cadence.
Increasingly, a trill of an interval larger than 1 step is used, but this is actually not a trill, but a tremolo. You see, back when music printing required engraving or music type pieces, it was very time consuming and expensive to carve, draw, or place many repeated notes. Therefore, an abbreviation of this, the tremolo, was used: draw a half note with two slashes and instantly indicate eight sixteenth notes.
https://easymusictheory.wordpress.com/ta...d-tremolo/
The magic is when you notate two notes with the tremolo between them- this cases them to be repeated between rapidly, but at a measured rate. There is nothing better than drawing two whole notes with tremolo markings and get a bunch of 16ths back and forth when your concerns are with ink, time, and a limited number of (expensive) musical printing press type pieces. The first few pages of the original score for Stravinsky's Rite of Spring is a good example of these measured tremolos in action- the obvious reduction of clutter is enormous.
As for simulating trills, I have had excellent results using WIPS/SIPS with settings of around ~30-50 ms on the length of the legato and length of the crossfade. Play your starting note and hold it while rapidly tapping the lower or upper note you want to trill with. If you have extra care, you can add key clicks. There is also a slight sound made from covering holes that is tricky to simulate, but if you were to sample it, that could be added as well.
EDIT 2: Here is a demo with a few turns and trills simulated with WIPS. You'll hear the plain bit, then the trill. In most cases, with these cadential trills, I've stopped trilling. You will also hear a few ornaments (appoggituras, 'turns', etc.).
https://instaud.io/BUH
EDIT: I forgot to mention, there also existed in the early days of synthesizers and game audio, a form of rapid tremolo between a large interval, say an octave or a 5th. This was because the number of voices was limited and this essentially allowed them to sound multiple notes. This had some origins in earlier jazz and ragtime styles as an extension on the trill.
eg:
https://instaud.io/vkn#0:31.9
So, TL;DR-
- You can use trills and tremolo however you want, there are zero rules that matter anymore.
- If you want your trills to mesh nicely, use it sparingly- typically only in your "lead" voice or else some other higher voice.
- Trills should always resolve to one of the two notes that is part of the trill, or the note above or below it.
- The easiest implementation is a half-step trill between "do" and "ti" in a Perfect Authentic cadence (V - i) , or the whole-step between "mi" and "re".
- Trills best fit wherever there is a 'Neighbor Tone' or a 'Passing Tone'- because then you have a resolution ready and waiting for you. (e.g. if you have the line "G - F } E", each being a half note, you could trill between G and F where the F half-note is currently, starting on G, then leading to E)