title: Bass.dll just Spectrum data C#
body: <p>I am trying to create a game based on beat and spectrum detection. I am currently stuck on that  my function returns not quite what i want, beacose the array is not fully assigned. The last element which is filled is wrong and i don't know why.</p>
  
  <p>The array size is 20 and this code fills only 12 or evven less</p>
  
  <pre><code>  float[] rmsData;
  
      public void spektrsw(int barrcount, bool lefton, out float[] spectrumData)
      {
         spectrumData = new float[barrcount]; 
               //defining array in which will  be spectrum data
          if (isPlaying) //check if sound is playing
          {
              int lenght = (int)Bass.BASS_ChannelSeconds2Bytes(ActiveStreamHandle, 1.0); //gets and sets lenght
              int rmsDataArraySize = Math.Abs(lenght / 4); 
                //calculating FFT data or RMS array size 
              if (rmsData == null || rmsData.Length &lt; rmsDataArraySize)
                   rmsData = new float[rmsDataArraySize]; 
                      //defining new array if old one has lenght smaler
  
              lenght = Bass.BASS_ChannelGetData(ActiveStreamHandle, rmsData, lenght); //geting lenght FFT data
              rmsDataArraySize = lenght / 4; //calculating FFT data or RMS array size 
  
              int times = (int)(rmsDataArraySize / (barrcount * 2)) + 1; 
     //calculating how many times loop will continue until the loop will go to next index
  
              int index = 0; 
     // creating index variable which will point to an element in array
  
              for (int counter = 0; counter &lt; rmsDataArraySize; counter++)
              {
  
                  if (counter % 2 == 0 || counter == 0) //For left channel
                  {
                     if(lefton) //which channel am i analysing
                      spectrumData[index] = spectrumData[index] +  Math.Abs(rmsData[counter]);
                      //adding data to array
                  }
                  else
                  {
                      if (!lefton) //which channel am i analysing
                          spectrumData[index] = spectrumData[index] + Math.Abs(rmsData[counter]);
                      //adding data to array
                  }
  
                  if (counter == times) //check to see if index needs to be increased
                  {
  
                      spectrumData[index] = spectrumData[index] / times;
                      //this is for calculating avarege in one bar since
                      //I combined lots of data in one bar
  
                      spectrumData[index] = spectrumData[index] * 1000f;
  
                      index++;//increasing index
                      times = times + counter;
  
                  }
              }                
          }          
      }
  </code></pre>
  
  <p>Questions are:</p>
  
  <ol>
  <li>Am i doing right?</li>
  <li>Why it doesn't return all the values?</li>
  <li>What is the easyest way to get data i need?</li>
  </ol>
  
  <p>Thanq for your answers allready.</p>
  
  <p>And I am sorry for my bad english......</p>
  
  <p>[EDIT]</p>
  
  <p>I have found out that the if statement or the way i calculet Times is wrong:-(</p>
  
  <p>So if you have a better idea how to get data from array of 4000 elements to an array of 20 i would be pleased if you posted your advice here.</p>