Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ambisonic B-format audio #203

Open
iamgreaser opened this issue Apr 5, 2015 · 5 comments
Open

Implement ambisonic B-format audio #203

iamgreaser opened this issue Apr 5, 2015 · 5 comments

Comments

@iamgreaser
Copy link
Owner

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:

  • client.wav_chn_count(): Gets the number of audio channels.
  • gain, w, x, y, z = client.wav_chn_ambisonic_get(chn_idx): Gets the ambisonic configuration for a given audio channel. chn_idx in range [0, chn_count).
  • client.wav_chn_ambisonic_set(chn_idx, gain, w, x, y, z): Sets the ambisonic configuration for a given audio channel. chn_idx in range [0, chn_count).

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
Copy link
Owner Author

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
Copy link

looks good, will sanic plugin ever be released?

@iamgreaser
Copy link
Owner Author

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

@rakiru
Copy link
Collaborator

rakiru commented Jan 15, 2016

<~Kasen> mari_kiri, what's the state of this? does it just need to be made configurable? #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
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants