<div dir="ltr">Hi Chris,<div><br></div><div>this is fantastic! Exactly the kind of advice I was looking for.</div><div>We'll try to make this work, I'll let you know how it goes!</div><div><br></div><div><br></div><div>Best regards,</div><div>Aleksei</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jul 18, 2020 at 3:30 AM Chris Robinson <<a href="mailto:chris.kcat@gmail.com">chris.kcat@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, 18 Jul 2020 01:58:04 -0700<br>
Aleksei Petrenko <<a href="mailto:petrenko@usc.edu" target="_blank">petrenko@usc.edu</a>> wrote:<br>
<br>
> My question is, is it possible to get programmatic access to the<br>
> sounds played during every particular frame of the game?<br>
> <br>
> An example to be more concrete. Let's say the normal framerate of the<br>
> game is 60FPS. I am running the game 10 times faster than realtime,<br>
> so at 600FPS (10x is not important, I want to run the game as fast as<br>
> hardware allows, the exact speedup is not known). At some point, a<br>
> game event triggers a sound that under normal circumstances would<br>
> play for 1 second, so for 60 game ticks. In my fast simulation it<br>
> only lasts 0.1 seconds, and the same 60 game ticks.<br>
<br>
Hi.<br>
<br>
With OpenAL Soft's ALC_SOFT_loopback extension, it should be possible<br>
to do this, as long as you're able to modify your program's source. If<br>
the ALC_SOFT_loopback extension is supported, you can get the<br>
alcLoopbackOpenDeviceSOFT function (with alcGetProcAddress), and create<br>
an ALCdevice using that. Specify the render format you want when calling<br>
alcCreateContext, and the normal AL functions can be used as normal when<br>
the context is made current.<br>
<br>
At that point, you're in control of when and how fast samples are<br>
mixed. Call alcRenderSamplesSOFT to render samples and fill in your<br>
provided buffer. Ideally you'd render ~20ms worth of samples per call<br>
(512 to 1024 sample frames at 44100hz), but any size can work and it<br>
can be called as often as your CPU allows. So for example:<br>
<br>
#include "alext.h"<br>
<br>
LPALCLOOPBACKOPENDEVICESOFT alcLoopbackOpenDeviceSOFT;<br>
LPALCRENDERSAMPLESSOFT alcRenderSamplesSOFT;<br>
<br>
...sound initialization...<br>
if(!alcIsExtensionPresent(NULL, "ALC_SOFT_loopback"))<br>
{<br>
    error("Loopback not supported");<br>
    abort();<br>
}<br>
<br>
alcLoopbackOpenDeviceSOFT = alcGetProcAddress(NULL,<br>
    "alcLoopbackOpenDeviceSOFT");<br>
alcRenderSamplesSOFT = alcGetProcAddress(NULL, "alcRenderSamplesSOFT");<br>
<br>
ALCdevice *device = alcLoopbackOpenDeviceSOFT(NULL);<br>
ALCint attrs[] = {<br>
    /* Standard 16-bit stereo 44.1khz. Can change as desired. */<br>
    ALC_FORMAT_TYPE_SOFT, ALC_SHORT_SOFT,<br>
    ALC_FORMAT_CHANNELS_SOFT, ALC_STEREO_SOFT,<br>
    ALC_FREQUENCY, 44100,<br>
<br>
    /* end-of-list */<br>
    0<br>
};<br>
ALCcontext *context = alcCreateContext(device, attrs);<br>
alcMakeContextCurrent(context);<br>
<br>
...in main loop...<br>
    ..make normal AL update calls..<br>
<br>
    /* Ensure 'buffer' can hold 1024 sample frames when calling (4096<br>
     * bytes for 16-bit stereo). */<br>
    alcRenderSamplesSOFT(device, buffer, 1024);<br>
<br>
    ..1024 sample frames are now in 'buffer'..<br>
...<br>
<br>
The above main loop can run faster than real-time. An AL call made after<br>
rendering 44100 sample frames would act as if it was made after one<br>
second of playback. If all the resulting samples are concatenated and<br>
played back at normal speed, it would sound indistinguishable from<br>
normal device playback. See<br>
<<a href="https://urldefense.com/v3/__https://openal-soft.org/openal-extensions/SOFT_loopback.txt__;!!LIr3w8kk_Xxm!83zmI7TW0wMP1j4irCuIr_UIc3DS4dOu99HuEnONDlUCVywFLZHZZskL-XP7CqY$" rel="noreferrer" target="_blank">https://urldefense.com/v3/__https://openal-soft.org/openal-extensions/SOFT_loopback.txt__;!!LIr3w8kk_Xxm!83zmI7TW0wMP1j4irCuIr_UIc3DS4dOu99HuEnONDlUCVywFLZHZZskL-XP7CqY$</a> > for more<br>
information about the extension.<br>
</blockquote></div>