Re: volume control in FSO

2013-04-10 Thread Lukas Märdian
Am 08.04.2013 17:56, schrieb Rico Rommel:
 I think, the linear control is enough, but somebody else could see it 
 differently.

OK. I don't care currently, either. So we'll keep it like that for now.
But I've created a ticket, just for the reference:
  http://trac.freesmartphone.org/ticket/732

Lukas



signature.asc
Description: OpenPGP digital signature
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-04-08 Thread Rico Rommel
Am Freitag, 5. April 2013, 01:44:36 schrieb Lukas Märdian:
 Am 03.04.2013 22:28, schrieb Lukas Märdian:
  Unfortunately I had to find out, that there is another bug:
  FSO assumes the volume to be linear, whereas this isn't true for the
  human ear. I hope to have a look at this soon.
 
 Just for the reference, the difference between linear percentage (aka
 amixer) and human percentage (aka alsamixer) is described here:
 
 http://mailman.alsa-project.org/pipermail/alsa-devel/2012-March/050074.html
 
 FSO is currently using the aplay/linear percentage, whereas it would
 probably be convenient to use the alsamixer/human percentage.
 
 What do you think?

I think, the linear control is enough, but somebody else could see it 
differently.

Rico

signature.asc
Description: This is a digitally signed message part.
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-04-04 Thread Rico Rommel
Am Mittwoch, 3. April 2013, 22:28:44 schrieb Lukas Märdian:

 I've finally found some time again and coded a (pretty huge) helper
 function to translate the ID from the alsa CONTROL interface (scenario)
 to the alsa MIXER interface (which is used to set the volume).

Thanks, it works perfectly.

Rico

signature.asc
Description: This is a digitally signed message part.
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-04-04 Thread Lukas Märdian
Am 03.04.2013 22:28, schrieb Lukas Märdian:
 Unfortunately I had to find out, that there is another bug:
 FSO assumes the volume to be linear, whereas this isn't true for the
 human ear. I hope to have a look at this soon.

Just for the reference, the difference between linear percentage (aka
amixer) and human percentage (aka alsamixer) is described here:

http://mailman.alsa-project.org/pipermail/alsa-devel/2012-March/050074.html

FSO is currently using the aplay/linear percentage, whereas it would
probably be convenient to use the alsamixer/human percentage.

What do you think?

Cheers,
  Lukas



signature.asc
Description: OpenPGP digital signature
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-04-03 Thread Lukas Märdian
Am 19.03.2013 14:20, schrieb Rico Rommel:
 attached is a patch, which should apply cleanly atop of the 0.12 branch
 of cornucopia.

 I do not yet understand all the alsa stuff, but this first patch seems
 to fix the issue on my laptop. Could you please try, if it fixes your
 use case as well?

 Please comment on any problems you see. I'll try to clean it up and push
 it into git after my vacations.
 
 It basically works now, good job. But I wonder, if I have to set volume now 
 in 
 the range of the mixer element absolute or as a percentage.

Hey Rico!

I've finally found some time again and coded a (pretty huge) helper
function to translate the ID from the alsa CONTROL interface (scenario)
to the alsa MIXER interface (which is used to set the volume).

An alsa expert could maybe have done it in a few LOC :-/, but no one
responded to my questions in #alsa.

It is working correctly on my Laptop, we can now set the volume in a
range of 0..100. If you've tested the attached patch to be OK I'd like
to push it to the git repo.

Unfortunately I had to find out, that there is another bug:
FSO assumes the volume to be linear, whereas this isn't true for the
human ear. I hope to have a look at this soon.

BR,
  Lukas
From 0dc49459a92fd45e356f6a015ff52a5189b225b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= l...@slyon.de
Date: Mon, 18 Mar 2013 17:43:45 +0100
Subject: [PATCH] fsodeviced: fix get/set main_volume
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Lukas Märdian l...@slyon.de
---
 fsodeviced/src/lib/alsa.vala   |   83 
 fsodeviced/src/plugins/router_alsa/plugin.vala |3 +-
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/fsodeviced/src/lib/alsa.vala b/fsodeviced/src/lib/alsa.vala
index 4029837..acf545a 100644
--- a/fsodeviced/src/lib/alsa.vala
+++ b/fsodeviced/src/lib/alsa.vala
@@ -325,6 +325,89 @@ public class FsoDevice.SoundDevice : FsoFramework.AbstractObject
 mel.get_playback_volume_range( out min, out max );
 mel.set_playback_volume_all( min + val * ( max-min ) / 100 );
 }
+
+/**
+ * Lookup mixer ID (mixer interface) for scenario ID (control interface)
+ * @return corresponding mixer ID for given scenario ID, fallback to 'Master' if nothing found
+ **/
+public uint getMixerVolumeId(MixerControl[] controls, uint idx)
+{
+uint numid;
+string description;
+string source = ;
+foreach ( FsoDevice.MixerControl control in controls )
+{
+numid = (uint)int.parse( control.to_string().split( : )[0] );
+description = control.to_string().split( : )[1];
+int len = description.length;
+//cut leading and trailing prime (') if existent, e.g. 'Master Playback Volume' = Master Playback Volume
+if ( description[0] == '[0]  description[len-1] == '[0] )
+description = description[1:-1];
+
+len = description.split(   ).length;
+if ( numid == idx  len = 3)
+{
+string direction = description.split(   )[len-2];
+string function = description.split(   )[len-1];
+debug ( @$numid, $direction, $function );
+
+//we're only interested in xxx Playback Volume controls (SOURCE DIRECTION FUNCTION)
+if ( direction == Playback  function == Volume )
+{
+string[] s = description.split(   );
+s = s[0:len-2];
+source = string.joinv (  , s );
+debug ( @control SOURCE: $source );
+break;
+}
+}
+}
+if ( source !=  )
+{
+Alsa.Mixer mix;
+Alsa.Mixer.open( out mix );
+assert( mix != null );
+mix.attach( cardname );
+mix.register();
+mix.load();
+
+Alsa.SimpleElementId seid;
+Alsa.SimpleElementId.alloc(out seid);
+
+Alsa.MixerElement mel = mix.first_elem();
+if( mel == null )
+{
+warning( mix.first_elem() returned NULL );
+return 0;
+}
+int i = 0;
+mel.get_id(seid);
+
+//look for the mixer element with the same name as the control source
+while ( seid.get_name() != source )
+{
+mel = mel.next();
+assert( mel != null );
+mel.get_id(seid);
+i++;
+}
+if ( mel != null )
+{
+debug( @mixer name: $(seid.get_name()) );
+return i;
+}
+else
+{
+warning( @main_volume=$(idx) doesn't match any mixer element. Falling back to 'Master'. );
+return 0;
+}
+  

Re: volume control in FSO

2013-04-03 Thread Lukas Märdian
Am 03.04.2013 22:28, schrieb Lukas Märdian:
 I've finally found some time again and coded a (pretty huge) helper
 function to translate the ID from the alsa CONTROL interface (scenario)
 to the alsa MIXER interface (which is used to set the volume).
 
 An alsa expert could maybe have done it in a few LOC :-/, but no one
 responded to my questions in #alsa.
 
 It is working correctly on my Laptop, we can now set the volume in a
 range of 0..100. If you've tested the attached patch to be OK I'd like
 to push it to the git repo.
 
 Unfortunately I had to find out, that there is another bug:
 FSO assumes the volume to be linear, whereas this isn't true for the
 human ear. I hope to have a look at this soon.

forgot to mention:
I've found out how to map CONTROL-MIXER interface here:
http://www.alsa-project.org/~tiwai/writing-an-alsa-driver/ch06s03.html

One can just decode the name of the control, which consists of 3 parts:
SOURCE, DIRECTION, FUNCTION, whereas DIRECTION has to do be 'Playback'
for our volume needs and FUNCTION has to be 'Volume'. The first part
left is the name which corresponds to the name of the MIXER.



signature.asc
Description: OpenPGP digital signature
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-19 Thread Rico Rommel
Am Montag, 18. März 2013, 17:48:28 schrieb Lukas Märdian:
 Am 17.03.2013 20:31, schrieb Lukas Märdian:
  So there's definitely something wrong in the alsa router.
 
  Can you or somebody else provide a patch? I have no idea how to solve
  this.
 
  I'm not sure how to fix this either, but I'll try to have a deeper look
  before my vacation (still few days left). I hope I'll be able to provide
  a patch for it soon.

 Hi Rico,

 attached is a patch, which should apply cleanly atop of the 0.12 branch
 of cornucopia.

 I do not yet understand all the alsa stuff, but this first patch seems
 to fix the issue on my laptop. Could you please try, if it fixes your
 use case as well?

 Please comment on any problems you see. I'll try to clean it up and push
 it into git after my vacations.

It basically works now, good job. But I wonder, if I have to set volume now in
the range of the mixer element absolute or as a percentage.

Rico

signature.asc
Description: This is a digitally signed message part.
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-18 Thread Lukas Märdian
Am 07.03.2013 18:16, schrieb Rico Rommel:
 mel.next() returns mixerelements in this (alphabetical) order so they don't 
 match the control ids in the scenario-config:
 
 Analog
 Analog Left AUXL
 Analog Left Carkit Mic
 Analog Left Headset Mic
 Analog Left Main Mic
 Analog Right AUXR
 Analog Right Sub Mic
 Carkit
 CarkitL Mixer AudioL1
 CarkitL Mixer AudioL2
 CarkitL Mixer Voice
 CarkitR Mixer AudioR1
 CarkitR Mixer AudioR2
 CarkitR Mixer Voice
 Codec Operation Mode
 DAC Voice Analog Downlink
 DAC Voice Digital Downlink
 ...

How did you retrieve those names? I assume those are SimpleElemntIds?

Using this names, we can probably just compare the name we get from the
alsa_router plugin with the names from this list and look for the
correct control.

Lukas



signature.asc
Description: OpenPGP digital signature
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-18 Thread Lukas Märdian
Am 17.03.2013 20:31, schrieb Lukas Märdian:
 So there's definitely something wrong in the alsa router.

 Can you or somebody else provide a patch? I have no idea how to solve this.
 
 I'm not sure how to fix this either, but I'll try to have a deeper look
 before my vacation (still few days left). I hope I'll be able to provide
 a patch for it soon.

Hi Rico,

attached is a patch, which should apply cleanly atop of the 0.12 branch
of cornucopia.

I do not yet understand all the alsa stuff, but this first patch seems
to fix the issue on my laptop. Could you please try, if it fixes your
use case as well?

Please comment on any problems you see. I'll try to clean it up and push
it into git after my vacations.

Cheers,
  Lukas
From d97a178308a0596d37bff4f3ad081398c3335513 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20M=C3=A4rdian?= l...@slyon.de
Date: Mon, 18 Mar 2013 17:43:45 +0100
Subject: [PATCH] fsodeviced: fix get/set main_volume
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Lukas Märdian l...@slyon.de
---
 fsodeviced/src/lib/alsa.vala   |   38 
 fsodeviced/src/plugins/router_alsa/plugin.vala |7 +++--
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/fsodeviced/src/lib/alsa.vala b/fsodeviced/src/lib/alsa.vala
index 4029837..dd8e723 100644
--- a/fsodeviced/src/lib/alsa.vala
+++ b/fsodeviced/src/lib/alsa.vala
@@ -296,6 +296,44 @@ public class FsoDevice.SoundDevice : FsoFramework.AbstractObject
 return (uint8) Math.round(( (val-min) * 100 / (double)( max-min ) ) );
 }
 
+public uint8 getVolume( BunchOfMixerControls scenario )
+{
+uint idx = scenario.idxMainVolume;
+MixerControl[] controls = scenario.controls;
+
+for ( int i = 0; i  controls.length; ++i )
+{
+var type = controls[i].info.get_type();
+if ( controls[i].eid.get_numid() == idx  type == ElemType.INTEGER )
+{
+debug( @getVolume: $(controls[i]) );
+//FIXME: what about controls with more than 1 value? (controls[i].info.get_count()  1)
+return (uint8)controls[i].value.get_integer(0);
+}
+}
+
+warning( @main_volume with id $idx not found );
+return 0;
+}
+
+public void setVolume( BunchOfMixerControls scenario, uint8 vol )
+{
+uint idx = scenario.idxMainVolume;
+MixerControl[] controls = scenario.controls;
+
+for ( int i = 0; i  controls.length; ++i )
+{
+var type = controls[i].info.get_type();
+if ( controls[i].eid.get_numid() == idx  type == ElemType.INTEGER )
+{
+//FIXME: what about controls with more than 1 value? (controls[i].info.get_count()  1)
+controls[i].value.set_integer(0, (long)vol);
+setControl(controls[i]);
+debug( @setVolume: $(controls[i]) );
+}
+}
+}
+
 /**
  * @set volume percent for mixer element with @a id
  **/
diff --git a/fsodeviced/src/plugins/router_alsa/plugin.vala b/fsodeviced/src/plugins/router_alsa/plugin.vala
index 7cfb445..e273807 100644
--- a/fsodeviced/src/plugins/router_alsa/plugin.vala
+++ b/fsodeviced/src/plugins/router_alsa/plugin.vala
@@ -317,15 +317,16 @@ class LibAlsa : FsoDevice.BaseAudioRouter
 {
 var scenario = allscenarios[currentscenario];
 assert( scenario != null );
-
-return device.volumeForIndex( scenario.idxMainVolume );
+//return device.volumeForIndex( scenario.idxMainVolume );
+return device.getVolume( scenario );
 }
 
 public override void setVolume( uint8 volume ) throws FreeSmartphone.Error
 {
 var scenario = allscenarios[currentscenario];
 assert( scenario != null );
-device.setVolumeForIndex( scenario.idxMainVolume, volume );
+//device.setVolumeForIndex( scenario.idxMainVolume, volume );
+device.setVolume( scenario, volume );
 }
 
 public override string repr()
-- 
1.7.9.5



signature.asc
Description: OpenPGP digital signature
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-18 Thread Rico Rommel
Am Montag, 18. März 2013, 17:48:28 schrieb Lukas Märdian:
 Am 17.03.2013 20:31, schrieb Lukas Märdian:
  So there's definitely something wrong in the alsa router.
 
  Can you or somebody else provide a patch? I have no idea how to solve
  this.
 
  I'm not sure how to fix this either, but I'll try to have a deeper look
  before my vacation (still few days left). I hope I'll be able to provide
  a patch for it soon.

 Hi Rico,

 attached is a patch, which should apply cleanly atop of the 0.12 branch
 of cornucopia.

 I do not yet understand all the alsa stuff, but this first patch seems
 to fix the issue on my laptop. Could you please try, if it fixes your
 use case as well?

 Please comment on any problems you see. I'll try to clean it up and push
 it into git after my vacations.

Thanks, i will try it next days.

Rico

signature.asc
Description: This is a digitally signed message part.
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-17 Thread Lukas Märdian
Am 13.03.2013 18:39, schrieb Rico Rommel:
 mel.next() returns mixerelements in this (alphabetical) order so they
 don't match the control ids in the scenario-config:

You're right. The mixer controls in src/lib/alsa.vala seem to have
different IDs from the controls in src/plugins/router_alsa/plugin.vala.

Thanks for spotting this!

 So there's definitely something wrong in the alsa router.
 
 Can you or somebody else provide a patch? I have no idea how to solve this.

I'm not sure how to fix this either, but I'll try to have a deeper look
before my vacation (still few days left). I hope I'll be able to provide
a patch for it soon.

Regards,
  Lukas



signature.asc
Description: OpenPGP digital signature
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-07 Thread Rico Rommel
Am Donnerstag, 7. März 2013, 10:30:30 schrieb Lukas Märdian:

 Maybe you can use this command, to export your current scenario and
 compare them?

 mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio
 org.freesmartphone.Device.Audio.SaveScenario stereoout

 For further information you could read this document:
   http://wiki.freesmartphone.org/index.php/AlsaScenarios

That doesn't point the problem.

I did some debugging in alsa.vala:

I set main_volume = 2 and expect in setVolumeForIndex() as mixerelement 'DAC1
Digital Fine Playback Volume', but I get 'Analog Left AUXL'

main_volume = 3
expected: 'DAC2 Digital Fine Playback Volume'
got: 'Analog Left Carkit Mic'

main_volume = 4
expected: 'DAC1 Digital Coarse Playback Volume'
got: 'Analog Left Headset Mic'

...


mel.next() returns mixerelements in this (alphabetical) order so they don't
match the control ids in the scenario-config:

Analog
Analog Left AUXL
Analog Left Carkit Mic
Analog Left Headset Mic
Analog Left Main Mic
Analog Right AUXR
Analog Right Sub Mic
Carkit
CarkitL Mixer AudioL1
CarkitL Mixer AudioL2
CarkitL Mixer Voice
CarkitR Mixer AudioR1
CarkitR Mixer AudioR2
CarkitR Mixer Voice
Codec Operation Mode
DAC Voice Analog Downlink
DAC Voice Digital Downlink
...

One Problem may be, that setVolumeForIndex() and volumeForIndex() are using
Alsas Simple Mixer Interface while scenario settings are using the usual mixer
interface.

Btw, does it work in SHR?

Rico

signature.asc
Description: This is a digitally signed message part.
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-07 Thread Rico Rommel
Am Donnerstag, 7. März 2013, 18:28:41 schrieb Lukas Märdian:
 Ouch, that doesn't look good.
 Could you describe a simple test case, so I can try it in SHR?

mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio
org.freesmartphone.Device.Audio.GetVolume

returns 0

mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio
org.freesmartphone.Device.Audio.SetVolume 50


mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio
org.freesmartphone.Device.Audio.GetVolume

returns 0 again



another one:

in /etc/freesmartphone/GTA04/alsa.conf

# PCM
[scenario.stereoout]
main_volume = 7

(this should be 'DAC2 Analog Playback Volume')

mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio
org.freesmartphone.Device.Audio.GetVolume

returns 0

mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio
org.freesmartphone.Device.Audio.SetVolume 50


mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio
org.freesmartphone.Device.Audio.GetVolume

returns 0 again


signature.asc
Description: This is a digitally signed message part.
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-07 Thread Lukas Märdian
Am 07.03.2013 18:39, schrieb Rico Rommel:
 Am Donnerstag, 7. März 2013, 18:28:41 schrieb Lukas Märdian:
 Ouch, that doesn't look good.
 Could you describe a simple test case, so I can try it in SHR?
 
 mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio 
 org.freesmartphone.Device.Audio.GetVolume
 
 returns 0
 
 mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio 
 org.freesmartphone.Device.Audio.SetVolume 50
 
 
 mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio 
 org.freesmartphone.Device.Audio.GetVolume 
 
 returns 0 again

Unfortunately, I can confirm that it doesn't work on SHR as well.

 another one:
 
 in /etc/freesmartphone/GTA04/alsa.conf
 
 # PCM
 [scenario.stereoout]
 main_volume = 7
 
 (this should be 'DAC2 Analog Playback Volume')
 
 mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio 
 org.freesmartphone.Device.Audio.GetVolume 
 
 returns 0
 
 mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio 
 org.freesmartphone.Device.Audio.SetVolume 50
 
 
 mdbus2 -s org.freesmartphone.odeviced /org/freesmartphone/Device/Audio 
 org.freesmartphone.Device.Audio.GetVolume 
 
 returns 0 again

This doesn't work either.

So there's definitely something wrong in the alsa router.

BR,
  Lukas



signature.asc
Description: OpenPGP digital signature
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland


Re: volume control in FSO

2013-03-06 Thread Rico Rommel
Am Dienstag, 5. März 2013, 20:41:44 schrieb Rico Rommel:
 Hi,

 SetVolume via fsodeviced doesn't work for me on GTA04 , beacuse there is no
 / a wrong main volume setting.
 In the source code of router_alsa I found an option called main_volume.
 But I'm not quite clear, where to set this option. Do I have to set this in
 alsa.conf for each scenario?

I'm answering myself:
It has to be set for each scenario.

But now there is a bigger problem:

The number in the scenario file does'nt match the number in class Alsa.Mixer.
It seems, Alsa.Mixer contains a alphabetical ordered list of controls, while
scenario settings are numerical ordered. So the index of one control in both
list isn't the same and it doesn't work at all or you have to find out, which
number in Alsa.Mixer hits the one in the alsa/scenario-settings.

It looks like a bug in lib/alsa.vala.

Rico

signature.asc
Description: This is a digitally signed message part.
___
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland