Volume Control
#1
Posted 06 February 2008 - 04:49 PM
Im pretty sure I can do this, but would modifying /dev/mixer override SDL and anything else and set the volume of all sound coming from the GP2X? In other words would it act like a master colume control?
#2
Posted 06 February 2008 - 05:54 PM
{
// Check the current volume is above 0
if(_CurrentVolume < MAX_VOLUME_LEVEL)
{
// Change the volume level up a notch
_CurrentVolume += 2;
Mix_VolumeMusic(_CurrentVolume);
}
}
void MusicManager::VolumeDown(void)
{
// Check the current volume is below 128
if(_CurrentVolume > MIN_VOLUME_LEVEL)
{
// Change the volume level up a notch
_CurrentVolume -= 2;
Mix_VolumeMusic(_CurrentVolume);
}
}
{
// Check the current volume is above 0
if(_CurrentVolume > MIN_VOLUME_LEVEL)
{
// Change the volume level down a notch
_CurrentVolume -= 2;
// For all Chunk wrappers
vector<ChunkWrapper *>::iterator Itr = _VectorOfChunkPointers.begin();
while(Itr != _VectorOfChunkPointers.end() )
{
// Check if a Chunk exists
if( (*Itr)->_MixChunk)
{
// If so, change the volume
(*Itr)->_MixChunk->volume = _CurrentVolume;
}
++Itr;
}
}
}
void SfxManager::VolumeUp(void)
{
// Check the current volume is below 128
if(_CurrentVolume < MAX_VOLUME_LEVEL)
{
// Change the volume level up a notch
_CurrentVolume += 2;
// For all Chunk wrappers
vector<ChunkWrapper *>::iterator Itr = _VectorOfChunkPointers.begin();
while(Itr != _VectorOfChunkPointers.end() )
{
// Check if a Chunk exists
if( (*Itr)->_MixChunk)
{
// If so, change the volume
(*Itr)->_MixChunk->volume = _CurrentVolume;
}
++Itr;
}
}
}
unsigned int CurrentInputState = _Kernel->GetInputManager()->GetCurrentInputState();
if( CurrentInputState & BUTTON_VOLUP )
{
_Kernel->GetSoundModuleWrapper()->GetMusicManager()->VolumeUp();
_Kernel->GetSoundModuleWrapper()->GetSfxManager()->VolumeUp();
}
if( CurrentInputState & BUTTON_VOLDOWN )
{
_Kernel->GetSoundModuleWrapper()->GetMusicManager()->VolumeDown();
_Kernel->GetSoundModuleWrapper()->GetSfxManager()->VolumeDown();
}
#3
Posted 06 February 2008 - 06:03 PM
If the /dev/mixer can control the volume of the entire system it will be a much quicker.
#4
Posted 07 February 2008 - 12:03 AM
This is the code I use to change volume:
// Check the current volume is above 0
if(_CurrentVolume < MAX_VOLUME_LEVEL)
// Check the current volume is below 128
if(_CurrentVolume > MIN_VOLUME_LEVEL)
You use some strangely misleading comments there... Maybe it's just me
#5
Posted 07 February 2008 - 01:10 AM
static void gp2x_set_volume(int newvol)
{
if ((newvol >= 0) && (newvol <= 100)) {
unsigned long soundDev = open("/dev/mixer", O_RDWR);
int vol = ((newvol << 8) | newvol);
ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
close(soundDev);
}
}
// Returns 0-100, current mixer volume, -1 on error.
static int gp2x_get_volume(void)
{
int vol = -1;
unsigned long soundDev = open("/dev/mixer", O_RDONLY);
if (soundDev)
{
ioctl(soundDev, SOUND_MIXER_READ_PCM, &vol);
close(soundDev);
if (vol != -1) {
//just return one channel , not both channels, they're hopefully the same anyways
return (vol & 0xFF);
}
}
return vol;
}
Edited by Senor Quack, 07 February 2008 - 02:25 AM.
#6
Posted 07 February 2008 - 01:57 AM
Yep, /dev/mixer is a more reliable way to set sound in a program in my experience:
Well that works sort of. With headphones on it changes the volume, but kills the right and only the left changes. Without headphones I can barely hear it, even going up to 100. Have you used this in any GP2X app's?
Edited by Pickle, 07 February 2008 - 01:57 AM.
#7
Posted 07 February 2008 - 02:14 AM
Yep, /dev/mixer is a more reliable way to set sound in a program in my experience:
Well that works sort of. With headphones on it changes the volume, but kills the right and only the left changes. Without headphones I can barely hear it, even going up to 100. Have you used this in any GP2X app's?
Sorry, I pasted the wrong version of the setvolume function, here is the correct one:
//DKS - new
static void gp2x_set_volume(int newvol)
{
if ((newvol >= 0) && (newvol <= 100)) {
unsigned long soundDev = open("/dev/mixer", O_RDWR);
int vol = ((newvol << 8) | newvol);
ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
close(soundDev);
}
}
Edited by Senor Quack, 07 February 2008 - 02:18 AM.
#8
Posted 07 February 2008 - 02:19 AM
#10
Posted 07 February 2008 - 03:47 AM
Yep, /dev/mixer is a more reliable way to set sound in a program in my experience:
*snip*
That's excellent! Thank you so much for sharing that
Well, in all honesty I think I got the code from an old post on here, maybe Squidge.
#11
Posted 07 February 2008 - 11:22 AM
This is the code I use to change volume:
// Check the current volume is above 0
if(_CurrentVolume < MAX_VOLUME_LEVEL)
// Check the current volume is below 128
if(_CurrentVolume > MIN_VOLUME_LEVEL)
You use some strangely misleading comments there... Maybe it's just me
Yeeeeeeeaaaahh... shhh......












