Thread: Strange occurences!

  1. #1
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    122

    Strange occurences!

    Hi... I have the function:

    Code:
    unsigned int flanger(short int left, short int right){
    
      unsigned int retVal;
      
      /* process samples and put into variable delay buffer */
        retVal = 0;
        
        if (lReadPtr == 0){
        retVal = (calculateAverage(leftArray[lReadPtr],leftArray[(((SAMPLE_RATE/1000)*MAX_DELAY)-1)])) << 16;
    	printf("1.left: %8d,",calculateAverage(leftArray[lReadPtr],leftArray[(((SAMPLE_RATE/1000)*MAX_DELAY)-1)]));
      }
      else{
        retVal = (calculateAverage(leftArray[lReadPtr],leftArray[lReadPtr-1])) << 16;
        printf("1.left: %8d,",calculateAverage(leftArray[lReadPtr],leftArray[lReadPtr-1]));
      }
    
      if (startLFO != 0){
        if (rReadPtr == 0){
          retVal |= (calculateAverage(rightArray[rReadPtr],rightArray[(((SAMPLE_RATE/1000)*MAX_DELAY)-1)]));
    	  printf(" Right: %8d\n",calculateAverage(rightArray[rReadPtr],rightArray[(((SAMPLE_RATE/1000)*MAX_DELAY)-1)]));
    	}
        else{
          retVal |= (calculateAverage(rightArray[rReadPtr],rightArray[rReadPtr-1]));
    	  printf(" Right: %8d\n",calculateAverage(rightArray[rReadPtr],rightArray[rReadPtr-1]));
    	}
      }
      else{
        retVal |= dataR; /* return original data! */ 
    	printf(" Right: %8d\n",dataR);
      }
      
      return retVal;
    
    }
    
    
    main{
    
      short int left, right, outputL, outputR;
      unsigned int stuffed;
      
      left = getAudioData();
      right = getAudioData();
    
      stuffed = flanger(left, right);
      
      outputL = 0;
      outputR = 0;
    
      /* extract stereo information from raw int! */
      outputL = stuffed >> 16;
      outputR = stuffed & 0x0000FFFF;
    
      printf("2.Left: %8d, Right: %8d\n",outputL,outputR);
    
    }
    and for the output...

    Code:
    Flanger Audio Effect Program
    1.left:    -2203, Right:      -10
    2.Left:       -1, Right:      -10
    1.left:     7580, Right:      -21
    2.Left:       -1, Right:      -21
    1.left:     6985, Right:       -8
    2.Left:       -1, Right:       -8
    1.left:    14154, Right:       19
    2.Left:    14154, Right:       19
    1.left:    21780, Right:       64
    2.Left:    21780, Right:       64
    1.left:    21172, Right:       26
    2.Left:    21172, Right:       26
    1.left:    -5451, Right:       58
    2.Left:    -5451, Right:       58
    1.left:    -4244, Right:       37
    2.Left:    -4244, Right:       37
    1.left:    22508, Right:      -34
    2.Left:       -1, Right:      -34
    1.left:    29264, Right:       21
    2.Left:    29264, Right:       21
    1.left:    18884, Right:        3
    2.Left:    18884, Right:        3
    1.left:     3400, Right:      -38
    2.Left:       -1, Right:      -38
    1.left:     5340, Right:       21
    2.Left:     5340, Right:       21
    1.left:    13028, Right:       12
    2.Left:    13028, Right:       12
    1.left:    14227, Right:        4
    2.Left:    14227, Right:        4
    1.left:    14244, Right:        6
    2.Left:    14244, Right:        6
    1.left:    13285, Right:       34
    2.Left:    13285, Right:       34
    1.left:    -3112, Right:        5
    2.Left:    -3112, Right:        5
    1.left:    -4776, Right:        5
    2.Left:    -4776, Right:        5
    1.left:     9548, Right:      -19
    2.Left:       -1, Right:      -19
    1.left:    11018, Right:      -37
    2.Left:       -1, Right:      -37
    1.left:    22291, Right:      -15
    2.Left:       -1, Right:      -15
    1.left:    24025, Right:       43
    2.Left:    24025, Right:       43
    1.left:    14800, Right:       17
    2.Left:    14800, Right:       17
    1.left:    13260, Right:      -42
    2.Left:       -1, Right:      -42
    I dont understand why the left output keeps going to -1 randomly! is it an obvious thing Im doing wrong??? Thanks!
    Many junglists take pride in their belongin to what may be referred to as a globalised drum & bass subculture, as a subculture though, it is not nearly as distinct at gothic or punk!

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    -1 is assocated with the newline, somewhere in your code add on and if getchar() != '\n';. I would tell you where to add it but you have only posted a cool function. Thats the only reason why I could think that is occuring but you only posted half the code.
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

  3. #3
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    122
    Hi! ...I will post the full function! ...its an array of short ints, not ASCII data! give me a few mins to put my code into a decent format!!!
    Many junglists take pride in their belongin to what may be referred to as a globalised drum & bass subculture, as a subculture though, it is not nearly as distinct at gothic or punk!

  4. #4
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    122

    full source code...

    Removed it cause i don't want anyone using this code for the next 5months as its me final year project at uni an im not gonna risk gettin screwed over for plagerism if anyone else is thinking of doin similar projects!!!
    Last edited by bobthebullet990; 01-08-2007 at 08:23 AM.
    Many junglists take pride in their belongin to what may be referred to as a globalised drum & bass subculture, as a subculture though, it is not nearly as distinct at gothic or punk!

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    not random, just when Right is < 0
    seems to be a problem of undefined behavior with bit-wise operations using ints...
    You should really check the results of all your operations, hard to determine where the problem is without knowledge of all variable types you are using without explicit conversions
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    122
    hmmm!!! indeed it seems that way!!! ...I will have to mess around with the data a bit more then I guess!!! arrgghhh!!!
    Many junglists take pride in their belongin to what may be referred to as a globalised drum & bass subculture, as a subculture though, it is not nearly as distinct at gothic or punk!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  2. number of occurences
    By kocika73 in forum C Programming
    Replies: 2
    Last Post: 01-29-2005, 12:44 PM
  3. Very strange bug...
    By JaWiB in forum Tech Board
    Replies: 6
    Last Post: 04-27-2003, 01:56 PM
  4. strange strange functions
    By threahdead in forum C Programming
    Replies: 4
    Last Post: 10-13-2002, 05:31 PM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 04:00 PM