I’m trying to get an AudioStream to feed data from the default playback device so I can then modify it e.g. apply a parametric EQ to the stream
The problem is I can’t get data from the AudioStream (verified with 0 bytes being read from the stream via GetAudioStreamData(output_stream, &buffer, max_bytes_to_fill)
Other things I’ve verified:
- Audio spec creates
- Correct output device
- Audio stream opened successfully
Where am I making the mistake?
Any help would greatly be appreciated ![]()
Here’s some of the code (note I’m using SDL3 with Odin):
```
// Setup the playback device
output_device : sdl.AudioDeviceID = sdl.OpenAudioDevice(sdl.AUDIO_DEVICE_DEFAULT_PLAYBACK, &desiredAudioSpec)
// Double check what the output device is
output_device_name : cstring = sdl.GetAudioDeviceName(output_device)
// Setup the stream
output_stream : ^sdl.AudioStream = sdl.OpenAudioDeviceStream(sdl.AUDIO_DEVICE_DEFAULT_PLAYBACK, &desiredAudioSpec, nil, nil)
// Error checking
if (output_stream == nil)
{
fmt.printfln("No stream detected", sdl.GetError())
}
// Start the stream
// (Successfully opens)
audio_stream_opened : bool = sdl.ResumeAudioStreamDevice(output_stream)
running := true
for running {
// Event handling - check for window close event
event : sdl.Event
for sdl.PollEvent(&event)
{
#partial switch event.type
{
case .QUIT:
running = false
}
}
minimum_audio : i32 = (8000 * size_of(f32)) / 2 /* 8000 float samples per second. Half of that. */
buffer : [512]f32
max_bytes_to_fill : i32 = size_of(buffer)
// Checks if the number of bytes queued is less than the minimum audio, if so continue
if (sdl.GetAudioStreamQueued(output_stream) < minimum_audio)
{
// Get the audio data and store it into the buffer
num_of_bytes_read_from_stream : i32 = sdl.GetAudioStreamData(output_stream, &buffer, max_bytes_to_fill)
fmt.println("Num of bytes read from stream ",num_of_bytes_read_from_stream)