1

ビートとスペクトルの検出に基づいてゲームを作成しようとしています。私は現在、配列が完全に割り当てられていないため、関数が必要なものを返さないことに固執しています。埋められた最後の要素が間違っていて、その理由がわかりません。

配列サイズは 20 で、このコードは 12 以下しか埋めません。

  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 < 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 < 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;

                }
            }                
        }          
    }

質問は次のとおりです。

  1. 私は正しくやっていますか?
  2. すべての値を返さないのはなぜですか?
  3. 必要なデータを取得する最も簡単な方法は何ですか?

すでに回答ありがとうございます。

そして、私の悪い英語で申し訳ありません......

[編集]

if ステートメントまたは Times の計算方法が間違っていることがわかりました:-(

したがって、4000 要素の配列から 20 要素の配列にデータを取得する方法についてより良いアイデアがあれば、ここにアドバイスを投稿していただければ幸いです。

4

0 に答える 0