Author Topic: [Solved]How to see amplitude?  (Read 1467 times)

Venks

  • Member
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
[Solved]How to see amplitude?
« on: Wed, Jun 6, 2012 »
I'm toying around with FlxSound, but for the life of me can't really figure it out or find any examples to send me towards the right path. What I really want is to just trace the amplitude of the mp3 I'm using.

Anyone know how to do this?
« Last Edit: Thu, Jun 7, 2012 by Venks »

yadurajiv

  • Member
  • **
  • Posts: 35
  • Karma: +1/-0
  • ~.^ wut you say?
    • View Profile
    • the rant
Re: How to see amplitude?
« Reply #1 on: Wed, Jun 6, 2012 »
Step 1. Embed the sound and declare a variable(should also work if its streaming.

Code: [Select]
...
public class amp extends FlxState
{
[Embed(source = "data/fast_car.mp3")] private var mus_end:Class;

private var mus:FlxSound;

Step 2. Initialize the variable, load the embedded sound and play
Code: [Select]
override public function create():void
{
super.create();

mus = new FlxSound();
mus.loadEmbedded(mus_end);
mus.play();
}

Step 3. Update!
Code: [Select]
override public function update():void
{

mus.update(); // amplitude below will be 0 without calling update

trace(mus.amplitudeLeft);
trace(mus.amplitudeRight);

super.update();
}
^___________^

Venks

  • Member
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: How to see amplitude?
« Reply #2 on: Wed, Jun 6, 2012 »
I get the error: 'Access of possibly undefined property amplitudeLeft through a reference with static type org.flixel:FlxSound'

Any idea what I'm doing wrong?

yadurajiv

  • Member
  • **
  • Posts: 35
  • Karma: +1/-0
  • ~.^ wut you say?
    • View Profile
    • the rant
Re: How to see amplitude?
« Reply #3 on: Wed, Jun 6, 2012 »
You might be on an older version of Flixel. You need 2.50 and above for it to work.
^___________^

Venks

  • Member
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: How to see amplitude?
« Reply #4 on: Thu, Jun 7, 2012 »
I just updated to the latest version.

Code: [Select]
package
{
       import org.flixel.*;
   import flash.display.Sprite;
   import org.flixel.FlxGroup;
   import org.flixel.FlxG;
   import org.flixel.FlxSound;
   import Levels.*;
 
       public class PlayState extends FlxState
       {

[Embed(source = '../media/Collapse.mp3')] public var Music01:Class;
private var mus:FlxSound;

            override public function create():void
            {
super.create();

mus = new FlxSound();
mus.loadEmbedded(Music01);
mus.play();
            }
 
            override public function update():void
            {
mus.update(); // amplitude below will be 0 without calling update

trace(mus.amplitudeLeft);
trace(mus.amplitudeRight);

                super.update();
            }
       }
}

I'm still getting:

15 Error: Access of possibly undefined property amplitudeLeft through a reference with static type org.flixel:FlxSound.
15 Error: Access of possibly undefined property amplitudeRight through a reference with static type org.flixel:FlxSound.

yadurajiv

  • Member
  • **
  • Posts: 35
  • Karma: +1/-0
  • ~.^ wut you say?
    • View Profile
    • the rant
Re: How to see amplitude?
« Reply #5 on: Thu, Jun 7, 2012 »
This is the code you just posted, some parts commented out and a different mp3

Code: [Select]
package
{
       import org.flixel.*;
   //import flash.display.Sprite;
   //import org.flixel.FlxGroup;
   //import org.flixel.FlxG;
   //import org.flixel.FlxSound;
   //import Levels.*;
 
       public class amp2 extends FlxState
       {

[Embed(source = 'data/end.mp3')] public var Music01:Class;
private var mus:FlxSound;

            override public function create():void
            {
super.create();

mus = new FlxSound();
mus.loadEmbedded(Music01);
mus.play();
            }
 
            override public function update():void
            {
mus.update(); // amplitude below will be 0 without calling update

trace(mus.amplitudeLeft);
trace(mus.amplitudeRight);

                super.update();
            }
       }
}

and it works - http://grab.by/e1Y8

You will only get this error when that property is not declared in that class, which means it should work with the latest flixel. Are you sure you downloaded the latest master - https://github.com/AdamAtomic/flixel/zipball/master
^___________^

Venks

  • Member
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: How to see amplitude?
« Reply #6 on: Thu, Jun 7, 2012 »
Derp. Yeah. I didn't have the latest flixel. Downloaded the wrong thing. Thanks for the persistence with me. I really appreciate it. Everything is working awesomely. Thank you!