Skip to content

Crashes when using SDL.OpenAudio directly #1

@jacius

Description

@jacius

(Copied from jacius#1, originally reported by rhp in November 2009)

Hi,

I am trying to set-up a program in which I use SDL to play some sound from a pre-loaded buffer.
Using the callback method for OpenAudio gives me some trouble: it crashes after running through a few loops of the callback method.

See this example:

#! /usr/bin/ruby -w

require 'rubygems'
require 'ruby-sdl-ffi'

SDL.Init(SDL::INIT_AUDIO)

spec = 
    SDL::AudioSpec.new(
        :freq => 22100,
        :format => SDL::AUDIO_S16,
        :channels => 2,
        :silence => 0,
        :samples => 512,
        :padding => 0,
        :size => 0,
        :userdata => nil,
        :callback => Proc.new { |unused, stream, len|
            p stream
            p len
        }
    )

raise "Could not open SDL audio" if SDL.OpenAudio(spec, nil) < 0

SDL.PauseAudio(0)

loop do
    SDL.PollEvent do |event|
        case event
            when SDL::QuitEvent
                exit(0)
            else
                # Do nothing
        end
    end
end

Comments from the original issue:

  • rhp November 15, 2009
    Auch... that didn't go entirely right...
    But I think you get the point...
    (ed: referring to broken formatting in the original post)

  • jacius November 29, 2009
    Hi. This library is still very young, so things are expected not to work. Thanks for the report though, I'll be sure to fix it in the future.

    As a workaround until this is fixed, I would suggest using SDL::Mixer::OpenAudio instead, if you don't need all the advanced AudioSpec stuff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions