What is Nostr?
Fabio Manganiello /
npub1v78…kv0u
2023-06-25 22:45:00

Fabio Manganiello on Nostr: A digital audio processing question for the #audio, #math and #physics geeks out ...

A digital audio processing question for the #audio, #math and #physics geeks out there (and, of course, any intersection between the three). I thought that I understood audio synthesizing (and acoustics in general), but this problem is making me question all of my knowledge on the topic.

Supposed that you have two sounds (say, for sake of simplicity, two MIDI notes, C4 and G4). They have their own associated fundamental frequencies f1 and f2.

Supposed that you build two simple sine waves for each of them with numpy or whatever, and let's say that each has 1000 samples.

The question is: how do I combine these two waves to give two different effects, at least to the human ear?

- Effect 1: f1 and f2 are "perceived" as a one single sound, with harmonics ratio of 3/2 in the case above, and the frequency that is perceived as "dominant" is the one with the highest amplitude.

- Effect 2: the sounds associated to f1 and f2 are "perceived" as distinct sounds that just happen to be played simultaneously - like in a chord.

If I take the sum of two resulting sine waves (or, better, the two numpy samples of 1000 items each), and send the resulting wave to the audio device, I get effect 1 - i.e. a fundamental frequency with some harmonics.

In order to achieve effect 2, I have to open two distinct audio streams (read "clients"), and send wave 1 to stream 1 and wave 2 to stream 2.

As I'm currently refactoring (and improving) the audio synthesizer extension of #Platypush, I find the latter solution quite inefficient - you may easily be on a system without Pulseaudio and/or with a limited amount of simultaneous sound outputs. Even in a Pulseaudio case with 32 channels, occupying each channel with a different note if I'm playing some polyphonic stuff is very inefficient.

So I'd like to "stuff" even case 2 (i.e. distinct sine waves played simultaneously) into a case-1-like solution (i.e. massage the sine waves and end up with a sound wave with the combination of them - not one with a new sound with harmonics).

And this made me wonder: from a mathematical and physical point of view, what makes the difference between the two cases? If I pluck two strings on my guitar at the exact same time, I perceive the resulting sound as a combination of two distinct waves each with its own fundamental frequency - not like a single sound with some upper harmonics given by the highest note.

Intuitively, the two sounds combine and make the air molecules "ripple" with a wave that should be (again, intuitively) the sum of the two waves.

So how come when I sum two waves on a computer I only get a single-note sound with harmonics? What makes the difference between the way our ears perceive those two cases? My educated guess says that it may have to be with the phase, but my empirical results tell me that it can't be the difference in phase alone.
Author Public Key
npub1v78mmuz20p6qd6nve30axhqu74avwn4f6z4grhug7755rat7wh3syukv0u