Author Topic: workaround for the "no digital sound" crash  (Read 4875 times)

workaround for the "no digital sound" crash
« on: 18 May 2015, 16:41 »
Without starting another discussion about what AGS should and should not do, I'm trying to find a workaround for the sound issue discussed in this thread. I.e. if "no digital sound" option is chosen in the setup, the code below will make your game crash.
Code: Adventure Game Studio
  1. AudioChannel *audio = aMusic.Play();
  2. audio.Volume = 70;
...unless you wrap everything in a "if(audio){}" which is too much work for me at this point.

I suppose there is no way of checking if this option is chosen, from within an ags-application? Could I do this by raw reading acetup.cfg? (been unsuccessful so far) Changing the name of audio.vox with a custom setup could do the trick, since ags can check for files. Any obvious dangers there? (such as windows security)

Thanks.

Wyz

  • AGS Project Tracker Admins
  • anno 1986
    • I can help with making music
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Re: workaround for the "no digital sound" crash
« Reply #1 on: 18 May 2015, 17:12 »
Without making any changes to the engine the best I can come up with is a wrapper object. This is structure that you assign an AudioChannel object and implements all functionality that AudioChannel objects already have but with the added null check.

For this example it would contain the following:
Code: Adventure Game Studio
  1. struct SafeAudioChannel
  2. {
  3.   AudioChannel *audio;
  4.  
  5.   void SetVolume(int volume)
  6.   {
  7.     if (audio)
  8.       audio.Volume = volume;
  9.   }
  10.  
  11.   int GetVolume(int volume)
  12.   {
  13.     if (audio)
  14.       return audio.Volume;
  15.     return -1;
  16.   }
  17.  
  18.   // ... many more potentially
  19. };
  20.  

Which you can use like this:
Code: Adventure Game Studio
  1. SafeAudioChannel channel;
  2. channel.audio = aMusic.Play();
  3. channel.SetVolume(70);
  4.  

Would be nice to have this as a module I guess. :)
« Last Edit: 18 May 2015, 17:44 by Wyz »
Life is like an adventure without the pixel hunts.

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: workaround for the "no digital sound" crash
« Reply #2 on: 18 May 2015, 17:17 »
Should be AudioChannel* audio; – but yeah.

Re: workaround for the "no digital sound" crash
« Reply #3 on: 18 May 2015, 21:23 »
Interesting.
Could this be done with already defined global AudioChannels as well?

Wyz

  • AGS Project Tracker Admins
  • anno 1986
    • I can help with making music
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Re: workaround for the "no digital sound" crash
« Reply #4 on: 19 May 2015, 01:24 »
I believe so yes. It would need the usual im/exporting and setting up like other global variables but I can't think of a reason why not.
Life is like an adventure without the pixel hunts.

Re: workaround for the "no digital sound" crash
« Reply #5 on: 19 May 2015, 17:29 »
Thanks Wyz.
Unfortunately, it seems that this solution was horrible to implement in retrospect. I will have to go for bracket wrapping this time, but any new project will have safe audio structs for sure. ...that is, if nobody makes it even easier and writes a module -COUGH!-

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: workaround for the "no digital sound" crash
« Reply #6 on: 19 May 2015, 17:51 »
Unfortunately, it seems that this solution was horrible to implement in retrospect.

How so? Seems to me that there should only be two or three steps to it:

1. Create the struct type like Wyz outlines, wrapping all the API methods you need.
2. If you have any AudioChannel* globalvars, change them to regular variables exported by a script and imported in the header.
3. Change every AudioChannel* declaration to a SafeAudioChannel declaration.

The only possible problem I can see is if you've been passing AudioChannel* variables as arguments to functions, or had them as members of other structs.

Re: workaround for the "no digital sound" crash
« Reply #7 on: 19 May 2015, 22:03 »
It's hard because my script is a mess, but I think I got it. :)
Quote
The only possible problem I can see is if you've been passing AudioChannel* variables as arguments to functions...
Well, sort of. At least now I know this is bad practice.

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: workaround for the "no digital sound" crash
« Reply #8 on: 19 May 2015, 22:36 »
No, not necessarily. It's just that it interferes with this particular workaround because of one of the most frustrating limitations in the AGS scripting language.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: workaround for the "no digital sound" crash
« Reply #9 on: 02 Jun 2015, 01:09 »
You can also use helper functions like
Code: Adventure Game Studio
  1. AudioChannel *SafePlayAtVolume(AudioClip *clip, int volume)
  2. {
  3.     AudioChannel *ch = clip.Play();
  4.     if (ch)
  5.         ch.Volume = volume;
  6.     return ch;
  7. }
  8.  

Re: workaround for the "no digital sound" crash
« Reply #10 on: 03 Jun 2015, 23:41 »
Well that looks simple enough.
Will definitely try it out.