Skip to content

Audio setup with WAV file loading#35

Draft
nrbyte wants to merge 5 commits into
mainfrom
audio
Draft

Audio setup with WAV file loading#35
nrbyte wants to merge 5 commits into
mainfrom
audio

Conversation

@nrbyte
Copy link
Copy Markdown
Collaborator

@nrbyte nrbyte commented May 8, 2026

OpenAL code to load PCM data and play it back, along with basic WAV file loader

Comment thread src/rasdaq/Audio/Audio.cs Outdated
ALError error = AL.GetError();
if (error != ALError.NoError)
{
throw new Exception("OpenAL error while trying to create audio buffer: " + error);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

}
else
{
throw new Exception("Unsupported WAV file: unknown chunk type " + Encoding.ASCII.GetString(chunkId));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.Error


if (fmtChunk.AudioFormat != 1)
{
throw new Exception("Unsupported WAV file: only PCM format is supported.");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.Error

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.");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.Error

stream.ReadExactly(fourcc, 0, 4);
if (Encoding.ASCII.GetString(fourcc) != "RIFF")
{
throw new Exception("Invalid WAV file: missing RIFF header.");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.Error

{
if (!File.Exists(path))
{
throw new Exception("WAV file not found: " + path);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log.Error

if (size > 16)
{
ushort extensionSize = BinaryPrimitives.ReadUInt16LittleEndian(ReadBytesFromStream(stream, 2));
if (extensionSize == 22)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you inverse this IF and the one above?

if (size <= 16) return ...
if (extensionSize != 22) return ...

Keeps things cleaner and less nesting

return buffer;
}

private static FmtChunk ProcessFmtChunck(FileStream stream)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is Chunck?

Comment thread src/rasdaq/Application.cs
@@ -2,6 +2,7 @@
using OpenTK.Windowing.Common;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add something in the pong sample to show using audio

/// Play back an audio source that has audio attached to it.
/// </summary>
/// <param name="source"></param>
public void PlaySource(AudioSource audioSource)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

@Rinceri Rinceri linked an issue May 14, 2026 that may be closed by this pull request
nrbyte added 5 commits May 14, 2026 23:06
OpenAL code to load PCM data and play it back, along with basic WAV file loader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audio

2 participants