Commit Graph

3386 Commits

Author SHA1 Message Date
bjorn cb8e1b5b91 Fix compile errors; 2021-02-08 16:08:29 -07:00
bjorn a3a5b29d6d Minor style changes; 2021-02-08 16:08:29 -07:00
mcc f515d8e84f Code review adjustments (code clarity, constness) for oculus spatializer 2021-02-08 16:08:29 -07:00
mcc 46bb053e0f Late changes on oculus spatializer: Fix memory corruption bug on source delete, add comment 2021-02-08 16:08:29 -07:00
mcc 9ba4037e74 LOVR_USE_OCULUS_AUDIO
This is a large patch which adds a new Oculus Audio spatializer. Oculus Audio is slightly different from the dummy spatializer in a few ways:

    - It *must* receive fixed-size input buffers, every time, always.
    - It can only handle a fixed number of spatialized sound sources at a time.
    - It has a concept of "tails"; the spatialization of a sound can continue after the sound itself ends (eg echo).

Changes to audio.c were needed to support Oculus Audio's quirks:

    - audio.c now supports a "fixedBuffer" mode which invokes the generator/spatializer in fixed size chunks
    - Each source now has an intptr_t "memo" field that the spatializer may use to store whatever (Oculus spatializer uses this to handle the sound source limit).
    - The spatializer interface got a couple new methods: A "tail" method which returns a sound buffer after all sources are processed; and "create" and "destroy" methods that are called when a sound source is created or destroyed (Oculus spatializer uses this to populate/clear the "memo" field).

Along the way some other miscellaneous changes got made:

    - lovr.audio.getSpatializerName() returns the current spatializer
    - Spatializer init now takes in "config in" and "config out" structs (Spatializer changes fields in config out to request things, currently fixed buffer mode).
    - lovr.conf now takes t.audio.spatializer (string name of desired spatializer) and t.audio.spatializerMaxSourcesHint (Spatializers with max sources limits like Oculus will use this as the limit).
    - audio.c went back to tracking position/orientation as vectors rather than a matrix
    - A file oculus_spatializer_math_shim.h was added containing a minimal copypaste of OVR_CAPI.h from Oculus SDK to support a ovrPoseStatef the spatializer API needs. This may have license consequences but we are probably OK via a combination of fair use and the fact that a user cannot use this header file without accepting Oculus's license through other means.

Some work remains to be done, in particular there is an entire reverb feature I did not touch and LOVR_USE_OCULUS_AUDIO cannot be activated from tup. Oculus Spatializer works better when it has velocity and time information but this patch does not supply it.
2021-02-08 16:08:29 -07:00
mcc bbf26ad4eb LOVR_DEBUG_AUDIOTAP debug helper in audio.c 2021-02-08 16:08:29 -07:00
mcc fb2d4fe0ca Fix build on MSVC2019 (ptr arithmetic on void * is nonstandard) 2021-02-08 16:08:29 -07:00
mcc 061f613697 Remove unused openal-soft module
This was breaking mercurial.
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 5cc33b3ee5 oops, use capture device for capture, not playback 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson d618a2e629 lovr.audio.isRunning 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson f5a684f359 Fix broken listener orientation code in dummy spatializer
it's a quat, not an axis-angle. now it works :)
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 84bfac984c l_audio: less code
why is this so hard for my brain? :S
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 7f5e46ad0b audio: don't uninit device on stop
in case initing a device is expensive, don't do it
unnecessarily, and treat 'stop' as more of a 'pause'.
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson c542be254e setDevice fix on android 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 2719eba1ba lovrAudioSetCaptureFormat
instead of mixing up using device with using format
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 49288b7547 ma_result_descripion all the things 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson a7b0780bfc Don't allow invalid sample format 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 9ba8638028 Audio: Simplify enabled/started/reset
* Stop also uninitializes
* Reset doesn't exist. Just stop and start instead.
* lovrAudioInit no longer takes config, and config is now private.
  Call lovrAudioStart if you want to start.
* ma_device_{un}init and start/stop are only called from one place each,
  reducing the risk of dangling state
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 138853ef01 Fix getDevices API
* Takes device type, so you only get either playback or capture devices
* Doesn't store devices in state, reducing risk of dangling pointers
* Uses names instead of identifiers, since miniaudio identifiers become
  invalid if you call "getDevices" again
* Better diagnostics
* Split up lovrAudioInitDevice to be per-type, cleaner that way
* UseDevice now takes type and name, instead of just identifier
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 9c7bc7c8db stub out pico permissions so we can compile 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson a5d073c5db stop void* arith 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 9ea635199d Forgot a return... 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 10af0e5748 oops, capturing with wrong bytesPerFrame 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 46e9ae8ef5 oops 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 5fcaad9bde Change mic capture API to return SoundData stream instead of individual chunks 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 044a5a47d9 allow configuring sound format and sample rate 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 035f48927a fix various audio logging 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson f98140c601 make converters array one of pointers
so that converters are allocated on heap and the converters
array can be expanded later without moving the converter
itself
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson f8c29d1c79 bump to miniaudio with Quest fix
This is a WIP version v0.10.28 aka 6c60953e9cb587
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 8133966148 take out lovrDataNewSoundDataStream 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 0d36cdd443 nicer assert in sound data append 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 213c721d1f oops 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson eee1d09cc4 SoundDataSetSample: only allowed on raw; and check frames instead of blob size 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 5df40bb103 don't try to forward-declare mb_pcm_rb 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson e1c94c3084 stop depending on audio from data 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 8b594332dc Revert miniaudio to 0.10.12
aka a9541579f38a0c1bab4bba294f3602fa0b80f127, plus cherry-pick of
2dc604ecde0f02280690c72f943bfb8bf52dd820.

There is a crasher in 0.10.13 and newer on Oculus Quest
(See https://github.com/mackron/miniaudio/issues/247)
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson d8dd09eb8d oops, initialize source's transform
otherwise we'll get NaNs up in here
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 6d62e634d4 oops 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson e46079b368 lovrAudioUseDevice 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 9381e2027d audio.getDevices full impl 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson ebcc5f51d7 Devices WIP 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 53d3568528 don't assert on audio thread 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 3e003d55b9 Separate SoundData and SoundDataStrema constructors
they take the same arguments so we can't overload
the function parameterically.
also I find it pretty confusing that lovr uses
overloads so much in the api,
so I really don't mind having
a separate constructor :S
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 35ac33f184 SoundData:setSample 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson f5fcb73324 duration and time for stream sounddata 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 8c1aa5a8ef lua API for SoundData:append 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 2a875b129b Fix a few bugs and style fixes
* We can't realloc converters, that'll break internal pointers
* inverted condition in an assert
* less magic numbers
* can't loop streams
2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 3c535986f0 SoundData: deallocate rb 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson d1f6e27437 SoundData stream lua API 2021-02-08 16:08:29 -07:00
Nevyn Bengtsson 7b58561c03 lovrSoundFormat 2021-02-08 16:08:29 -07:00