iamgreaser / iceball

Open-source rewrite of the VOXLAP version of Ace of Spades.
http://iceball.build
GNU General Public License v3.0
113 stars 32 forks source link

Implement ambisonic B-format audio #203

Open iamgreaser opened 9 years ago

iamgreaser commented 9 years ago

Because it's fucking amazing. Even on craptop speakers while using a simplistic psychoacoustic model. Experiments with a modified version of f3m (my s3m playroutine) confirm this.

Also because the current audio model is kinda shit.

May possibly chuck in a special mixer for sackit, too.

Ultimately this would require me to also add support for an arbitrary number of channels as well as some way to position each channel in 3D space. (I use 3W +/- 2Y + X for headphones but I may need to tweak this - may even drop in a Z component.)

Proposed API:

Note, Y is left minus right, and X is front minus back. (In other words they were still on drugs in the 70s.)

clsave/config.json will need a "channels" option.

Here's how you'd use a headphone setup:

if client.wav_chn_count() == 2 then
    client.wav_chn_ambisonic_set(0, 1.0, 1, 1/3, +2/3, 0)
    client.wav_chn_ambisonic_set(1, 1.0, 1, 1/3, -2/3, 0)
end

Of course we'll just use this for the engine default for 2-channel audio, unless of course we really care that much about compatibility with the old audio engine that we need to use [W+Y, W-Y]. (I personally don't.)

Ambisonic profiles should be settable in clsave/pub/user.json, although I think we should stick a few profiles in clsave/pub/ambisonics.json.

That is, clsave/pub/user.json would have "ambisonic_speaker_profile" (default to "headphones"), and then ambisonics.json would have something like:

{
    "profiles" : {
        "headphones" : {
            "2" : [
                [ 0.333, 3.0, 1.0,  2.0, 0.0 ],
                [ 0.333, 3.0, 1.0, -2.0, 0.0 ],
            ]
        },

        "laptop_speakers" : {
            "2" : [
                [ 0.25, 4.0, 1.0,  3.0, 0.0 ],
                [ 0.25, 4.0, 1.0, -3.0, 0.0 ],
            ]
        },

        "speakers" : {
            "2" : [
                [ 0.5, 2.0, 1.0, 1.0, 0.0 ],
                [ 0.5, 2.0, 1.0,-1.0, 0.0 ],
            ],

            "3" : [
                [ 0.5, 2.0, 1.0, 1.0, 0.0 ],
                [ 0.5, 2.0, 1.0,-1.0, 0.0 ],
                [ 1.0, 1.0,-1.0, 0.0, 0.0 ],
            ],

            "4" : [
                [ 0.5, 2.0, 1.0, 1.0, 0.0 ],
                [ 0.5, 2.0, 1.0,-1.0, 0.0 ],
                [ 0.5, 2.0,-1.0, 1.0, 0.0 ],
                [ 0.5, 2.0,-1.0,-1.0, 0.0 ],
            ],

            "5" : [
                [ 0.5, 2.0, 1.0, 1.0, 0.0 ],
                [ 0.5, 2.0, 1.0,-1.0, 0.0 ],
                [ 0.5, 2.0,-1.0, 1.0, 0.0 ],
                [ 0.5, 2.0,-1.0,-1.0, 0.0 ],
                [ 0.8, 1.0, 1.0, 0.0, 0.0 ],
            ],

            "6" : [
                [ 0.5, 2.0, 1.0, 1.0, 0.0 ],
                [ 0.5, 2.0, 1.0,-1.0, 0.0 ],
                [ 0.5, 2.0,-1.0, 1.0, 0.0 ],
                [ 0.5, 2.0,-1.0,-1.0, 0.0 ],
                [ 0.8, 1.0, 1.0, 0.0, 0.0 ],
                [ 1.0, 1.0, 0.0, 0.0, 0.0 ],
            ],
        },
    }
}
iamgreaser commented 9 years ago

Implementation of the actual mixing is in 0.2.1-29. There's no config options yet - it's just using a setup I like to use with headphones.

epicfacethe3rd commented 9 years ago

looks good, will sanic plugin ever be released?

iamgreaser commented 9 years ago

Get on IRC, I'll flick you a link.

rakiru commented 8 years ago

<~Kasen> mari_kiri, what's the state of this? does it just need to be made configurable? https://github.com/iamgreaser/iceball/issues/203 <&DerpyBot> [GitHub issue] iamgreaser/iceball #203 - iamgreaser: Implement ambisonic B-format audio (open) - engine & enhancement - Milestone: No milestone / Assigned: iamgreaser

it's not required <&mari_kiri> Kasen: Yeah, that's all really
iamgreaser commented 8 years ago

Pretty much.

If you want a proper matrix like this has then feel free, otherwise just do a two-variable "stereo separation fraction" thing and leave it at that. The latter case will make a more-than-two-speaker setup kinda suck, but heck, we don't even delay the channels by distance properly, and apparently that's one of the fundamental tenets of 3d sound.

But what we have now sounds better than what we had before, so eh.


If you're wondering, sound travels at ~343m/s through 20'C dry air, and at a 44100Hz sampling rate this basically means that every ~7.778mm a sound is from your ears you delay the sound by one sample.