Author Topic: record and fft question  (Read 3034 times)


  • Posts: 4
record and fft question
« on: 26 Mar '12 - 10:36 »
hello im beginner programmer. and im not good at english... really... so please understand me.

language: c#

i want recording with mic. and get frequency data. mic is on the notebook computer.

so my code is:

Code: [Select]
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero));
if (!Bass.BASS_RecordInit(-1)) {
                Console.WriteLine("Can't initialize device");
int handle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, null, IntPtr.Zero);
Bass.BASS_ChannelPlay(handle, false);
float[] fft = new float[512];
Bass.BASS_ChannelGetData(handle, fft, (int)BASSDATA.Bass_DATA_FFT1024));
i guess data is stored fft array. with only this code. so
Code: [Select]
for (int i = 0; i < fft.length; ++i) {
console.writeline(fft [i]);

but fft's every element is 0. maybe there are problems... T.T

i think record is running on thread.. but this program is terminated in 1 second.
when recording? i think record takes time. but this program is immediately terminated.

if data is stored, i don't understand data's meaning.
what is array's index? and value?
and BASSDATA.Bass_DATA_FFT1024 -> what is 1024? i want mic input -> fft -> make score
what number i have to use?

Bass.BASS_ChannelGetData function is called 1 per music. -> right?

i read api document... with my not good english skill.
and Bass.BASS_ErrorGetCode result is all BASS_OK
and windows inner program <recorder> is well excuted.

please help me. im beginner. so detail explanation please. thank you~
« Last Edit: 26 Mar '12 - 19:13 by 0708pes »


  • Posts: 4
Re: record and fft question
« Reply #1 on: 26 Mar '12 - 10:42 »
console.writeline(fft); -> fft with square brackets i


  • Posts: 160
Re: record and fft question
« Reply #2 on: 26 Mar '12 - 19:01 »
Please put your Code in Code-Tags in the Forum to make it more easy to read and more easy to distinguish from the Rest of your Post.

The ChannelGetData returns an Array containing FFT Bins/Values, the Index means which Frequency it is, the Value shows you the Amplitude of this Frequency ("How Loud" or "How much contained in the Sample it is").

You can calculate the Frequency of each Value in the Array like this:

Frequency = Index * sampleRate / FFTSize

FFTSize is 1024 in your Case !

If you want it even more easy, just use FFTIndex2Frequency with the right Parameters which works the same Way or the same Way with some Interpoliations, I am not sure about this.

i want mic input -> fft -> make score

Please explain that, what "score" do you need from the Microphone Sound Input?

If you just want to get the peak Frequency from your Channel, you can also use DetectPeakFrequency from Bass. It does the whole thing, getting FFT, calculating Frequencies, getting Frequency with highest Amplitude automatically.

Returns the frequency (in Hz) containing the maximum energy within the current FFT data when calling this method.


  • Posts: 4
Re: record and fft question
« Reply #3 on: 26 Mar '12 - 19:40 »
very very thank you~ gnag. thanks to you, i understand fft array's meaning.

and i still wonder about q1, q2, q4.

score is music score.(band score?)

music -> mic -> frequency analysis -> fft -> get note(tune? key?) -> make score.

but that code's return array with all value is zero. so i can't get any data.

i think

BASS_channelplay(record start) -> immediately BASS_channelgetdata -> immediately veryfy arrays value.
in this procedure when record? recording need time. but BASS_channelgetdata immediately return. so not record.
BASS_channelgetdata function call is one time. isn't it? if no, push in the loop?

please correct my wrong idea. thank you!


  • Posts: 160
Re: record and fft question
« Reply #4 on: 26 Mar '12 - 19:59 »
You can try to use a Timer with an interval of for example 100ms which calls ChannelGetData to get FFT Results and outputs the Peak Frequency to make it be called in a Loop. The Array can be full of Zeroes in the first Call but after some Calls it should be returning real Values if not, you made something wrong.

As your q1&q4 describe you Program only calls the FFT Function immediately after starting to Record and finishes then, please adjust it like i described above in this Post.


  • Posts: 4
Re: record and fft question
« Reply #5 on: 27 Mar '12 - 05:49 »
thanks to you, i can get fft data and peak frequency.

thank you very much~