Results 1 to 6 of 6
  1. #1
    sunshine64 is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Unhappy Issue with nested for loop

    Perhaps I'm an idiot and just doing this wrong but this is what I have and it must be going in an endless loop because nothing plays. Here is the method:
    Java Code:
    public Sound myMix(Sound mixIn, Sound mixIn1,Sound mixIn2){
        Sound target = new Sound(getLength());
        
        int sampleValue, mixValue,newValue;
    
        
        for (int srcIndex=0,trgIndex=0;
             srcIndex < getLength() && srcIndex < mixIn.getLength();
             srcIndex++,trgIndex++)
        {
        	for (int srcIndex1=0,trgIndex1=0;
            srcIndex1 < getLength() && srcIndex1 < mixIn1.getLength();
            srcIndex1++,trgIndex1++)
       {
        	    	for (int srcIndex2=0,trgIndex2=0;
        	        srcIndex2 < getLength() && srcIndex2 < mixIn2.getLength();
        	        srcIndex2++,trgIndex2++)
       {
          sampleValue = this.getSampleValueAt(srcIndex) + this.getSampleValueAt(srcIndex1) + this.getSampleValueAt(srcIndex2);
          mixValue = mixIn.getSampleValueAt(srcIndex) + mixIn1.getSampleValueAt(srcIndex1)+ mixIn2.getSampleValueAt(srcIndex2);
          newValue = (int)(mixValue) + (int)(sampleValue);
          target.setSampleValueAt((trgIndex + trgIndex1 + trgIndex2),newValue);
       }
       }}
    	return target;}}
    Last edited by Eranga; 02-03-2011 at 02:40 AM. Reason: code tags added

  2. #2
    Join Date
    Dec 2008
    Location
    Manchester England
    Posts
    14
    Rep Power
    0

    Default

    You cannot get any sound because that code is just a load of crap basicly. If i was you i would go to a bookstore and buy myself a nice Java Basics Book, pop the book under my arm, go home, make myself a large mug of cofee and sit down and read. Code tags would help as well. By the way your probably not an idiot, an idiot would of tried to explain what all them variables were doing.

  3. #3
    sunshine64 is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default You are right

    Yeah, I kinda thought the code was crap so I scrapped it and am in the process of starting over. I wish I could find a good book that explains things a bit better. I've only had one semester of Java and I did manage to pull an A in it so I don't think I'm a total idiot...just a partial one.

    Thanks for the advice.

  4. #4
    Join Date
    Dec 2008
    Location
    Manchester England
    Posts
    14
    Rep Power
    0

    Default

    you are not an idiot, that was me being stupid and i apologise.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by sunshine64 View Post
    Yeah, I kinda thought the code was crap so I scrapped it and am in the process of starting over. I wish I could find a good book that explains things a bit better. I've only had one semester of Java and I did manage to pull an A in it so I don't think I'm a total idiot...just a partial one.

    Thanks for the advice.
    Do not try to convert everything into piece of code which comes to your mind. That's why your code seems so busy. Spend more time on model what you want to do first.

    Take a piece of paper and write down step by step on it, that what you want to do in your application. Then build the logic on each step, and if you have a better understanding about the Java basis it's much easy.

    Later start to convert all your logic into a Java code.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    @OP, please use code tags also when you are posting again. Unformatted codes are really hard to read. If you don't know how to do that, check on my forum signature. You can find a relevant link there.

Similar Threads

  1. Nested For Loop algorithm
    By but43r in forum Advanced Java
    Replies: 5
    Last Post: 01-11-2011, 08:52 AM
  2. Does Hashmap or Nested Loop use more memory?
    By TheGame in forum New To Java
    Replies: 2
    Last Post: 10-21-2010, 09:22 AM
  3. can some one help me with nested loop?
    By keycoffee in forum New To Java
    Replies: 10
    Last Post: 01-25-2010, 02:49 AM
  4. nested for loop question
    By javabob in forum New To Java
    Replies: 3
    Last Post: 05-20-2008, 11:00 PM
  5. Nested For Loop
    By yuchuang in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 01:11 PM

Posting Permissions

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