How to initialize audio with Vala/SDL

Posted by ioev on Stack Overflow See other posts from Stack Overflow or by ioev
Published on 2011-11-25T15:10:52Z Indexed on 2011/11/25 17:50 UTC
Read the original article Hit count: 262

Filed under:
|
|

I've been trying to figure this out for a few hours now.

In order to start up the audio, I need to create an SDL.AudioSpec object and pass it to SDL.Audio.Open. The problem is, AudioSpec is a class with a private constructor, so when I try to create one I get:

sdl.vala:18.25-18.43: error: `SDL.AudioSpec' does not have a default constructor
        AudioSpec audiospec = new SDL.AudioSpec();
                              ^^^^^^^^^^^^^^^^^^^

And if I try to just assign values to it's member vars like a struct (it's a struct in normal sdl) I get:

sdl.vala:20.3-20.25: error: use of possibly unassigned local variable `audiospec'
        audiospec.freq = 22050;
        ^^^^^^^^^^^^^^^^^^^^^^^

I found the valac doc here: http://valadoc.org/sdl/SDL.AudioSpec.html But it isn't much help at all.

The offending code block looks like this:

// setup the audio configuration
AudioSpec audiospec;
AudioSpec specback;
audiospec.freq = 22050;
audiospec.format = SDL.AudioFormat.S16LSB;
audiospec.channels = 2;
audiospec.samples = 512;

// try to initialize sound with these values
if (SDL.Audio.open(audiospec, specback) < 0)
{
    stdout.printf("ERROR! Check audio settings!\n");
    return 1;
}

Any help would be greatly appreciated!

© Stack Overflow or respective owner

Related posts about audio

Related posts about sdl