SDL and sound problem

Discussion about other and unofficial ports of ScummVM

Moderator: ScummVM Team

User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

SDL and sound problem

Post by Der_Knob »

Hi,

I'm the developer of the Sally Project: www.sally-project.de
I started to port ScummVM as an plugin to Sally.

First of all: It's really easy to make a port! Good Job!!! :D

I'm basically using the windows SDL port and changed just the output surface. Afterwards I copy the SDL surface to a DirectX Texture and display that one in the plugin... so far every thing is already working (Mouse / Keyboard input, starting of games, ...).

There is only a problem with the sound... I don't hear anything.
I hunted the error and found the problem.
I changed in the loadGFXMode() method the creation of the _hwscreen surface from:

_hwscreen = SDL_SetVideoMode(hwW, hwH, 16,
_videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
);

to:

_hwscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, hwW, hwH, 16, 0, 0, 0, 0);

When I change it back, I can hear the sound (but it opens a new window... and that is not what I want).
I'm new to SDL.
My first thougth was that SDL needs a window to play sound, so I created a little test program and it's possible to play sound if you don't have a window...

Can anyone help me with this?
Any idea? Any function I should take a look at?

Regards
Knob
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

I'd say, your best bet would be to take a look at the SDL documentation, and find out how to properly initialize the audio system if now window is used (if that's possible, I have no idea).
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

sorry, I forgot to say, that I have created a test project in SDL and I was able to play sound without having a window...
I just created a surface and the audio stuff and it worked.
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

OK, then next check what we do in the SDL backend, step by step, and modify it to do the same as your test project does?
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

ok, I think I will try this on the weekend...
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

I'm looking for the class / method where the sound initialized (or something like this)?

Where can I find this one?
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

backends/platform/sdl/sdl.cpp see OSystem_SDL::setupMixer

Or: just grep for SDL_OpenAudio :)
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

Thanks!

I have taken a look at it in the debugger and everything looks ok :-(

Is there something like a logfile?
I know, when I start scummvm normally I get a console with some output.
Can I configure the output target to write the console output to a file?
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

mh, and I can't find any type of code, weher you use the variables initialized with SDL_OpenAudio(&desired, &_obtainedRate)...

Just if someone know: How is the sound be played over / with the SDL_OpenAudio device?
User avatar
eriktorbjorn
ScummVM Developer
Posts: 3561
Joined: Mon Oct 31, 2005 7:39 am

Post by eriktorbjorn »

Der_Knob wrote: Just if someone know: How is the sound be played over / with the SDL_OpenAudio device?
I've hardly ever used SDL directly myself, but the idea (as far as I know) is that when you call SDL_OpenAudio() you tell SDL how you want to generate audio data ("desired"). SDL replies back with how it wants you to do ("obtainedRate"). ScummVM assumes that the only thing there could possibly be any doubt about is the sample rate, so it looks at obtainedRate.freq and sends that to the mixer.

After that, once SDL_PauseAudio(0) has been called, SDL will automatically call the audio callback function (desired.callback) mixCallback(). This function is responsible for filling a buffer with audio data, which SDL plays.

The SDL Documentation Wiki describes this in greater detail.
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

Thanks, that will help me...
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

Just a little update...

When I start Sally (my program) ScummVM is not directly started. Just the plugin is loaded and waits for the start of ScummVM. At this state you can't see the program in the volume control of vista (there you can see all program with audio output).
But when I start ScummVM it's shown in the list... so he starts some kind of audio interface - but don't sends anything.

I already debugged through some classes and compared the steps with the original ScummVM SDL. Here everything look good.

I think is some kind of SDL behaviour :(
As I mentioned, when I created the SDL window, I hear sound. Even it is not the used by ScummVM (I created a new one outside of ScummVM).

But I will not give up!! 8)
Last edited by Der_Knob on Wed Jan 13, 2010 8:37 pm, edited 1 time in total.
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

ok, I found a (solution) hack for this...

I set SDL_putenv("SDL_VIDEODRIVER=dummy"); and create the window as normal:

_hwscreen = SDL_SetVideoMode(hwW, hwH, 16,
_videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE

But it than opens no window (dummy video driver) and than I can still copy the content to my directx texture :?

I'm not sure if that is ... a ... good behaviour?!?!

But it is working 8)

Thanks all for the help so far!
In the new year I will come back to you because of cvs checkin and so on :)
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

On a different note... I just had a peek at this "Sally" project you want to integrate ScummVM into. While the page says that it is freeware, I see no link nor offer for source code, nor any reference to the GPL, so I assume that it is not an open source project.

So, just to avoid any bad mutual feelings in the future, I just wanted to point out that if you want to ever release what you are doing there to the public in the future, you'll of course have to comply to the GPL, and release the complete source code.

If you plan to release this as an open source plugin for the "Sally" project, then also note that this may not be legal if you are using dynamic linking (although the details may vary between countries, and also may depend on case law; see e.g. http://www.gnu.org/licenses/gpl-faq.html#GPLPluginsInNF )
User avatar
Der_Knob
Posts: 14
Joined: Mon Mar 19, 2007 11:22 am
Location: Germany
Contact:

Post by Der_Knob »

Thanks, I already thought about that... :D

1. I will offer ScummVM as a single Plugin. You can download it (from your side or so) and install it by double clicking. So it's not linked static. We have a full plugin engine where everyone can create new plugins. So it will not be included in the main pack.
I will of course open the source of the ScummVM plugin.

So, that should be no problem, or? It's like you are installing an application in windows or on the iPhone...

We have an API for the developers, but right now it is changing nearly every day => no docu is available. And the dev area on the homepage is in a very early stage... The API is only available on request.

2. I think we will put Sally an open source project to sourceforge. Right now I had no time to create a sourceforge project and put the stuff in there and so on... I'm have to do nearly the complete stuff (programming, webpage and so on) by my self :D

--- edit

The ScummVM Plugin for sally links dynamically the SallyAPI.dll... not the other way around. Sally don't know anything about the scummvm plugin (or any other plugin which is deliverd with it or downloaded).
So it Should be ok, as far as I understand the licence.
But I will check this again in the new year... I don't want to make any mistake here
Last edited by Der_Knob on Thu Dec 31, 2009 12:40 am, edited 3 times in total.
Post Reply