0
0

Hi,
I’m trying to get the frequency of a song every second. I’d rather preprocess this so I am using the NOSOUND_NRT parameter for the output type. However, I’m quite new to FMOD in C# and am wondering how I’d go about doing this. My initial thought is this, but I’d like to know if there is a more efficient way of doing it.
I would load the audio file, and use a loop which stops once the end of the song is reached. I would then use Channel.SetPoint(X + 1, FMOD.TIME.MS). This would the be followed by Channel.GetFrequency. Store this in a list and loop. Have I gone wrong somewhere?
At the moment, I’m just trying to get the frequency at any point, but I always get the same number appearing. I get 22050 returned all the time, regardless of the song or at what point it is playing.
My current (no doubt erroneous :( ) code:

[code:3a2lu7qh]

        system.init(32, INITFLAG.NORMAL, (IntPtr)null);


        system.createSound("C:\\song.mp3", MODE.SOFTWARE, ref sound);

         system.playSound(CHANNELINDEX.FREE, sound, false, ref channel);


        system.setOutput(FMOD.OUTPUTTYPE.NOSOUND_NRT);
        channel.getFrequency(ref frequency);

        system.update();



         Timer myTimer = new Timer();
         myTimer.Elapsed += new ElapsedEventHandler( getFreqData );
         myTimer.Interval = 1000;
         myTimer.Start();


         while (Console.Read() != 0)
         {
         }






    }

    private static void getFreqData(object source, ElapsedEventArgs e)
    {




        Console.WriteLine(ik + " " + frequency.ToString() + "Hz");


        ik++;
    }[/code:3a2lu7qh]

Thanks for any clarification.

  • You must to post comments
0
0

Frequency in this context is the sample rate (samples/second). It is used for speeding things up and down. (i.e. an increase in samples per second means the song is playing faster than usual)

If you’re trying to get the spectrum of frequencies of the currently playing sound (Hz) that is entirely different.

You might want to use Channel::getSpectrum

Hope this helps,

-Pete

  • You must to post comments
0
0

Thanks Peter, that was the problem. I am getting something more realistic now, but I’ve noticed that if I play the same song twice, I get a different set of frequencies. I’ve altered the code to below. Where am I going wrong?
Thanks again

[code:2u5g5dzv]
system.init(32, INITFLAG.NORMAL, (IntPtr)null);

        system.createSound("C:\\Song.mp3", MODE.SOFTWARE, ref sound);


         system.playSound(CHANNELINDEX.FREE, sound, false, ref channel);






        system.setOutput(FMOD.OUTPUTTYPE.NOSOUND_NRT);





         Timer myTimer = new Timer();
         myTimer.Elapsed += new ElapsedEventHandler( getSpectrumData );
         myTimer.Interval = 1000;
         myTimer.Start();


         while (Console.Read() != 0)
         {
         }






    }

    private static void getSpectrumData(object source, ElapsedEventArgs e)
    {






        system.update();

        channel.getSpectrum(spectrum, 256, 0, DSP_FFT_WINDOW.TRIANGLE);



        for (int i = 0; i < 1; i++)
        {

            Console.WriteLine(ik + " " + spectrum[i].ToString() + "Hz");
        }





        ik++;
    }[/code:2u5g5dzv]
  • You must to post comments
0
0

Hi,
I scanned all my results and it seems that some of the frequencies correlate with each other when testing the same song. I, therefore, assume that any discrepancy is down to accuracy and the exact time the song is being checked. In order to overcome this and make it more efficient, is it possible to scan a song’s frequency spectrum without playing it? I’d like to obtain the frequency once every second for every song. Since I’d like to process a bunch of songs (without playing), what would be the best way to go about doing this?
(I’d thought I’d post it here as a follow up question, but I’d be more than happy to create a new post if that would be preferred).

Thank you.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.