How do I create sine wave sounds?

• Oct 12, 2020 - 15:38

I need to create sine waves for all notes (440 to 880 Hz) --- and have 110, 220, 330, 440, 550, 660, 770, and 880 Hz. Flute is close, but does have harmonics.

With sine wave tones, it is possible to demo pure tones vs. equal temperament tones
=> Pure Tone 550 Hz, Equal Temperament 554.37 Hz
=> Pure Tone 660 Hz, Equal Temperament 659.26 Hz

With sine wave sounds, it is also possible to demo overtones / undertones. It's simple math.

================================================
Below are replies from another post https://musescore.org/en/node/311541
..........................................................................................

Reply: Ziya Mete Demircan • Oct 12, 2020 - 01:49

I attached the sine-wave tones (in wav format) you wanted. I hope it works.
=> Attachment - Size
=> sine-waves.zip - 948.43 KB


Reply: bhs67 • Oct 12, 2020 - 01:58

Wow! That was fast! How do I load them into MuseScore?


Reply: Ziya Mete Demircan • Oct 12, 2020 - 02:40

If I create a soundfont: temperament patch is easy, but where do I put 110, 220, 330, etc (natural harmonics)?

When I place these frequencies in their respective octaves only, the remaining notes should not sound. because all the remaining notes will be in the wrong tuning.

Nevertheless, a soundfont can be made that contains a 12TET patch and one patch with only the harmonic frequencies at the relevant note locations.

But you mentioned a "math". How did you intend to use these natural harmonics?


Reply: bhs67 • Oct 12, 2020 - 14:54

I think it would be easier to create an instrument named "sine wave". And another instrument named "pure tone sine wave".

The source code is written in what language?

For the math:
sin(α) * sin(β) = ½ cos(α - β) - ½ cos(α + β)
sin(550) * sin(330) = ½ cos(550 - 330) - ½ cos(550 + 330)
sin(550) * sin(330) = ½ cos(220) - ½ cos(880)

In this example, playing a C# and an E results in a 220 Hz A undertone and an 880 Hz A overtone at half the amplitude as the C# and E. Playing two sounds results in four sounds.


Reply: Marc Sabatella • Oct 12, 2020 - 16:35

The source code is in C++, but nothing about creating a new instrument requires programming. First you need to add the sound, that's done using a soundfont editor, not programming. Then you would need to add the instrument definition to the instruments.xml file. But since sine waves are sounds, not instruments, that's not anything I'd recommend. Instead, simply use one of the existing "synthesizer" instruments, and use the Mixer to select the sound from the soundfont.


Comments

As mentioned in that other topic as well, MuseScore plays back the sound samples of a soundfont.
If you're looking to have MuseScore play back pure sine wave samples, then look into creating a soundfont containing such samples and on how to create such samples in the first place.

Response:

1) I see quite a few choices for Electronic Music - selected Effect Synthesizer. Is there a better choice for a pure sine wave?

2) View => Mixer --- opens the Mixer. How do I filter out all harmonics?

In reply to by bhs67

1) again, the instrument choice itself does not necessarily relate to the sound used for playback; the chosen playback sound in the mixer does.

2) you don't, not there by itself. You need a soundfont with your wanted samples. Then you can load that into musescore and use the mixer to select it for playback.

Soundfont editors work with audio samples and we cannot write any code or script in them.
It's simply the process of distributing the samples placed into the keys and additionally some ADSR and Modulation settings are made.

Unfortunately, even if you put a single wav file in it and specify 0-127 (the entire MIDI note range) as the coverage area in the instrument part, the Soundfont editors automatically set this to 12TET.

That is, we cannot obtain the expected +2 cents difference from the 3rd harmonic and the expected difference of -14 cents in the 5th harmonic (and also the difference of the next harmonics).

You can fine tune samples in Soundfont or notes in Musescore. But that's all.

And it is not possible in soundfont technology to make a difference (under or overtones) by combining two or more samples. Only additive-synthesis (by stacking the samples and adjusting their tunings) can be made and this causes a combination (Like organ instruments. eg: Hamm0nd).

In reply to by Ziya Mete Demircan

All of the sounds - flute, trombone, etc. - are stored some place (perhaps as an .mp3 file?). When users select flute, they will hear a flute sound.

It should be possible to select "sine wave" files. The question is, how does one implement "sine wave" files?

Overtones and undertones should "not" be added. When two sounds are generated, we will hear four sounds.

In reply to by jeetee

I was able to install HedSound-SineWave-Simple.sf2. I see the message:

"SoundFont installed. Please go to View > Synthesizer to add it and View > Mixer to choose an instrument sound."

When I select View, I see:

Sound Font Installed.jpg

Selecting "Synthesizer" is not allowed.

(BTW is there a way to resize jpg images?)

In reply to by bhs67

I had selected Piano for a new score --- then View => Synthesizer => Add => HedSound-SineWave-Simple.sf2.

Next I selected View => Mixer --- the Mixer displays Piano --- which I leave, and close Mixer.

When I return, I hear no sound.

I open a previous score with trumpet, trombone, etc. --- no sound. Is there a mute?

In reply to by bhs67

Make sure you keep the default soundfont on top of the list to ensure you'll hear all other instruments still as normal.
If you move the sine soundfont to the end of the list and then open the mixer; you'll find its entry to be the last there as well, it's called "008:080 - Sine-wave".

In reply to by jeetee

Thanks for that important info. I had selected Piano when I created the score.

1) In the mixer, I replaced "Piano" with "Sine Wave". Is that ok?

2) I decided to add a Piano. Now both staffs display the word Piano. How do change one of them to display Sine Wave?

Synth.jpg

3) When I look at Instruments to add to the score, I do not see Synthesizer or Sine Wave. Perhaps the only place to select that is in the Mixer?

In reply to by bhs67

1) Yes. Basically a choice of sound is pretty much unrelated to the choice of instrument. Choosing an instrument will automatically pick the closest matching General MIDI sound, but you are free to change the playback sound to whatever you want after that.
The choice of instrument becomes important when considering things like notation and transposition.

2) You can change the appearance/name of the instrument in the staff/part-properties for it. Right-click (ctrl-click if you're on Mac) within a staff of the instrument and choose the corresponding option from the context menu.
You can change both the long and the short name for the instrument. In your case however I would opt for starting from the actual synthesizer instrument first (see below)

3) By default MuseScore shows a limited list in the instruments window of the most common instruments across all musical genres. Synthesizer indeed isn't among them. If you use the search field at the bottom of the instruments list however, it filters through all defined instruments. Type in "synth" to see a listing of all known synthesizer definitions within MuseScore. Or in your case, type "sine" into the search field to filter directly on that.
EDIT: given that you're using a custom soundfont, you'll still have to select your sound in the mixer as well after choosing the correct instrument.

In reply to by bhs67

Where should we use them in soundfont?
If we create a single instrument and put these notes only where they are, the sounds you can play will only be: a2, a3, e4, a4, c#5, e5, g5, a5 (with their existing frequencies).
Otherwise (that is, if we let the remaining notes play as well) all other notes will be tampered.

Edit: I made a patch that only uses harmonics.
Soundfont is attached. // There is also a score inside that shows which notes can be played.

In reply to by Ziya Mete Demircan

Good question! I think it could work to label this pure tone 110 Hz, and have all other notes silent.

Using an electronic spectrum analyzer (Roga Visual Analyzer) the E4 and C#5 are different volume amplitudes. Not sure, yet, why this is occurring (perhaps sound card?). Also, I do not see, or hear, the sum and difference frequencies.

When I play A4 and A#4, I can hear the difference frequency - should be around 26 Hz. I cannot hear the sum frequency, perhaps because the frequency is high - should not be a problem as approximately 880 Hz is in our hearing range.

I plan to investigate further.

In reply to by bhs67

Using C# programming, I decided to create multiple sine waves, with zero harmonics - can adjust the volume for every frequency. The sine waves use the same zero crossing - intentionally, as this more accurately represents actual instruments.

In reply to by Ziya Mete Demircan

If you use Audacity you can take a wav (or mp3 - but wav would be "purer") and change the pitch by small amounts. You can also do this with other tools, such as Logic. You'd probably need some form of table with the factors to use, but it can be done. Sine waves of course can be generated mathematically, so if you wanted a composition of a few tracks of sine waves (or cosine, any related) you could do that. Some ready made synthesisers already do additive synthesis - though I'm not sure which ones work in MuseScore, or come with a default distribution. It seems to me that quite a few musicians using synthesisers have moved on (or never done it... ) from trying out pure tones and additive synthesisers. Subtractive synthesisers approach sound generation from a different direction, so probably the generated outputs won't have such sharply defined pure tones, while FM synthesisers are yet another approach.

If MuseScore doesn't give exactly the pitches required, then generate appropriate waves in MS, then export and do the fine tuning in another tool, such as Audacity.

If you want to play an instrument with anything other than 12TET they maybe look at PianoTeq, which can do that, but would need an appropriate sound library first to work on. https://www.modartt.com/

Playing with synthesisers can be fun, but many people just use presets, and don't try to simulate or reinforce "natural" sounds.

In reply to by dave2020X

Thanks for the response!

Using C# programming, I decided to create multiple sine waves, with zero harmonics - can adjust the volume for every frequency - can adjust the frequencies to fractions of Hz.

The sine waves start with the same zero crossing - intentionally, as this more accurately represents actual instruments.

In reply to by bhs67

You may be right about the more accurate representation - starting at a zero crossing - but once tones are running the zero crossings won't line up unless all are harmonically related. I think you might find that you have to do a short - barely perceptible fade in and similarly fade out on tones, otherwise you will probably hear (perceive) a click at the beginning and end of each tone.

Years ago experiments were done on the effects of relative phase in audio. This is very important for stereo channels (or surround sound) as the timing/phase difference between the stereo (or surround) channels is used by the ear/brain for location, but on mono channels I recall that changing the phases between spectral components made hardly any difference to the perceived tone. Similarly I think that changing the phases between spectral components on stereo or surround channels makes little difference to the preceived tone/timbre as long as the spatial phase relationships are maintained.

Thanks for mentioning the generators in Audacity - they are on a separate menu to the left of Effect.

Using MuseScore connected through JACK Audio Connection Kit to some external synthesizer, you can handle any kind of sound, included sine waves.

With Ubuntu (Linux), there are more than two completed synthesizers (including old analog MOOG near sounds) to get this.

Do you still have an unanswered question? Please log in first to post your question.