Menu

#37 mixed sounds

Unstable_(example)
closed
nobody
None
5
2016-10-30
2016-10-16
No

Dear Jim,

I propose you next update for generated sounds:

1) more accurate frequencies by using a true PI. Some harmonies sounded a bit bad before and sinusoids was not as it should.

2) playing multiple sounds in the same time was possible by playing each voice on separated QAudioOutput. But if you press stop in the previous implementation, you can hear the voices stopping one by one (very short delay even the fact that voices are stopped in a simple and faster loop). The problem is simple: if stopping action implies a short delay between voices, the same thing is happening (probably) on start action.
And if we go further to use generated sounds just like old WAV files, we need a mixed (single) voice. So that we can seek, pause, rewind, stop and play just one sound, without the worry about voices that compose the main sound (voices that can be of different durations).
So we need to correctly mix sounds.
This implementation give us this infrastructure to go further by mixing voices (almost perfectly).

3) the user can choose from settings the default value for sound volume. Now, the sound volume is reset to default value (5) for each run. So, if you play a game that mute the sound and then run another one that do not set the sound volume, now you will hear sound (as it should).

4) now, the user can choose the sample rate of sounds in settings because 4400Hz is not so generous with user ears.

The main challenge was/is the mixing voices. One voice at maximum volume is ok to play. But if you play two sounds in the same time then the voices should be added (10 voices of humans sound 10 times louder than one). But the output is limited and the exceeded sound you will be heard as noise. So, to mix multiple sounds, I got to fit into the maximum range. In the same time, when just one voice is heared, this should be played as normal, at normal volume.

It is a bit complicated and the internet is full with wrong methods.
I choose to mix just like Windows do. If you listen carefully you will hear:
a) when system play a single sound, it is played at maximum volume
b) when system play multiple sounds in the same time, it adjust the volume to this mixed new sound to fit in playable range.
c) when all other sounds (voices) are stopped and there is just one sound to play, windows will slowly increase the volume back to normal.
This is how it work this implementation also. But because of normalized volume portions (too louder sounds), there are two new options in the settings:

Min. period to normalize louder sounds
This is the period of time after a louder (mixed) sound in which system is waiting to see if the louder portion is over before to bring volume to normal.

Period to restore volume after louder sound
This is the period of time after a louder (mixed) sound in which system will bring volume to normal by increase it bit by bit (fade to normal).

To play with those settings, run this code at maximum volume with different settings:

volume (10)

pause 1
#simple sound
sound {262,2000}

#mixed sound with one sound as background
#the entire mixed sound should not be normalized entierly (only louder parts)
sound {{262,20000},{0,3000,330,2000,0,3000,330,2000,0,3000,330,2000,0,3000,330,2000},{0,4000,392,1000,0,4000,392,1000,0,4000,392,1000,0,4000,392,1000}}

#simple, mixed sound
sound {{262,10000},{0,1000,330,9000},{0,2000,392,8000},{0,3000,523,7000}}

Final notes:
Commons musical notes are not integers (E4=329.63; F4=349.23; F#4/Gb4=369.99).
Do you think that it would be a good idea to let user to play such frequences (float, not integers)?

PS About the redesign of sound commands I will continue the discution in that post.

Respectfully,
Florin Oprea

7 Attachments

Discussion

  • Jim Reneau

    Jim Reneau - 2016-10-30
    • status: open --> closed
     
  • Jim Reneau

    Jim Reneau - 2016-10-30

    added to 1.99.99.72

     

Log in to post a comment.