Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6861769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:34:39+00:00 2026-05-27T02:34:39+00:00

I’ve been trying to figure this out for a few hours now. In order

  • 0

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!

Another update, as I’m still having some trouble. I’ve changed the vapi file, and this is what I have now:

public delegate void AudioCallback (out void* userdata, out uchar stream, int len);

[CCode (cname="SDL_AudioSpec")]
[Compact]
public struct AudioSpec {
    public int freq;
    public AudioFormat format;
    public uchar channels;
    public uchar silence;
    public uint16 samples;
    public uint16 padding;
    public uint32 size;
    public AudioCallback callback;
    public void* userdata;
}// AudioSpec

I have a method that (tries?) to meet this function signature:

public void callback(out void* userdata, out uchar stream, int len)
{
    stream = 0;
    userdata = null;
}

And assigning it as:

    audiospec.callback = gen.callback;

Needless to say, this still isn’t working, get lots of errors:

/home/gukid/vala/soundgen.vala.c: In function ‘sound_gen_main’:
/home/gukid/vala/soundgen.vala.c:766:12: error: ‘SDL_AudioSpec’ has no member named ‘callback_target_destroy_notify’
/home/gukid/vala/soundgen.vala.c:766:72: error: ‘SDL_AudioSpec’ has no member named ‘callback_target_destroy_notify’
/home/gukid/vala/soundgen.vala.c:766:114: error: ‘SDL_AudioSpec’ has no member named ‘callback_target’
/home/gukid/vala/soundgen.vala.c:768:11: error: ‘SDL_AudioSpec’ has no member named ‘callback_target’
/home/gukid/vala/soundgen.vala.c:769:11: error: ‘SDL_AudioSpec’ has no member named ‘callback_target_destroy_notify’
/home/gukid/vala/soundgen.vala.c:770:21: warning: assignment from incompatible pointer type [enabled by default]
/home/gukid/vala/soundgen.vala.c:771:11: error: ‘SDL_AudioSpec’ has no member named ‘callback_target’
/home/gukid/vala/soundgen.vala.c:772:11: error: ‘SDL_AudioSpec’ has no member named ‘callback_target_destroy_notify’
error: cc exited with status 256

So I’m at a bit of another sticky point.

3rd post: EUREKA! I have a solution! (debatable :P)

First off, the sdl.vapi looks like:

[CCode (cheader_filename = "SDL.h")]
public delegate void AudioCallback (void* userdata, uchar* stream, int len);

[CCode (cname="SDL_AudioSpec", has_type_id=false)]
public struct AudioSpec {
    public int freq;
    public AudioFormat format;
    public uchar channels;
    public uchar silence;
    public uint16 samples;
    public uint16 padding;
    public uint32 size;
    [CCode (delegate_target = false, type = "void*")]
    public weak AudioCallback callback;
    public void* userdata;
}// AudioSpec

And then I can just create a function:

public static void callback(void* userdata, uchar* stream, int len)

And:

audiospec.callback = callback;

Ahhh, finally my beautiful white noise generator is complete!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:34:40+00:00Added an answer on May 27, 2026 at 2:34 am

    I think it’s a bug in the VAPI. In sdl.vapi, try changing

    [Compact]
    public class AudioSpec {
    

    to

    public struct AudioSpec {
    

    and

    [CCode (cname="SDL_OpenAudio")]
    public static int open(AudioSpec desired, AudioSpec obtained);
    

    to

    [CCode (cname="SDL_OpenAudio")]
    public static int open(AudioSpec desired, out AudioSpec obtained);
    

    and make your code look like:

    AudioSpec 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, out specback) < 0)
    {
        stdout.printf("ERROR! Check audio settings!\n");
        return 1;
    }
    

    and give it a test. It seems to generate the correct code according to the SDL docs. If it works, consider submitting the VAPI changes to the Vala bugzilla.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.