Help - Search - Members - Calendar
Full Version: Playing Sound, Controlling The Volume
OESF Forums > Distros, Development, and Model Specific Forums > Everything Development > Qt/Qtopia
speculatrix
I have successfully played sound like this...
CODE
#include <qsound.h>

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!
Meanie
QUOTE(speculatrix @ Feb 21 2007, 09:45 AM)
I have successfully played sound like this...
CODE
#include <qsound.h>

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!
*



you can use tkvol to change the volume from the command line. the code for tkvol is included in the zplayer source....
speculatrix
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
~/build/zplayer-0.1.1/tkmix> more qtopia_volume.cpp
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/soundcard.h>
#include <sys/ioctl.h>
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
#include <qpe/qcopenvelope_qws.h>

#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);
}
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.