Author Topic: Playing Sound, Controlling The Volume  (Read 6629 times)

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Playing Sound, Controlling The Volume
« on: February 20, 2007, 06:45:41 pm »
I have successfully played sound like this...
Code: [Select]
#include

QSound soundSample(Resource::findSound("wave"));
soundSample.play();


However, I am trying to set the volume control.. I have tried everything I can find from googling, but no joy!

If anyone has any ideas, I'd be terrible grateful!

Here's what I have so far:[/code]
    Config      cfgSound("Sound");
    cfgSound.setGroup("System");
    int oldVolume = cfgSound.readNumEntry("Volume", 0);
    cfgSound.writeEntry("Volume", 66);
    int newVolume = cfgSound.readNumEntry("Volume", 0);
    QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
[/code]

the code runs but the volume doesn't change..

reading it and calling readNumEntry then writeEntry then readNumEntry reveals the new value is accepted, but the volume level doesn't change!
« Last Edit: February 20, 2007, 06:46:04 pm by speculatrix »
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Playing Sound, Controlling The Volume
« Reply #1 on: February 21, 2007, 02:12:04 am »
Quote
I have successfully played sound like this...
Code: [Select]
#include

QSound soundSample(Resource::findSound("wave"));
soundSample.play();


However, I am trying to set the volume control.. I have tried everything I can find from googling, but no joy!

If anyone has any ideas, I'd be terrible grateful!

Here's what I have so far:[/code]
    Config      cfgSound("Sound");
    cfgSound.setGroup("System");
    int oldVolume = cfgSound.readNumEntry("Volume", 0);
    cfgSound.writeEntry("Volume", 66);
    int newVolume = cfgSound.readNumEntry("Volume", 0);
    QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
[/code]

the code runs but the volume doesn't change..

reading it and calling readNumEntry then writeEntry then readNumEntry reveals the new value is accepted, but the volume level doesn't change!
[div align=\"right\"][a href=\"index.php?act=findpost&pid=154831\"][{POST_SNAPBACK}][/a][/div]


you can use tkvol to change the volume from the command line. the code for tkvol is included in the zplayer source....
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Playing Sound, Controlling The Volume
« Reply #2 on: February 21, 2007, 07:27:06 am »
thanks for that... looks like he does an IOCTL on the mixer device and then tells qtopia of the change! so, I am guessing the proper way doesn't work... using google I only found a few places where the official way was discussed, and one comment said that TrollTech changed the interface from the proprietary/closed versions and the public GPL one.

I shall copy this technique, although as a programmer I'd prefer to learn the proper method so as to achieve device independence!
Code: [Select]
~/build/zplayer-0.1.1/tkmix> more qtopia_volume.cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include "qtopia_volume.h"

bool QtopiaVolume::setLevel(int level)
{
        int iDevice, isetlv = (level + (level << 8));

        // Set value
        if ((iDevice = open("/dev/mixer", O_RDONLY)) == -1) {
                qDebug("Syntax error in open device\n");
                return false;
        }
        if (ioctl(iDevice, MIXER_WRITE(0), &isetlv) == -1) {
                qDebug("Syntax error in set volume\n");
                return false;
        }

        // Update applet
        QCopEnvelope("QPE/System", "volumeChange(bool)") << FALSE;

        close(iDevice);

        return true;
}

int QtopiaVolume::getCurrentLevel()
{
        Config cfg("qpe");
        cfg.setGroup("Volume");
        return cfg.readNumEntry("VolumePercent", 0);
}
« Last Edit: February 21, 2007, 07:27:27 am by speculatrix »
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.