SonyEricsson Java Adapting R2A
SonyEricsson Java Adapting R2A
1
Contents
Contents ......................................................................................................................................................2
1. Introduction.......................................................................................................................................3
2. The Sony Ericsson T610/T616/T618 & Z600.............................................................................4
2.1. The Mobile Information Device Profile 1.0................................................................................5
2.2. The Mobile Media API.....................................................................................................................6
3. Adapting Your MIDlets ...................................................................................................................8
3.1. General Considerations.................................................................................................................8
3.2. Managing Sound in the T610/T616/T618 and Z600.................................................................8
3.2.1. Reducing Playback Latency .............................................................................................................................................10
3.2.2. Using Multi ple Players ........................................................................................................................................................10
4. Conclusion..................................................................................................................................... 18
5. Appendix 1 - Map of Nokia Frequencies to MIDI Note Numbers..................................... 19
6. Appendix 2 - Resources............................................................................................................. 22
7. Appendix 3- T610 Firmware Update ........................................................................................ 23
7.1. Availability of firmware upgade for the T610 phone ........................................................... 23
2
1. Introduction
Sony Ericsson sells the high-end T610/T616/T618, a series of advanced wireless mobile phones with complete imaging
and messaging capabilities, including the T610 and T616 for the American market and T618 for the Chinese market. The
T610 series of phones has a large color LCD display, built-in camera, and multimedia messaging services. Sony Ericsson
has recently introduced the Z600, which offers similar capabilities as the T610/T616/T618.
This paper discusses the T610/T616/T618 and Z600 phones and how to adapt your existing MIDlets to them, with special
focus on adapting existing Nokia Series 40 MIDlets.
This article assumes that you are familiar with the J2ME Mobile Information Device Profile (MIDP) 1.0, and the Liquid
Crystal Display User Interface (LCDUI) API, which is part of the MIDP 1.0 specification.
For your convenience, below is a list of acronyms that are used in this document:
LCDUI Liquid Crystal Display User Interface, the least common denominator type o f user interface targeted by
MIDP
3
2. The Sony Ericsson T610/T616/T618 & Z600
The Sony Ericsson T610/T616/T618 is series o f high-end devices. It supports the MIDP 1.0. Figure 1 shows the
T610/T616/T618.
The Sony Ericsson Z600 supports similar features as the T610/T616/T618 --such as the 65536-color display, network
connectivity, and integral camera--all packaged in an attractive clamshell design. Figure 2 shows the Z600 device.
4
Table 1 T610/T616/T618 and Z600 Specifications
* Note: The T610/T616/T618 and Z600 phones have infrared, Bluetooth, and serial connectivity, but these are not
currently supported from Java .
In addition to the core MIDP APIs, these handsets support a subset of the standard Mobile Media API, as defined by the
Java Community Process JSR-135. This subset supports audio playback. You control synthesizers that use data sources
such as MIDI, iMelody, and stored tone sequences to play back sounds or music.
The T616 for the North American market also supports the Wireless Messaging API JSR-120.
5
Table 2 Summary of MIDP 1.0 API
java.io MIDP subset of system input and output through data streams.
The application (MIDlet) interface, its life-cycle classes and its interactions with
javax.microedition.midlet
the runtime environment, and the application manager.
Covering the MIDP 1.0 APIs in detail is outside the scope of this article. For more information on MIDP, please refer to
the MIDP documentation that can be downloaded from Sun Microsystems MIDP page.
The MMAPI splits media processing into two main concepts: data source and the respective handlers (media protocols
specified via a URL) and content handlers (media players and controls). A media Manager provides a factory of resources
such as players as well as methods to query for supported content types and protocols:
6
Manager Create Player
(Player Factory)
Creates Application
Controls
Data Source Consumes Player Control(s)
(Content) (Content Handler) Controls
Generates
Digital
Tones Image Video
Audio
Figure 2 The MMAPI Manager, Player, Player Control and Data Sources
The entry point to any MMAPI-based application is the Manager, which is a factory of Players for multimedia processing.
A Player (the content handler) consumes and renders content. A Player provides basic multimedia functionality such as
start and stop multimedia playing, and the overall multimedia playing life-cycle. The Player can also expose extended
multimedia functionality through the use of Controls . Examples of controls are the ToneControl and VideoControl. The
Manager also includes a simple tone player. Not shown in Figure 2 is the PlayerListener , which can be used by the
application for fine-grained control. Using a PlayerListener an application can keep track of the Players state, for
example, when a Player has been started, stopped, or when the end of media has been reached.
The MMAPI v 1.0 s pecification defines protocols, controls and players for a number of media types, such as
MIDIControl, VideoControl, ToneControl, and VolumeControl (12 total in MMAPI v 1.0). The specification does
not mandate any particular one, allowing profiles to use a subset the MMAPI as appropriate the only requirement is
that implementations must guarantee support of at least one media type and protocol. In the case of the
T610/T616/T618 and Z600, the only supported audio-control is the ToneControl. The MMAPI subset does support
multiple audio media formats including simple tone generation, plus MIDI, AMR, and iMelody playback.
Later in this article we will see how to use the MMAPI to play various audio media formats. For more information on the
MMAPI, please refer to The Mobile Media API. For detailed information how to use the MMAPI with the T610/T616/T618
and Z600, consult the training course Making the Most of the Mobile Media API (JSR-135) with Sony Ericsson Handsets.
7
3. Adapting Your MIDlets
Java is an excellent programming language and runtime environment for creating portable applications. But making
portable applications goes beyond just using Java.
MyGameSounds
<<interface>>
playExplodingSound()
playFiringSound()
playBackgroundMusic()
Default
Sony Ericsson Nokia Motorola Other
(MMAPI) Behavior Behavior Behavior
Behavior
playExplodingSound() playExplodingSound() playExplodingSound() playExplodingSound()
playFiringSound() playFiringSound() playFiringSound() playFiringSound()
playBackgroundMusic() playBackgroundMusic() playBackgroundMusic() playBackgroundMusic()
In the above example we ask the Manager to create a tone Player to play back tone sequences stored in an array. To
control the tone player use the Players control methods realize(), prefetch(), and start(). There are many
other Player methods consult the MMAPI Javadoc . To select the tone sequence to play we use the tone control-specific
setSequence() method.
In addition to simple tone sequences, the T610/T616/T618 and Z600 also supports the following media formats:
MIDI the Musical Instrument Digital Interface player can be located by using the "audio/midi" media locator
Uniform Resource Identifiers (URI) syntax.
AMR the Adaptive Multi -Rate player can be located by using the "audio/amr " media locator URI syntax.
iMelody the iMelody player can be located by using the "audio/imelody " media locator URI syntax.
Playing any of the above media formats is as simple as playing a tone sequence. For example, the following snipp et of
code plays a file that contains iMelody commands:
try {
InputStream is = getClass().getResourceAsStream(fileName);
mp = Manager.createPlayer(is, "audio/imelody ");
mp.prefetch();
mp.start();
} catch (Exception e) {
...
}
Note how we use method getResourceAsStream() to create an input stream from a file that is stored in the MIDlet
suite. To create our Player, we pass the input stream and the media locator audio/imelody to the Manager, which
returns the iMelody Player. We then use the player control methods as previously described.
To play AMR media formats we do exactly as above, but we load an AMR file and specify audio/amr as the media
locator. You can create AMR files by converting existing Wave (.WAV) sound files into AMR media formats by using the
Sony Ericsson AMR Converter, which is downloadable from the Ericsson Mobility World site: Sony Ericsson AMR
Converter.
9
3.2.1. Reducing Playback Latency
There are times when a Player must perform a number of time-consuming tasks before it is ready to be started. This
includes allocating resources, filling buffers, or other start-up processing. This results in a long delay when calling
Player.start(). To minimize this delay or latency always pre-fetch your sounds before starting the player. This is
simply done by calling Player.prefetch().
:
: // pauseApp(), destroyApp(), other.
:
// Create a player for the background music. Pre-fetch and start the music!
try {
InputStream is = getClass().getResourceAsStream(fileName);
p = Manager.createPlayer(is, "audio/amr");
p.addPlayerListener(new Listener());
p.prefetch();
10
p.start();
} catch (Exception ioe) {
...
}
}
:
: // Other MIDlet methods...
:
/**
* This inner class implements a PlayerListener. Its purpose is to continuously
* repeat the background music.
*/
class Listener implements PlayerListener {
public void playerUpdate(Player p, String event, Object eventData) {
if (event == END_OF_MEDIA) {
try {
p.start();
} catch (MediaException me) { }
break;
}
}
}
}
The PlayerListener is key to fine-grained control in general. Player events that can be tracked are:
BUFFERING_STARTED, BUFFERING_STOPPED, CLOSED, DEVICE_AVAILABLE, DEVICE_UNAVAILABLE,
DURATION_UPDATED, END_OF_MEDIA, ERROR , RECORD_ERROR, RECORD_STARTED , RECORD_STOPPED,
SIZE_CHANGED, STARTED, STOPPED, STOPPED_AT_TIME, VOLUME_CHANGED .
Playing foreground audio, such as the firing sound on a game is simply done by starting the player when the fire key is
pressed. The following code snippet shows elements of a Canvas class that creates a player, pre-fetches content, and
then, when the fire key is pressed, starts the Player to play the fire tone sequence.
public class MyCanvas extends Canvas
{
byte[] fireSequence = ...;
Player firePlayer;
:
:
11
firePlayer = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
firePlayer.realize();
ToneControl c =
(ToneControl)mp.getControl("javax.microedition.media.control.ToneControl");
firePlayer.setSequence(fireSequence);
firePlayer.prefetch();
} catch (Exception ex)
...
}
}
What happens when you have both of these Players active in, say, a game? Player p plays continuously, providing the
background mus ic. However, once firePlayer starts, this halts p and the background music. When firePlayer
completes the playback of its media, an END_OF_MEDIA event is sent to both Players. This has p resume the playback of
its media, since it is set to play continuously. Be aware that background music playback resumes from the start of the
media, and not at the point that p was interrupted. However, with a carefully designed soundtrack, you can minimize the
12
effect of firePlayer constantly restarting the background music. For more information, consult the training course
Making the Most of the Mobile Media API (JSR-135) with Sony Ericsson Handsets.
BEGIN:IMELODY
VERSION:1.2
FORMAT:CLASS1.0
NAME:Vibrate
BEAT:200
STYLE:S1
Melody:(vibeonr5vibeoff@100)
END:IMELODY
BEGIN:IMELODY
VERSION:1.2
FORMAT:CLASS1.0
NAME:Test BackLight
BEAT:200
STYLE:S1
Melody:(backonr3backoff@100)
END:IMELODY
BEGIN:IMELODY
VERSION:1.2
FORMAT:CLASS1.0
NAME:Test LED
BEAT:200
STYLE:S1
Melody:(ledonr3ledoff@10)
END:IMELODY
BEGIN:IMELODY
VERSION:1.2
FORMAT:CLASS1.0
NAME:IndyJones
COMPOSER:
BEAT:480
STYLE:S0
VOLUME:V15
MELODY:*5c4e3r1r4d4f3r4e4g3r4c4r3.e4*6c1:r4*5c4r3.c4r3.c4r1:r4c4
d1r2e3r4c4f3.r2c4r1:r4c4r3.c4r3.c4r1:r4c4g1r2a3r4c4b3r4c4r3.a4*6
f1:r4*5c4r3.c4r3.c4r1:r4f4a0;r5;g4b3.c4*6c2:r1*5g4*6d1r2:c4e1
END:IMELODY
13
As previously explained, you would store the appropriate sequence of iMelody commands in a file within the MIDlet suite.
To load this file for later playback you use the getResourceAsStream() method.
3.5. Moving Your Nokia Series 40 MIDlet to the T610/T616/T618 and Z600
The Nokia Series 40 also supports MIDP 1.0. But in addition to the standard MIDP APIs, the Nokia Series 40 introduces
proprietary APIs for the following:
Low-level access to image pixel data
Transparency support
Full screen drawing
Sound
Vibration and device lights control
These APIs are package under the com.nokia.mid.sound and the com.nokia.mid.ui Java packages. But as
mentioned earlier, once your MIDlet uses any proprietary APIs, your code becomes non-portable.
For networking, persistence storage, and to managing the MIDlet lifecycle, the Nokia Series 40 uses the standard MIDP
1.0 APIs, so we dont have any concerns with respect to those APIs. It is the sound and user interface APIs that are of
concern. The next section will show how to adapt existing Nokia Series 40 MIDlets to the T610/T616/T618 and Z600
phones.
14
Similar to the MMAPI, the Nokia sound API provides methods that include setting the sound to play, start, and stop
playing. This makes the mapping of com.nokia.mid.sound to the MMAPI pretty direct. Table 5 shows how simple
generation can be done in the Nokia Series 40 and the T610/T616/T618 and Z600 using the MMAPI.
sound.play(1);
...
In the example above, frequency 262 maps to the Mobile Media note value of ToneControl.C4. This corresponds to
the MIDI note C4, at 261.63 Hz. The constant value for ToneControl.C4 is 60, which maps to the MIDI note number for
this same frequency. All of the ToneControl values repres ent MIDI note numbers, so its easy to map Nokia Sound API
frequencies to Mobile Media API MIDI note numbers. For your convenience refer to Appendix 1 , which shows this
relationship between the Nokia Sound API frequencies and the Mobile Media API MIDI numbers. For clarity, the Table
omits the scale's sharp and flat notes.
The Nokia API can also play a sequence of tones, including digitized sound based on the WAV encoding if supported by
the particular device. Note that the T610/T616/T618 and Z600 do not support WAV encoding, so you must use any of the
alternate audio formats described shortly.
To play a sequence of bytes using the Nokia API you must use a Sound object using the following Constructor:
public Sound(byte[] data, int type)
Then play the sequence using the sound.play(int loop) method. You can also play a sequence of tones by first
initializing the Sound object by using the method Sound.init(byte[] data, int type) then calling
sound.play(int loop) to play it.
Playing sequence of tones using the MMAPI is more involved, as the ToneControl provides more tone control
capabilities, as shown in the following snippet of code taken from the Sony Ericsson J2ME SDK.
byte C4 = ToneControl.C4;
byte D4 = C4 + 2; // a whole step
byte E4 = C4 + 4; // a major third
byte G4 = C4 + 7; // a fifth
byte rest = ToneControl.SILENCE; // eighth-note rest
byte d = 8;
byte[] mySequence = new byte[] {
ToneControl.VERSION, 1,
ToneControl.TEMPO, 30,
ToneControl.BLOCK_START, 0,
E4,d,D4,d,C4,d,D4,d,E4,d,E4,d,E4,d,rest,d,
ToneControl.BLOCK_END,0,
ToneControl.PLAY_BLOCK,0,
D4,d,D4,d,D4,d,rest,d,E4,d,G4,d,G4,d,rest,d,//play "B" section
ToneControl.PLAY_BLOCK,0, // content of "A" section
D4,d,D4,d,E4,d,D4,d,C4,d,rest,d// play "C" section
};
15
...
mp = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
mp.realize();
ToneControl c = (ToneControl)mp.getControl("ToneControl");
c.setSequence(mySequence);
mp.prefetch();
mp.start();
In addition to simple tone generation, the T610/T616/T618 and Z600 supports other audio media formats including the
iMelody, AMR, and MIDI. To play iMelody, AMR and MIDI content, the content is stored o utside the MIDlet itself as a
resource, and loaded and played at run time as shown in the following example:
try {
String my_imelody_file = "/my_imelody_file";
String mediaType = "audio/imelody";
int loopCount = 1;
InputStream is = getClass().getResourceAsStream(my_imelody_file);
mp = Manager.createPlayer(is, mediaType);
mp.setLoopCount(loopCount);
mp.prefetch();
mp.start();
} catch (Exception ex) {
...
}
The source code to play an AMR or MIDI files look exactly the same, except the media type and resource location strings
need to be adjusted as appropriate.
16
Adapting th e DirectGraphics and DirectUtils classes to the T610/T616/T618 and Z600 (or any other standards
based device) is more complicated than adapting DeviceControl or FullCanvas . As described in Table 6, we can
implement similar capabilities found in the DeviceControl class by using iMelody sequences. Recall that the iMelody
sequences support ways to turn on/off the vibrator, LEDs and backlight. In the case of FullCanvas, we would use the
standard LCDUI Canvas instead. Because the screen sizes of the Nokia Series 40 versus those T610/T616/T618 and
Z600 are very similar, your Nokia Series 40 MIDlet should map very easily to these phones. Also note that by not using
FullCanvas we dont have to worry about the detail that FullCanvas doesnt support LCDUI Command or
CommandListener. Put another way, using FullCanvas forces us to implement an alternate way to capture user
interface commands. Because the LCDUI Canvas class does support Command and CommandListener, our code
becomes simpler.
To keep your code portable, you must never hardcode values such as coordinates or screen sizes you must always
discover these through the appropriate API methods. Recall that the Canvas provides methods to discover the actual
size of the drawing area, as shown next:
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();
int canvasWidth = getWidth();
int canvasHeight = getHeight();
Once you have the above information, you can scale and draw your user interface as appropriate. For example, the
following code snippet implements the paint() method of a Canvas:
public void paint(Graphics g) {
17
4. Conclusion
This paper has covered the new Sony Ericsson T610/T616/T618 and Z600, which are high-end wireless communicators
with support for MIDP 1.0 and the Mobile Media API. It also covered details that developers must be aware of when
creating new MIDP applications, or migrating existing applications to the T610/T616/T618 and Z600.
The T610/T616/T618 and Z600 are completely standards based no proprietary APIs are exposed, ensuring that MIDlets
created for these phones are truly portable.
Adapting applications to the T610/T616/T618 and Z600 is also simple. First, as a truly standards based platform, any
MIDP application can be ported to these phones with minimal or no changes. Adapting MIDlets from devices that uses
proprietary extensions such as the Nokia Series 40 is more involved but not difficult to do, as this paper shows.
18
5. Appendix 1 - Map of Nokia Frequencies to
MIDI Note Numbers
A0 - 27.5 28 21
B0 - 30.868 31 23
C1 - 32.703 33 24
D1 - 36.708 37 26
E1 - 41.203 41 28
F1 - 43.654 44 29
G1 - 48.999 49 31
A1 - 55 55 33
B1 - 61.735 62 35
C2 - 65.406 65 36
D2 - 73.416 73 38
E2 - 82.407 82 40
F2 - 87.307 87 41
G2 - 97.999 98 43
A2 - 110 110 45
B2 - 123.47 123 47
C3 - 130.81 131 48
19
D3 - 146.83 147 50
E3 - 164.81 165 52
F3 - 174.61 175 53
G3 - 196 196 55
A3 A0 220 220 57
B3 B0 246.9 4 247 59
C4 C0 261.63 262 60
D4 D0 293.67 294 62
E4 E0 329.63 330 64
F4 F0 349.23 349 65
G4 G0 392 392 67
A4 A1 440 440 69
B4 B1 493.88 494 71
C5 C1 523.25 523 72
D5 D1 587.33 587 74
E5 E1 659.26 659 76
F5 F1 698.46 698 77
G5 G1 783.99 784 79
A5 A2 880 880 81
B5 B2 987.77 988 83
C6 C2 1046.5 1047 84
D6 D2 1174.7 1175 86
E6 E2 1318.5 1319 88
F6 F2 1396.9 1397 89
G6 G2 1568 1568 91
A6 A3 1760 1760 93
B6 B3 1975.5 1976 95
C7 C3 2093 2093 96
20
D7 D3 2349.3 2349 98
For the proper mapping of Tone values, please refer to the Nokia and the MMAPI documentation.
21
6. Appendix 2 - Resources
22
7. Appendix 3- T610 Firmware Update
In the menu that appears, select "Service information" and then "SW information" (note that the menu names may differ in
other languages). The information about which SW revision (R followed by a number) your handset has will now be
displayed.
If your software number says "R3B" , it incorporates all performance fixes and is also TCK-compliant. If your handset has
a lower software revision number on (such as "R3A"), you should contact your nearest Sony Ericsson service point to get
your T610 updated with the latest software. The nearest service point can be found in the documentation in the phone
box or on the Sony Ericsson Global support web site (http://www.sonyericsson.com/support).
If you were provided a handset through the Sony Ericsson Developer Program or a local Ericsson Mobility World center
with which Sony Ericsson collaborates, you should consult that contact as how to get the handset updated.
There is no easy way to detect directly from a Java application the firmware version that phone uses. However, your
download server can detect if the phone has the new or the old software version through the User Agent field in the HTTP
protocol during a download. The SW version in the useragent field for the new software is: "SonyEricssonT610/R301
Profile/MIDP-1.0 Configuration/CLDC-1.0". If the "R301" is replaced by a lower value ("R201" for example)
it is the old firmware version. If instead the "R301" is replaced by a higher value ("R401" for example) it is a newer
version that includes the performance improvements.
23