Author Topic: Using the soundsystem.  (Read 4475 times)

Offline mige

  • byte
  • *
  • Posts: 10
    • View Profile
Using the soundsystem.
« on: February 21, 2012, 07:48:59 AM »
EDIT: Music is now playing, but the system doesnt seem to know that?

my code: (its just returning false, if im checking if anything is playing..)
Code: [Select]
try{
url = file.toURL();
System.out.println("fsdf");
ss.newStreamingSource(true, "Music", url, fileName, false, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, 0);
ss.play("Music");
System.out.println(ss.playing("Music"));
}catch (Exception e) {
e.printStackTrace();
}
« Last Edit: February 22, 2012, 08:22:59 AM by mige »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Using the soundsystem.
« Reply #1 on: February 21, 2012, 03:42:27 PM »
Do not use the MidiChannel class.  Everything is done through the SoundSystem class.  Midi is particularly easy.  Just call backgroundMusic (or quickPlay, or newSource then play).  For example:

Code: [Select]
SoundSystem ss = new SoundSystem();
ss.backgroundMusic( "Cool music!", "music.mid", true ); // assumes file is in package "/Sounds"

I recommend working through the examples in my guide 3D Sound with SoundSystem.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline mige

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Using the soundsystem.
« Reply #2 on: February 22, 2012, 06:42:28 AM »
Do not use the MidiChannel class.  Everything is done through the SoundSystem class.  Midi is particularly easy.  Just call backgroundMusic (or quickPlay, or newSource then play).  For example:

Code: [Select]
SoundSystem ss = new SoundSystem();
ss.backgroundMusic( "Cool music!", "music.mid", true ); // assumes file is in package "/Sounds"

I recommend working through the examples in my guide 3D Sound with SoundSystem.

Ok, thx.

Got it playing now... but just noticed that it doesnt seem to return value for playing() correctly, heres my code: (its always returning false)
Code: [Select]
SoundSystem ss = new SoundSystem();
try{
url = file.toURL();
System.out.println("fsdf");
ss.newStreamingSource(true, "Music", url, fileName, false, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, 0);
ss.play("Music");
System.out.println(ss.playing("Music"));
}catch (Exception e) {
e.printStackTrace();
}

Also would there be anyway to change the masterVolume through static method, otherwise I would have to change a lot in my original code....
« Last Edit: February 22, 2012, 10:30:10 AM by mige »

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Using the soundsystem.
« Reply #3 on: February 22, 2012, 03:45:36 PM »
Hmm, I'll have to look at the code to see why it would return false when it is actually playing.  Probably something midi-specific.  I don't have my PC back up fully, so I'll look into this on Saturday.

Making the masterVolume static would require relatively large changes (I can do it easily enough if it is necessary, but you might have to wait a couple weeks for me to find the time to work on it).  Could you just make the SoundSystem instance a static member of your class, so that it could be accessed from a static context? (or alternately, keep a static handle to your class' instance)
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline mige

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Using the soundsystem.
« Reply #4 on: February 23, 2012, 09:47:47 AM »
Hmm, I'll have to look at the code to see why it would return false when it is actually playing.  Probably something midi-specific.  I don't have my PC back up fully, so I'll look into this on Saturday.

Making the masterVolume static would require relatively large changes (I can do it easily enough if it is necessary, but you might have to wait a couple weeks for me to find the time to work on it).  Could you just make the SoundSystem instance a static member of your class, so that it could be accessed from a static context? (or alternately, keep a static handle to your class' instance)

Ok, hopefully u will figure out whats the problem with the playing() method.

+ Also making the soundsystem static worked out just fine, thx for that. :)

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Using the soundsystem.
« Reply #5 on: February 25, 2012, 09:57:35 AM »
MidiChannel.java

ADD the following:

Code: [Select]
    public boolean playing( String sourcename )
    {
        if( loading() || sequencer == null )
            return false;
        return sequencer.isRunning();
    }

BEFORE:

Code: [Select]
//-- INSERT HERE--
/**
 * Plays the MIDI file from the beginning, or from where it left off if it was
 * paused.
 */
    public void play()



SoundSystem.java

ADD the following:

Code: [Select]
            if( soundLibrary.midiSourcename( sourcename ) )
                return soundLibrary.getMidiChannel().playing();

AFTER:

Code: [Select]
/**
 * Returns true if the specified source is playing.
 * @param sourcename Unique identifier of the source to check.
 * @return True or false.
 */   
    public boolean playing( String sourcename )
    {
        synchronized( SoundSystemConfig.THREAD_SYNC )
        {
            if( soundLibrary == null )
                return false;
//--INSERT HERE--

Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted