I'm developing this game that utilizes Nokia's sound class. When testing i discovered that tones played in the emulator sound loud and clear, but when ported to the actual device(i used 7650) it sounded too soft that i have to actually put it beside my ear to hear the tones.
Using getGain, to my surprise it displays a value of 0!!
When i setGain to something else that is not 0, the tone refuse to play at all.
I wouldn't want to use wav files that are so big, could somebody please help? My code is as below
-----------------------------------------------------------------------------------
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.nokia.mid.sound.*;
public class TestCanvas extends Canvas
{
Sound sound;
byte[] music = {
(byte)0x02, (byte)0x4a, (byte)0x3a, (byte)0x40,
(byte)0x04, (byte)0x00, (byte)0x1d, (byte)0x1c,
(byte)0x82, (byte)0x2c, (byte)0x2a, (byte)0xc3,
(byte)0x0c, (byte)0x35, (byte)0x04, (byte)0x91,
(byte)0x69, (byte)0x18, (byte)0x20, (byte)0xd4,
(byte)0x0c, (byte)0x30, (byte)0xd3, (byte)0x08,
(byte)0xa0, (byte)0x00
};
TestCanvas()
{
sound = new Sound(music, Sound.FORMAT_TONE);
sound.setGain(128);
}
public void paint(Graphics g)
{
g.setColor(0,0,0);
g.fillRect(0,0,getWidth(), getHeight());
g.setColor(255, 255, 255);
g.drawString("gain is " + sound.getGain(), getWidth()/2, getHeight()/2, Graphics.TOP|Graphics.LEFT);
}
public void keyPressed(int key)
{
if(key == Canvas.KEY_NUM0)
sound.setGain(sound.getGain() + 1);
else if(key == Canvas.KEY_NUM1)
sound.setGain(sound.getGain() + 2);
else if(key == Canvas.KEY_NUM2)
sound.setGain(sound.getGain() + 5);
else
sound.play(1);
repaint();
}
}

Reply With Quote

