Conversation
Thrill12
reviewed
May 10, 2026
| ALError error = AL.GetError(); | ||
| if (error != ALError.NoError) | ||
| { | ||
| throw new Exception("OpenAL error while trying to create audio buffer: " + error); |
Owner
There was a problem hiding this comment.
should add a Log.Error(...) here to add the errors to log as well... When we manage error handling, we will likely have a method which throws AND logs the trace and error message too but for now just do log.error
Thrill12
reviewed
May 14, 2026
| } | ||
| else | ||
| { | ||
| throw new Exception("Unsupported WAV file: unknown chunk type " + Encoding.ASCII.GetString(chunkId)); |
Thrill12
reviewed
May 14, 2026
|
|
||
| if (fmtChunk.AudioFormat != 1) | ||
| { | ||
| throw new Exception("Unsupported WAV file: only PCM format is supported."); |
Thrill12
reviewed
May 14, 2026
| Encoding.UTF8.GetString(byteFileType); | ||
| if (Encoding.ASCII.GetString(byteFileType) != "WAVE") | ||
| { | ||
| throw new Exception("Invalid WAV file: file type not listed as WAVE in RIFF header."); |
Thrill12
reviewed
May 14, 2026
| stream.ReadExactly(fourcc, 0, 4); | ||
| if (Encoding.ASCII.GetString(fourcc) != "RIFF") | ||
| { | ||
| throw new Exception("Invalid WAV file: missing RIFF header."); |
Thrill12
reviewed
May 14, 2026
| { | ||
| if (!File.Exists(path)) | ||
| { | ||
| throw new Exception("WAV file not found: " + path); |
Thrill12
reviewed
May 14, 2026
| if (size > 16) | ||
| { | ||
| ushort extensionSize = BinaryPrimitives.ReadUInt16LittleEndian(ReadBytesFromStream(stream, 2)); | ||
| if (extensionSize == 22) |
Owner
There was a problem hiding this comment.
can you inverse this IF and the one above?
if (size <= 16) return ...
if (extensionSize != 22) return ...
Keeps things cleaner and less nesting
Thrill12
reviewed
May 14, 2026
| return buffer; | ||
| } | ||
|
|
||
| private static FmtChunk ProcessFmtChunck(FileStream stream) |
Thrill12
reviewed
May 14, 2026
| @@ -2,6 +2,7 @@ | |||
| using OpenTK.Windowing.Common; | |||
Owner
There was a problem hiding this comment.
should add something in the pong sample to show using audio
Thrill12
reviewed
May 14, 2026
| /// Play back an audio source that has audio attached to it. | ||
| /// </summary> | ||
| /// <param name="source"></param> | ||
| public void PlaySource(AudioSource audioSource) |
Owner
There was a problem hiding this comment.
would it not make sense to have the Play function be directly on the AudioSource component? Then you can do something like
Entity.GetComponent().Play()
Open
OpenAL code to load PCM data and play it back, along with basic WAV file loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenAL code to load PCM data and play it back, along with basic WAV file loader