forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Volume SFX Control

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
yeshua



Joined: 30 Nov 2009
Posts: 20

PostPosted: Wed Dec 09, 2009 6:05 am    Post subject: Volume SFX Control Reply with quote

So I'm helping improve the JGE engine that we either broke or didn't work to begin with. Either way I'm trying to add volume control to SFX.

if I set volume straight on here without calling anything or using vars it works...
But we cant do that...
Code:
 
JMP3::init();
  pspAudioInit();
  JMP3 * sfx = JMP3::mInstance;
   if (sfx) sfx->pspSetSfxVol();
   pspAudioSetChannelCallback(0, audioOutCallback_0, NULL);
   pspAudioSetChannelCallback(1, audioOutCallback_1, NULL);
   pspAudioSetChannelCallback(2, audioOutCallback_2, NULL);
}


Also pspSetSfxVol() does this

Code:

void JMP3::pspSetSfxVol() {
  int i = 0;
  for(i = 0;i<3;i++)
    pspAudioSetVolume(i, m_sfxvolume, m_sfxvolume);
}



and m_sfxvolume is set by Jmp3 when you call

Code:

void JSoundSystem::SetSfxVolume(int volume)
{
  JMP3 * sfx = JMP3::mInstance;
   if (sfx) sfx->setSfxVolume(volume);
}


and all setSfxVolume(volume) does is:

Code:

int JMP3::setSfxVolume(int volume) {
   return (m_sfxvolume = volume);
}


According to the sample in the sdk

Code:
pspAudioInit();
   pspAudioSetVolume(0, 0x4000, 0x4000);
   pspAudioSetVolume(1, 0x4000, 0x4000);
   pspAudioSetChannelCallback(0, audioOutCallback0, NULL);
   pspAudioSetChannelCallback(1, audioOutCallback1, NULL);


This should work...
Back to top
View user's profile Send private message
yeshua



Joined: 30 Nov 2009
Posts: 20

PostPosted: Wed Dec 09, 2009 6:40 am    Post subject: Reply with quote

I tried removing it from the class and using an external variable didnt work.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Dec 09, 2009 9:47 am    Post subject: Re: Volume SFX Control Reply with quote

yeshua wrote:
So I'm helping improve the JGE engine that we either broke or didn't work to begin with. Either way I'm trying to add volume control to SFX.

if I set volume straight on here without calling anything or using vars it works...
But we cant do that...
Code:
 
JMP3::init();
  pspAudioInit();
  JMP3 * sfx = JMP3::mInstance;
   if (sfx) sfx->pspSetSfxVol();
   pspAudioSetChannelCallback(0, audioOutCallback_0, NULL);
   pspAudioSetChannelCallback(1, audioOutCallback_1, NULL);
   pspAudioSetChannelCallback(2, audioOutCallback_2, NULL);
}


Also pspSetSfxVol() does this

Code:

void JMP3::pspSetSfxVol() {
  int i = 0;
  for(i = 0;i<3;i++)
    pspAudioSetVolume(i, m_sfxvolume, m_sfxvolume);
}



and m_sfxvolume is set by Jmp3 when you call

Code:

void JSoundSystem::SetSfxVolume(int volume)
{
  JMP3 * sfx = JMP3::mInstance;
   if (sfx) sfx->setSfxVolume(volume);
}


and all setSfxVolume(volume) does is:

Code:

int JMP3::setSfxVolume(int volume) {
   return (m_sfxvolume = volume);
}


According to the sample in the sdk

Code:
pspAudioInit();
   pspAudioSetVolume(0, 0x4000, 0x4000);
   pspAudioSetVolume(1, 0x4000, 0x4000);
   pspAudioSetChannelCallback(0, audioOutCallback0, NULL);
   pspAudioSetChannelCallback(1, audioOutCallback1, NULL);


This should work...


Well... the problem is... you (or maybe the creator of jge) seem to misunderstand what pspAudioSetVolume does/how it handles the paramters given or possibly even: How variables really work.
Calling pspAudioSetVolume(i, m_sfxvolume, m_sfxvolume); once on startup and then changing the value of m_sfxvolume during runtime won't change the volume then (since you give the variables by-value rather then by-reference). What you should do, to change the sound volume at runtime via JSoundSystem::SetSfxVolume, is call JMP3::setSfxVolume and afterwards call JMP3::pspSetSfxVol().

IMO this is a pretty weak design for multiple reasons, one being that you have two different functions with similar names that *should* do only one thing, yet have both functions have to be called in turn to achieve the result.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
yeshua



Joined: 30 Nov 2009
Posts: 20

PostPosted: Wed Dec 09, 2009 2:48 pm    Post subject: Reply with quote

Thanks it works
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Fri Dec 11, 2009 5:09 pm    Post subject: Reply with quote

Hey Yeshua, here's a quick review seeing the chunks of code here. Your design doesn't look good to me and I believe there has been a misunderstanding when I told you what I think should be done.

Goal: we want independent control of the volume of SFX and Music.

The Jmp3 class in JGE is made to handle music, not sfx.
For sfx we use JAudio.cpp.

Therefore you shouldn't have a function "setSfxVolume" in JMp3, it makes no sense.

you should have one method SetVolume in Jmp3 (it already exists) and a method with the same name in JAudio,

JSoundSystem should be the one having one "SetMusicVolume" and one "SetSfXVolume" methods.

It should look like:
Code:

JSoundSystem::setMusicVolume(int volume){
    myJmp3->setvolume(volume);
}

JSoundSystem::setSfxVolume(int volume){
    myJAudio->setvolume(volume);
}

Ok, I know JGE is not always clean, and unfortunately, the name of the JSoundSystem file is... JSfx.cpp, which doesn't help...but that's where the functions setMusicVolume and setSfxVolume should be, not anywhere else...
Feel free to rename JSfx.cpp to JSoundSystem.cpp.


Also the method names in JMp3 should not start with "psp", since JMp3 is used only by the PSP anyways.
_________________
Wagic. Play that card game against an AI on your PSP
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group