Developers Reference Guide on Creating Audio

xiaoxiao2021-03-06  84

Developers Reference Guide On Creating Audio sfx, Melodies and Vibration ON Nokia, Motorola, Sharp, Sagem and Sony Mobile Devices.

IntroductionHow many times have you thought your software works on a specific mobile device, because it works in the PC-emulator, only to find that once you try it on an actual device it crashes without any explanation why! This guide will help software developers create . 100% working FX on Nokia, Motorola, Sharp, Sagem and Sony mobile devices This practical guide will include full-code for each device.The most common FX required whilst developing mobile game software is the ability to:

Play melodies Play Wave-Audio Vibrate

Although IT IS generally Possible to create J2ME Software That Will Work ON All Devices * It is impossible to create generic code. Will activivate.

* Apart from Nokia Full Screen Mode, Motorola Reverse Soft-Keys and Nokia 3650 Alternative Key Layout.

If the device you need is not listed below, please email me dan@jcodeworks.com and i will consider address it.

FX Reference Guide

Please note:. Although it might be possible to achieve melody, wave-audio and vibrate using different types of file-format I will only list one The format described will (a) work !!! (b) use the least amount of processor Time and (c) Use the Least Amount of Resources.

DEVICES:

NOKIA 3650, 6600 and N-Gage Nokia 7650 Motorola V525 and V600 Sagem Myv65 and Myv75 Sharp GX10, GX10i and GX20 * Sony-Ericsson T6NN and Z600 * COMING SOON

NOKIA 3650, 6600 and N-GAGE

API: javax.microedition.media. *

Restriction: Only play 1 FX at a time.NOTE: You can add a listener that will inform you of Player events (eg Stopped - when Player finishes FX) To do this use:.. Player.addPlayerListener (* class *) The specified * Class * Must Implement Playerlistener.to Catch The Listener Events, Use The Following Method Inside * Class *:

Public Void Playerupdate (Player Player, String Event, Object Obj) {// Player Indicates Which Player Caused The Event // Event Informs You of Event Type}

Also: I have not Tried Playerlistener on Nokia 6600 and N-Gage and So, Cannot Confirm That IT Works Properly.

- - - -

Melody: Available - plays .mid files (format zero) The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them It's the standard of all standards in the music creation world.To LOAD a MIDI file. :

Import javax.microedition.media. * ;............................................................................................................................................................. .Realize (); Player.Prefetch (); // Remove this line for nokia 6600 and n-gage} catches (Exception E0) {}

To Play The melody, EnSure That You Stop All Other Players:

Try {Player.Stop (); catch (Exception E1) {}

... and the play your request melody with:

Try {Player.PreFetch (); // Remove this Line for Nokia 3650 Player.setMediatime (0); // Remove this for nokia 6600 and n-gage player.setloopCount (n); // n = number of time. - 1 = forever. Player.Start (); catch (Exception E2) {}

NOTE: Playing a melody does Not Seem to Cause Any Serious Delays. So you will not need to place it in a separate thread to the main game code.to clean-up a melody resource:

IF (player! = null) {Try {Player.close ();} catch (Exception E3) {} Player = NULL;} - - -wave audio: available - Plays .amr files (8 Bit, Rate CAN Vary Depending ON AMR FILES Are A Lot Smaller Than .wav Files. To Create AMR Files Use The Miksoft Mobile AMR Converter. Check IT Out at www.miksoft.8m.com:

Import javax.microedition.media. * ;............................................................................................................... .realize (); Player.Prefetch ();} catch (exception E0) {}

To Play The Audio, EnSure That You Stop All Other Players:

Try {Player.Stop (); catch (Exception E1) {}

... and the Play Your Required Wave-Audio with:

Try {Player.SetMediatime (0); Player.Start (); catch (Exception E2) {}

Note: Calling the start () Method Does Seem to take the main time before calling back. So you will need to place it in a separate thread to the main game code.to clean-up a Wave-audio resource:

IF (Player! = null) {Try {Player.close ();} catch (exception E3) {} Player = null;}

- - - -

Vibrate: Not available.

NOKIA 7650

API: com.nokia.mid.sound. * Restriction: Only Play 1 FX At A Time.

NOTE: There Does Not Seem To Be Any Sound Listeners Implement On This Device, SO You Will Need To Create Your OWN Means of Determining et...............

- - - -

NOT AVAILABLE.

- - - -

Wave Audio: Available - Plays .wav FILES (8bit, 8kHz)

Warning: i Have Found That Short Wave-Audio (E.G. Under .7 of A Second) Do Not Play Properly E.G. Produce Clicking Noises or Don't Play At ALL.

To load a Wave-audio:

Import com.nokia.sound. * ;... .Byte [] bytes = readdataFromjar ("beep.wav"); Sound Sound; if (Bytes! = null) Sound = New Sound (Bytes, Sound.Format_wav) ;. .. .//utility method used by code above ... public byte [] readDataFromJar (String name) {// get data from JAR resource ByteArrayOutputStream bout; InputStream in; byte [] res = null; try {in = * canvas ref * .getclass (). getResourceAsStream (Name); bout = new byteArrayoutputStream (); for (int RET = IN.READ (); RET> = 0; RET = IN.READ ()) Bout.write (RET); res = Bout.TobyteArray ();} Catch (Exception E) {} Return Res;} To Play The Audio, Ensure That You Stop All Other Wave-Audio:

IF (sound! = null) Sound.stop ();

... and the Play Your Required Wave-Audio with:

IF (sound! = null) Sound.Play (n); // n = number of reviews, E.G. 1

NOTE: CALLING The Play () Method Does Not See MAIN. SO You Will NOT NEED To Place It in a Separate Thread To The Main Game Code.to Clean-Up A Wave-Audio Resource:

IF (sound! = null) {Sound.stop (); Sound = null;

BUG NOTIFICATION: Some older 7650 firmware versions (version number unknown) crashes the application if you use the command 'setGain' Once the application terminates, the device will display an error notification:. Jes-8e-javax.microedition.lcdui0 @ 1. ..Cmdaaudioplayeru 2 (or Similar - Depending on firmware version). The Application Will Crase Even if you enclose The Command With a try / catch exception handler.

- - - -

Vibrate: Not available.

Motorola V525 and V600

API: Use javax.microedition.media. * For melody and wave-audio.use the midp2 display.vibrate Command for Vibration.

Restriction: Only play 1 FX at a time.NOTE: You can add a listener that will inform you of Player events (eg Stopped - when Player finishes FX) To do this use:.. Player.addPlayerListener (* class *) The specified * Class * Must Implement Playerlistener.to Catch The Listener Events, Use The Following Method Inside * Class *:

Public Void Playerupdate (Player Player, String Event, Object Obj) {// Player Indicates Which Player Caused The Event // Event Informs You of Event Type}

- - - -

Melody: Available - plays .mid files (format zero) The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them It's the standard of all standards in the music creation world.To LOAD a MIDI file. :

Import javax.microedition.media. * ;............................................................................................................................................................. .Realize ();} catch (exception E0) {}

To Play the melody, EnSure That You Stop and DEAllocate All Other Players:

Try {Player.Stop (); catch (Exception E1) {} try {player.deallocate (); catch (Exception E2) {}

... and the play your request melody with:

Try {Player.Prefetch (); catch (Exception E3) {} try {player.setmediatime (0); Catch (Exception E4) {} Player.SetLoopCount (n); // n = Number of Times. -1 = forver .Try {Player.Start (); catch (Exception E5) {}

NOTE: CALLING DOS NOT Seem to Cause Any Serious Delays. So you will not need to place it in a separate thread to the main game code.to clean-up a melody resource:

IF (Player! = null) {Try {Player.close ();} catch (exception e6) {} Player = null;}

- - -Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required) AMR files are a lot smaller than .WAV files To create AMR files use the MIKSOFT Mobile AMR converter Check it out at.. www.miksoft.8m.comTo LOAD a wave-audio: import javax.microedition.media * ;. .Player player; try {player = Manager.createPlayer (* canvas ref * .getClass () getResourceAsStream ( "beep.... .amr ")," Audio / AMR "); Player.Realize (); Player.Prefetch ();} catch (Exception E0) {}

To Play The Wave-Audio, EnSure That You Stop and DEAllocate All Other Players:

Try {Player.Stop (); catch (Exception E1) {} try {player.deallocate (); catch (Exception E2) {}

... and the Play Your Required Wave-Audio with:

Try {Player.Prefetch (); Catch (Exception E3) {} try {player.setmediatime (0); Catch (Exception E4) {} try {Player.Start (); catch (Exception E5) {}

Note: Calling the start () Method Does Not See MAIN. SO You Will NOT NEED To Place It in a Separate Thread to the main game code.to clean-up a Wave-Audio Resource:

IF (Player! = null) {Try {Player.close ();} catch (exception e6) {} Player = null;}

- - - -

Vibrate: Available.

Use the midp2 Built-in Display Class Command:

* Display * .vibrate (duration); // duration is in MilliseConds

SAGEM MYV65 and MYV75

API:. Javax.microedition.media * Restriction: Only play 1 FX at a time.NOTE: There does NOT seem to be any Player listeners implemented on this device, so you will need to create your own means of determining if the Player has Finished Using An Elapsed Time Clock Counter.

- - - -

Melody: *** To be fully investigated *** Although it is possible to play MIDI files it is NOT 100% compatible For example:.. I have not been able to play drum tracks I need to investigate this in more depth and I Will Then Write Up My Discoveries.- - - -

Wave Audio: Available - Plays .wav FILES (8bit, 8kHz)

Warning: The Sagem Is Extreme Fussy About Wave-Audio. You Must Only Have 1 Player Pre-Fetched At Any One Time.

To load a Wave-audio:

Import javax.microedition.media. * ;.... .. ............................................ Player.Realize ();} catch (exception E0) {}

To Play The Audio, Ensure That You Stop and DEAllocate All Other Players:

Try {Player.Stop (); catch (Exception E1) {} try {player.deallocate (); catch (Exception E2) {}

... and the Play Your Required Wave-Audio with:

Try {Player.Prefetch (); Catch (Exception E3) {} try {player.setmediatime (0); Catch (Exception E4) {} try {Player.Start (); catch (Exception E5) {}

Note: Calling the stop (), deallocate () (), prefetch () and start () Methods Does Not Seem To Cause Any Serious Delays. So you will not need to place it in a separate thread to the main game code.to clean- Up a Wave-Audio Resource:

IF (Player! = null) {Try {Player.close ();} catch (exception e5) {} Player = null;

As I mentioned earlier, the Sagem device is extremely fussy about wave-audio, and so I have tried to catch every possible problem with an exception. Remove the try / catches if you dare, but do not be too surprised if you start getting Unexpected Crashs!

- - - -

Vibrate: Not available.

Sony-Ericsson T6NN and Z600

API: javax.microedition.media. *

Restriction: Only play 1 FX at a time.NOTE: You can add a listener that will inform you of Player events (eg Stopped - when Player finishes FX) To do this use:.. Player.addPlayerListener (* class *) The specified * Class * Must Implement PlayerListener.

To catch the listener events, use the folowing method inside * class *:

Public Void Playerupdate (Player Player, String Event, Object Obj) {// Player Indicates Which Player Caused The Event // Event Informs You of Event Type}

- - - -

Melody: Available - plays .mid files (format zero) The great thing about MIDI files is that you can use your favourite professional audio sequencing package to create them It's the standard of all standards in the music creation world.To LOAD a MIDI file. :

Import javax.microedition.media. * ;............................................................................................................................................................. .Realize ();} catch (exception E0) {}

To Play The melody, EnSure That You Stop All Other Players:

Try {if (Player.getState ()! = player.closed) Player.Stop (); catch (Exception E1) {}

... and the play your request melody with:

Try {Player.Prefetch (); Player.SetLoopCount (N); // n = Number of Times. -1 = forever. Player.Start (); catch (Exception E2) {}

NOTE: CALLING THEEFETCH () Method Does Not Seem To Cause Any Serious Delays. So you will not need to place it in a Separate thread to the main game code.to clean-up a melody resource:

IF (Player! = null) {Try {Player.close ();} catch (exception E3) {} Player = null;}

- - - -

Wave Audio: Available - plays .amr files (8 bit, rate can vary depending on quality required) AMR files are a lot smaller than .WAV files To create AMR files use the MIKSOFT Mobile AMR converter Check it out at www.miksoft.. .8m.comNote: Many Than You Wave Audio Code.to Load A Wave-Audio:

Import javax.microedition.media. * ;............................................................................................................... .Realize ();} catch (exception E0) {}

Player.prefetch ();

To Play The Audio, EnSure That You Stop All Other Players:

Try {if (Player.getState ()! = player.prefetched) Player.Stop (); catch (Exception E1) {}

... and the Play Your Required Wave-Audio with:

Try {Player.SetLoopCount (1); Player.Start (); catch (Exception E2) {}

Note:. The prefetch () method does seem to take some time before calling back So if you need to prefetch on the fly in a tight game loop you will need to place it in a separate thread to the main game code.To clean- Up a Wave-Audio Resource:

IF (Player! = null) {Try {Player.close ();} catch (exception E3) {} Player = null;}

- - - -

Vibrate: Available - Using .IMY Fileto Load a Vibrate Player:

Import javax.microedition.media. * ;....... ......................................................................................................................................... .realize (); Player.Prefetch ();} catch (exception E0) {}

The vibrate.imy is a Text File with The Following Lines of Code (To Change The Vibration Delay Alter The Settings in The Melody Line):

Begin: IMELODYVERSION: 1.2Format: Class1.0Beat: 200style: S1melody: VibeonR5Vibeoffend: IMELODY

To Start The Vibration, Ensure That You Stop All Other Players:

Try {if (Player.getState ()! = player.closed) Player.Stop (); catch (Exception E1) {}

... and the start the vibration with:

Try {Player.Start (); catch (Exception E2) {}

NOTE: CALLING The Start () Method Does Not Seem To Cause Any Serious Delays. So you will not need to place it in a Separate thread to the main game code.to Clean-Up A Vibration Resource:

IF (Player! = null) {Try {Player.close ();} catch (exception E3) {} Player = null;}

转载请注明原文地址:https://www.9cbs.com/read-121386.html

New Post(0)