-
-
Notifications
You must be signed in to change notification settings - Fork 957
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
feat: Port native Audio providers to C# #2454
base: master
Are you sure you want to change the base?
Conversation
sources/Directory.Packages.props
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the whole file got "touched" in the latest commit (maybe the encoding change or the EOL character). Try to keep the encoding on all file to be UTF-8 and EOL to be LF when pushing (but can be CRLF when checking out on Windows). Please check whether the git config option on Windows and Linux are consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With that said, sometimes git does the strangest diff and it's out of our control (could be the case here).
Funnily enough, my OpenAL audio layer fixes a bug where when opening the audio a second time it crashes the entire game. |
fb4142f
to
426a701
Compare
22643f4
to
2a18ab9
Compare
2a18ab9
to
6ec7068
Compare
buffer.Buffer.PContext = bufferPtr; | ||
|
||
var data = stackalloc byte[maxBufferSizeBytes]; | ||
buffer.Buffer.PAudioData = data; | ||
return buffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me if I speak prematurely, but I stumble upon this and it hurts my eyes. It is never valid to stackalloc
and let the pointer escape the current method. data
is implicitly discarded and will be reused for method calls immediately upon return from this method. This buffer should probably be a rented buffer and perhaps also allocated from the pinned object heap, or allocated using NativeMemory
, since I assume it will be used for native interop and/or hardware.
@@ -161,6 +167,11 @@ public unsafe Source SourceCreate(Listener listener, int sampleRate, int maxNumb | |||
var delay = stackalloc float[AUDIO_CHANNELS]; | |||
source.dsp_settings.pDelayTimes = delay; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
al.SourceQueueBuffers(source.Value, 1, &buffer.Value); | ||
fixed (uint* bufferPtr = &buffer.Value) | ||
{ | ||
al.SourceQueueBuffers(source.Value, 1, bufferPtr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The buffer will be used asynchronously, but it won't be pinned when it is used anymore, since the fixed
statement is exited. To keep the buffer pinned, allocate it pinned, or from native memory, or use GCHandle.Alloc(buffer.Value, GCHandleType.Pinned)
and then keep the GCHandle
around and call Free
on it once the buffer no longer needs to be pinned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for derailing the conversation slightly, but since we have you here, @ericwj can you quickly take a look at this comment we left a while ago on something you wrote #2393 (comment)
PR Details
The goal of this PR is to make the Stride.Audio module fully working in C#, without worring about C++ build tools.
Todo
Types of changes
Checklist