Click here to Skip to main content
15,894,460 members
Home / Discussions / C#
   

C#

 
Questionxsd? Pin
dec8227-Dec-08 18:06
dec8227-Dec-08 18:06 
AnswerRe: xsd? Pin
Lev Danielyan27-Dec-08 20:24
Lev Danielyan27-Dec-08 20:24 
AnswerRe: xsd? Pin
Aman Bhullar27-Dec-08 22:37
Aman Bhullar27-Dec-08 22:37 
GeneralRe: xsd? Pin
Lev Danielyan28-Dec-08 1:58
Lev Danielyan28-Dec-08 1:58 
QuestionProjects/Libraries On Tuning? Pin
Brandon X.27-Dec-08 14:44
Brandon X.27-Dec-08 14:44 
AnswerRe: Projects/Libraries On Tuning? [modified] Pin
Ravadre28-Dec-08 17:32
Ravadre28-Dec-08 17:32 
QuestionRe: Projects/Libraries On Tuning? Pin
Brandon X.29-Dec-08 6:47
Brandon X.29-Dec-08 6:47 
AnswerRe: Projects/Libraries On Tuning? Pin
Ravadre29-Dec-08 7:33
Ravadre29-Dec-08 7:33 
Hello,

In my library I use few FFT algorithms, just for fun, the best and easiest to use and understand was FFT algorithm in AForge library (100% c#) (by Andrew Kirillov, who writes greats articles on CP.com btw Smile | :) ).
The mystery of DFT (Discrete Fourier Transform)is, that it simply converts data from time-domain to frequency-domain (now mathematicans will scratch simply and write few books on how hard, complicated and beatiful it is, but for now - we don't need that knowledge).
FFT is nothing more then algorithm of computing DFT efficiently, so I will use FFT term from now on.

And now quick tutorial on FFT and sound data:
What you have when capturing sound from microphone is buffer of data, this data represents how sound has changed over time, so it's in time-domain. Now, what you have to do is compute F = FFT(T), where T is your time domain data, and what you will have in result is the same data, but in frequency domain. You should get array of complex numbers (or 2 double arrays, 1st representing Re part, 2nd representing Im part), if algorithm from this program returns doubles, I assume it computes magnitude of complex numbers, which is OK for your purpose (you would have to compute it anyway from normal FFT algorithm). So, what we've got now is:
T - array of input data (sound we've catched).<br />
F - array of output data (magnitudes of complex numbers computed by FFT)<br />
length(T) == length(F)


Now we have to find which frequency has the highest magnitude. We iterate over our array and find index with the highest value - that's the easy part.
So now we also have
fi - Index in array of F with greatest value

Now the question is how to get frequency of that sound. The answer is:
double freqStep = sampling_rate / length(F)

Now, if fe. your fi = 50, sample_rate = 44100 (which is standard value), and you will catch 4096 samples (which means, your T tables has length od 4096, and that means, your F table has length of 4096), the most significant frequency in your sound probe is:
Freq = 50 * (44100 / 4096)

If you analyse this, you can see, that the longer probes you will have, the smaller freqStep will be, and that means you will analyze sound frequency better (more accurate), but you will have to catch sound longer.

Now the last part is how to convert Freq to pitch (C, C#, D ...). I don't know how does it look for guitar, but in piano 1st key has frequency of 27.5Hz, which is A sound, and piano has 88 keys, so We have to compute help table:
pitches = new double[88];
pitches[0] = 27.5;

double step = Math.Pow(2, 1.0 / 12.0);

for (int i = 1; i < 88; ++i)
{
	pitches[i] = pitches[i - 1] * step;
}


Now, to get pitch, we find index that value is closest to Freq, fe. If we have Freq=445.0, the closest index will be 48 (which has value of 440). Now, because 1st value in our array is A pitch, and we have 12 pitches, we can get pitch like that:
string GetPitch(int pitchindex)
{
int rest = pitchindex % 12;

switch (rest)
{
case 0: return "A";
	case 1: return "A#";
	case 2: return "H";
	case 3: return "C";
	case 4: return "C#";
	case 5: return "D";
	case 6: return "D#";
	case 7: return "E";
	case 8: return "F";
	case 9: return "F#";
	case 10: return "G";
	case 11: return "G#";
}

throw new Exception("?");
}

GeneralRe: Projects/Libraries On Tuning? Pin
Brandon X.29-Dec-08 8:10
Brandon X.29-Dec-08 8:10 
GeneralRe: Projects/Libraries On Tuning? Pin
Ravadre29-Dec-08 8:16
Ravadre29-Dec-08 8:16 
QuestionRe: Projects/Libraries On Tuning? [modified] Pin
Brandon X.29-Dec-08 19:29
Brandon X.29-Dec-08 19:29 
AnswerRe: Projects/Libraries On Tuning? Pin
Ravadre30-Dec-08 4:42
Ravadre30-Dec-08 4:42 
QuestionRe: Projects/Libraries On Tuning? [modified] Pin
Brandon X.31-Dec-08 10:24
Brandon X.31-Dec-08 10:24 
AnswerRe: Projects/Libraries On Tuning? Pin
Ravadre31-Dec-08 12:35
Ravadre31-Dec-08 12:35 
QuestionC# .NET Windows Media Player WM_COPYDATA *whimper* Pin
spamoom27-Dec-08 13:44
spamoom27-Dec-08 13:44 
AnswerRe: C# .NET Windows Media Player WM_COPYDATA *whimper* Pin
Richard Andrew x6427-Dec-08 14:45
professionalRichard Andrew x6427-Dec-08 14:45 
QuestionRe: C# .NET Windows Media Player WM_COPYDATA *whimper* Pin
spamoom28-Dec-08 0:13
spamoom28-Dec-08 0:13 
AnswerRe: C# .NET Windows Media Player WM_COPYDATA *whimper* Pin
Richard Andrew x6428-Dec-08 1:36
professionalRichard Andrew x6428-Dec-08 1:36 
GeneralRe: C# .NET Windows Media Player WM_COPYDATA *whimper* Pin
spamoom28-Dec-08 2:04
spamoom28-Dec-08 2:04 
Question[Message Deleted] Pin
TwoSocks27-Dec-08 13:40
TwoSocks27-Dec-08 13:40 
Questionlock the windows xp Pin
abu rakan27-Dec-08 12:06
abu rakan27-Dec-08 12:06 
AnswerRe: lock the windows xp Pin
User 665827-Dec-08 13:00
User 665827-Dec-08 13:00 
Questionavi file Pin
manishkumarcse27-Dec-08 11:57
manishkumarcse27-Dec-08 11:57 
GeneralRe: avi file Pin
Luc Pattyn27-Dec-08 12:38
sitebuilderLuc Pattyn27-Dec-08 12:38 
AnswerRe: avi file Pin
Code Soldier28-Dec-08 5:25
Code Soldier28-Dec-08 5:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.