Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Object not being update till end of loop

  • 27-10-2005 11:31am
    #1
    Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭


            // Objects used
            // FloatControl fc;
            // int fadetime = 3;
    
    	public void run()
    	{
    		float interval = 10f;
    		float increment = 80f/interval;
    		float newValue = -80f;
    
    		System.out.println(increment);
    
    		for(int i = 0; i < 1000; i++)
    		{
    			setVolume(newValue);
    			try
    			{
    				Thread.sleep((fadeTime)/1000);
    			}
    			catch(Exception e)
    			{
    				System.out.println(e);
    			}
    
    			newValue = getVolume() + increment;
    
    		}
    
    	}
    	public void setVolume(float value)
    	{
    		fc.setValue(value);
    	}
    	public float getVolume()
    	{
    		return fc.getValue();
    	}
    

    The FloatControl object controls the volume on a SourceDataLine:

    Starting volume is -80, in order to reach 0 over 1000 iterations it needs to increment by .08.

    When incremented, the new value won't update in the float control object, when the loop ends the new value of 0 is there. As you might notice i'm trying to produce a fade effect.

    In fact i've modified the code so much that it isn't incrementing in the right amounts but don't worry about that, it's the fact that it won't change no matter what I put in that's annoying me.



    Sorry if this seems a bit senseless, brain no function properly.


Comments

  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Try putting a call to DoEvents() in the SetVolume, after the value is written to fc.

    RTFM if you need to find out what DoEvents is about :)

    jc


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    bonkey wrote:
    Try putting a call to DoEvents() in the SetVolume, after the value is written to fc.

    RTFM if you need to find out what DoEvents is about :)

    jc

    That appears to be a VB method, forgot to mention that I'm writing in java.

    yield() in java appears to be a DoEvents() equivalent but doesn't solve my problem.


  • Closed Accounts Posts: 324 ✭✭madramor


    it would be a good idea to post the FloatControl code
    and
    format your code to make it easier to read


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    madramor wrote:
    it would be a good idea to post the FloatControl code
    and
    format your code to make it easier to read

    FloatControl is a class in the javax.sound.sampled API.

    What is wrong with the formatting of my code ? It may not be standard but it ain't hard to read.


  • Closed Accounts Posts: 1,502 ✭✭✭MrPinK


    // int fadetime = 3;
    ...
    Thread.sleep((fadeTime)/1000);
    
    If fadetime really is 3 then the thread will be sleeping for 0 milliseconds.

    EDIT:

    While I don't actually have a clue what this class does, the shift method in the API sounds like it does what you're trying to do here
    public void shift(float from, float to, int microseconds)

    Changes the control value from the initial value to the final value linearly over the specified time period, specified in microseconds. This method returns without blocking; it does not wait for the shift to complete. An implementation should complete the operation within the time specified. The default implementation simply changes the value to the final value immediately.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Slaanesh wrote:
    That appears to be a VB method, forgot to mention that I'm writing in java.

    For some reason I mistook it to be C#, hence the MS-ish suggestion.

    Ignore me.

    jc


  • Closed Accounts Posts: 324 ✭✭madramor


    Slaanesh wrote:
    What is wrong with the formatting of my code ? It may not be standard but it ain't hard to read.
    in order to view the code you posted you have to use 2 scroll bars
    1 on the browser and 1 on the code, for a few lines of code

    your code looks fine so it must be something to do with
    how you are using floatcontrol or controlling the threads
    so you will have to post the code where you create
    floatcontrol and use it.

    i've never used FloatControl or the sound api so if its
    not a standard mistake i wouldn't see it
    public class Test {
        float f;   
        public Test() {
        }
        public static void main(String args[]){
            Test t = new Test();
            t.run();
        }
        public void run() {
            float interval = 10f;
            float increment = 80f/interval;
            float newValue = -80f;
            System.out.println(increment);//8.0
            for(int i = 0; i < 1000; i++) {
                setVolume(newValue);
                try {
                    Thread.sleep((3)/1000);
                } catch(Exception e) {
                    System.out.println(e);
                }
                newValue = getVolume() + increment;
                System.out.println("Fade:"+getVolume());//-72.0 to 7920.0
            }
            System.out.println("Result:"+getVolume());//7912.0
        }
        public void setVolume(float value) {
            f = value;
        }
        public float getVolume() {
            return f;
        }
    }
    


  • Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭Slaanesh


    Ah I see what you mean about the layout, I'm running a high resolution so it looks fine to me. That's the way it pasted from textpad, seemed to indent a bit more than usual.

    I'll try a few of the different suggestions in this thread tomorrow, thanks guys.


    madramor wrote:
    in order to view the code you posted you have to use 2 scroll bars
    1 on the browser and 1 on the code, for a few lines of code

    your code looks fine so it must be something to do with
    how you are using floatcontrol or controlling the threads
    so you will have to post the code where you create
    floatcontrol and use it.

    i've never used FloatControl or the sound api so if its
    not a standard mistake i wouldn't see it


Advertisement