Single button/command to switch audio output between analog, digital?
#1
First up, I'm not sure if this should be in "Support" or "Feature requests", so please move if it's in the wrong spot.

I've searched around and seen this discussed a few times, but the threads seem to peter out with no real solution given.

eg these threads:

http://forum.xbmc.org/showthread.php?tid...tal+button
http://forum.xbmc.org/showthread.php?tid...og+digital

Basically, I want to be able to easily switch the audio output between analog (when using TV speakers) and digital (when using receiver for audio). I know it can be done through the OSD, but I want to be able to integrate the switching in to a macro for my universal remote (Harmony).

Ideally I would like a command to select Analog, and a separate command to select Digital (ie discretes), but a toggle command would be almost as good, and still much better than the current menu system.

Does the fact that this feature has been requested a few times, but not implemented (to my knowledge), mean this is difficult to achieve, or is it just that there isn't enough interest? (I thought it would be a pretty popular feature??)

I don't like to ask for things from others without making an effort to help out myself, so any assistance anyone can give me in implementing this feature myself would be grealy appreciated. Just be aware I know absolutely nothing about "coding", and don't have a great deal of spare time to learn!

How do functions get added to the list of available functions in keymap.xml? Is it relatively easy to add any selection/command available within XBMC menus, or are there certain things that just can't be added to the keymap commands?

Is this the sort of thing a clueless end-user such as myself should even think about attempting, or do you need to be a developer with a degree in Computer Science to tackle it?
Reply
#2
moved to feature requests... xbmc's source code can be quite intimidating. in buttontranslator.cpp, you'll find the button and action definitions. you'll need to add a new action. then that action will need to be tied to the setting that switches the audio output. this would probably be best done as a global action in application.cpp. the in gui settings are in guisettings.cpp. if you look there, you can figure out what the option is called. where there will be an issue is with the ac3 & dts passthru. those options are only available when digital out is enabled. you can see how thats done in guiwindowsettingscategory.cpp.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#3
Thanks for that...I'm intimidated already!

I'll have a look at the things you mentioned, and see what I can come up with. I'm thinking I'll need more of a "Coding 101" lesson first though Smile
Reply
#4
i moved the thread into the dev forum. you can keep asking for questions and pointers there.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#5
Ok....I've been looking through the areas you pointed me to, but I think I'm going to need a lot more help Blush.

What I think I've figured out:

I need to create a new action (or 2) in Application.cpp
eg:
Quote:if (action.wID == ACTION_SET_AUDIO_ANALOG)
{
Something in here to set audio output to Analog;
return true;

if (action.wID == ACTION_SET_AUDIO_DIGITAL)
{
Something in here to set audio output to Digital;
return true;

I then need to assign a command to those actions in buttontranslator.cpp

eg:
Quote:else if (strAction.Equals("AudioAnalog")) wAction = ACTION_SET_AUDIO_ANALOG;
else if (strAction.Equals("AudioDigital")) wAction = ACTION_SET_AUDIO_DIGITAL;

Then I can assign a remote button to those commands in keymap.xml

eg:
Quote:<5>AudioAnalog</5>
<7>AudioDigital</7>
would make the "5" button on the remote set Analog audio, and "7" set Digital audio.

Am I on the right track?

Where I'm stuck is the part to put in application.cpp to actually SET the audio output type.
I found this in GUISettings.cpp:
Quote:AddCategory(4, "audiooutput", 772);
AddInt(3, "audiooutput.mode", 337, AUDIO_ANALOG, AUDIO_ANALOG, 1, AUDIO_DIGITAL, SPIN_CONTROL_TEXT);
AddBool(4, "audiooutput.ac3passthrough", 364, true);
AddBool(5, "audiooutput.dtspassthrough", 254, true);
Which seems to be what I'm after, but I don't know how to make that in to discrete functions in application.cpp?

I also found audio output settings in other areas, such as Settings.cpp and SettingsControls.cpp. If I add what I'm thinking to Application.cpp will it break something if I don't make matching changes in all other areas?

Also, what is the difference/signifigance of the matching ".h" extensions? eg Application.cpp and Application.h? This is just for my curiosity I guess.

I'm starting to think I'm getting in way over my head hereShocked Huh
Reply
#6
Yes - your thinking is pretty much bang on. Take a look at the code in GUIDialogAudioSettings::OnSettingChanged()

Code:
else if (setting.id == AUDIO_SETTINGS_DIGITAL_ANALOG)
  {
    if(m_outputmode == 0) // might be unneccesary (indexes match), but just for clearity
      g_guiSettings.SetInt("audiooutput.mode", AUDIO_ANALOG);
    else
      g_guiSettings.SetInt("audiooutput.mode", AUDIO_DIGITAL);

    EnableSettings(AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS, g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL);
    g_application.Restart();
  }

I'd also do this in GUIWindowFullScreen.cpp personally, rather than in Application.cpp - I presume you only want to switch it while watching a video? If not, then Application.cpp makes more sense.

A .h file is normally a header file, which normally contains the class declarations and function prototypes (declarations), whereas the .cpp files contain the implementation (definition). It's really just a way to keep separation between the interface that parts of the program should be exposed to, and parts that implement the interface.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#7
I'm not sure if this is right but perhaps a dev can have a look at it.

Code:
if (action.wID == ACTION_SET_AUDIO_ANALOG)
  {
    if (g_guiSettings.GetInt("audiooutput.mode") == AUDIO_ANALOG);
        return true;
    else
    {
        g_guiSettings.SetInt("audiooutput.mode", AUDIO_ANALOG);
        EnableSettings(AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS, g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL);
        g_application.Restart();
        return true;
    }
  }
  if (action.wID == ACTION_SET_AUDIO_DIGITAL)
  {
    if (g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL);
        return true;
    else
    {
        g_guiSettings.SetInt("audiooutput.mode", AUDIO_DIGITAL);
        EnableSettings(AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS, g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL);
        g_application.Restart();
        return true;
    }
  }
Reply
#8
Obviously EnableSettings() can't be called, and you don't need g_application in front of the Restart() call.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#9
ok so do you need the EnableSettings() at all? I really did not get what it was doing.

is this enough?
Code:
g_guiSettings.SetInt("audiooutput.mode", AUDIO_DIGITAL);
Restart();
return true;

or can you do something like GUIDialogAudioSubtitleSettings::EnableSettings()
Reply
#10
Maybe you need Restart(true); aswell? or does it default to true?
Reply
#11
The code snippet you pasted is fine.

The EnableSettings() code is just to update the other audio settings in the audio settings dialog (i.e. from a looks perspective - some have to be disabled if you're using analog out), so it doesn't apply here.

And yes, the default for Restart() is true (see Application.h).

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#12
see, even cut'n'paste "coders" can do some good
Smile
Reply
#13
Star 
And for a singlebutton approach:

if (action.wID == ACTION_SWITCH_AUDIO_OUTPUT_MODE)
{
if (g_guiSettings.GetInt("audiooutput.mode") == AUDIO_ANALOG)
g_guiSettings.SetInt("audiooutput.mode", AUDIO_DIGITAL);
else
g_guiSettings.SetInt("audiooutput.mode", AUDIO_ANALOG);

Restart();
return true;
}
Reply
#14
Thanks for the suggestions

@jmarshall: I was looking at Application.cpp only because kraqh3d suggested it. However, I want to make the setting part of a Power On/Activity Start macro on my remote, so from what you said Application.cpp would be the correct place anyway?

@Watzen: That looks like it makes sense, even to me! Just a couple of questions... What is the "g_application.Restart()" part for? Does that mean it's going to restart XBMC everytime I make this selection?
Also, the "EnableSettings(AUDIO_SETTINGS_OUTPUT_TO_ALL_SPEAKERS" part... I'm not really sure what this is saying. Does it just mean the option to select "Output to all speakers" will be made available, or will it actually set to output to all speakers.

This brings up another question that kraqh3d touched on earlier...
With the options for passthrough of DD/DTS, I personally will ALWAYS want to passthrough DD and DTS when using Digital output. Can I set this to always be enabled when digital audio is enabled? Will this cause problems elsewhere?
I guess this is kind of a question about "coding etiquette" too. Am I expected to be writing these changes with only myself in mind, or do I need to consider these changes may be added to the main SVN, and will therefore need to cater to everyone? Would the devs even trust a mug like me to do that??

One more question I've got. Assuming I'm doing these changes only for myself, does this mean I'll have to add these bits of code and do my own compiling every time I update from now on? Up until now I've been using the T3CH releases which add a few nice goodies. I'd like to keep using them if possible...is there a way to add my changes to the T3CH releases I download?
Reply
#15
Sorry about second post....no edit availableHuh

I actually started writing my reply just after watzen's first post, but had to go and feed a baby, have dinner and put 2 year old to bed in the middle of writing it...did I mention I get bugger all time to do this stuff??

Thanks for all the suggestions. It looks like the basics are now covered. Id still like to know about the DD/DTS passthrough question though. If I just set those once using the GUI, will those settings be subsequently "remembered" using the approach above?

Also, does it matter where in Application.cpp I put those lines? I was thinking of putting it about halfway in, just after the "Take a screenshot" section. Would this be suitable? I think it's a "global" area?
Reply

Logout Mark Read Team Forum Stats Members Help
Single button/command to switch audio output between analog, digital?0