×

Discussion Board

Results 1 to 5 of 5

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    75

    Problem playing tones after playing a sound file

    Hi,

    I've developed a game that includes sound effects. In order to help it work well on the widest variety of phones, some sound effects can be produce by:


    generating a tone
    playing a .wav or .amr file

    It also turns out that most S40 phones seem to have hardware for tone generation that appears to produce the tones asynchronously, and without introducing any delay in the program. The more expensive S60 phones do not seem to have tone-generating hardware and producing tones on these phones places a noticeable load on the phone (causing a slight delay in the game action). I have developed a bunch of tricks to determine whether or not the phone has tone-generating hardware, to "cue up" sound files to reduce latency when they need to be displayed, and to play sound files of tones (instead of generating tones) on phones without hardware tone-generation.

    It has all been working quite well on many S40 phones including 3610 (S40 5th Ed.) and 6303 (S40, 6th Ed.), but it does not work correctly on 2700 (S40 5th Ed, FP1), where I am getting inconsistent behavior. It appears that the 2700 is happy to play tones,

    Manager.playTone (70, 1000, 100);

    until I play a .wav file. After I play a .wav file the playTone method produces no sound and throws no exception. Under some circumstances--which I am still trying to identify--the playTone method will start producing tones again. But, the very next time a .wav file is played the playTone method stops producing sounds again.

    Has anyone come across this behavior? Does anyone have any ideas?
    Cheers,

    Matt Brenner
    UnME2, Inc.

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Problem playing tones after playing a sound file

    I have certainly encountered a great many strange and bizarre sound playing issues... though never the exact one you mention.

    My first thought is to ask if you religiously deallocate() Players after they finish, before you try playing anything else... though it sounds like you have some experience with this, so I guess ou already have checked this.

    Does playing MIDI files have the same effect as playing WAVs? Does playing a MIDI after the WAV cause tones to start working again? This might sound irrelevant, but I've sometimes seen problems that were fixed by playing a very short, silent MIDI file, and I wonder if such a fix might help you...

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    75

    Re: Problem playing tones after playing a sound file

    Hi Graham,

    Thanks so much for your reply. Your suggestion about deallocate( ) had occurred to me. I checked my code carefully and found that I do NOT call deallocate, but instead call close( ) on each Player after its use. I'm wondering if perhaps I am failing to call close under some circumstance, which ties up the player and prevents Manager.playTone( ) from working. Perhaps later something happens that frees the Player and then Manager.playTone( ) works again.

    What's so odd to me is that my code works correctly on so many other Nokia phones.
    Cheers,

    Matt Brenner
    UnME2, Inc.

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Problem playing tones after playing a sound file

    Closing should deallocate. I deallocate rather than close, at it leaves the Player in a state where it can more quickly be played again. I tend to use a playerListener() to deallocate (or close, in your case), so it always happens.

    Why a problem on that device? Either it's some sychronization issue (maybe this devices is a little slower, for example), that results in a Player not being closed, or it's just some bug with the device.

  5. #5
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    75

    Re: Problem playing tones after playing a sound file

    Hi again,

    I'm learning all sorts of things as I try to get proper sound behavior from the 2700. For one thing, Manager.playTone only plays one tone. It doesn't care which tone I ask for, it just plays the same one tone. Here the shortest complete example I could write (give or take a line or two):


    Code:
    //   8/17/10   M. Brenner
    
    import	javax.microedition.midlet.*;
    import	javax.microedition.lcdui.*;
    import	javax.microedition.media.*;
    
    public class Playtones extends MIDlet
    	implements CommandListener
    {
    	public void startApp()
    	{
    		int		note;
    		
    		Displayable	disp;
    		
    		
    		disp = new TextBox ("Sound Test", "Playing a sequence of rising tones...", 100, TextField.ANY);
    		disp.addCommand (new Command("Exit", Command.EXIT, 1));
    		disp.setCommandListener (this);
    		Display.getDisplay (this).setCurrent (disp);
    
    			try {
    		for (note = 65; note < 75; note++) {
    			Manager.playTone (note, 200, 100);
    			Thread.sleep (200);
    		}
    			}
    			catch (Exception e) {}
    	}
    
    	public void
    	commandAction (Command c, Displayable d)
    	{
    		destroyApp (false);
    		notifyDestroyed();
    	}
    
    	public void destroyApp(boolean unconditional) { }
    
    	public void pauseApp() { }
    }
    As you can see, the for loop should play a sequence of rising tones (65 - 74). On every phone I tried, except the 2700, it works as expected. On the 2700 I get the same tone over and over.

    I installed the latest software update, but the problem persists.


    Also, I learned that if I create a second (or third, ...) GameCanvas a large off-screen buffer gets allocated (600k on the 2700). Fair enough, that's well-documented. But no matter how I try to release that object to the garbage collector it never gets deallocated. I've created some memory leaks in past, but WOW, 600K at a time!

    No big deal about the GameCanvas, as it's never necessary to create more than one, but the playTone problem looks like a real and significant bug to me. Is there any way to get Nokia to look at this one?
    Cheers,

    Matt Brenner
    UnME2, Inc.

Similar Threads

  1. Replies: 1
    Last Post: 2009-12-15, 13:05
  2. Problem playing sound on N70
    By smallbug005 in forum Mobile Java Games
    Replies: 3
    Last Post: 2009-07-17, 05:50
  3. problem playing resource sound file
    By WinBase in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2008-01-21, 18:05
  4. Capture sound while playing mp3 file
    By stm in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2007-01-10, 23:02
  5. playing a sound file
    By murmur20 in forum Symbian Media (Closed)
    Replies: 5
    Last Post: 2004-12-14, 07:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×