PDA

View Full Version : سوال در مورد کد دو متد



p30better
چهارشنبه 25 تیر 1393, 02:00 صبح
سلام می خواستم یدونم این دو تا متد کارشون دقیقا چیه ...


این پایین دو مقدار فرکانس و صدا رو میگیره بقیش رو نمی دونم


private WaveSound CreateBeep(int frequencyHz, int volumne)
{
// samples for 1/beepLength seconds
short[] samples = new short[waveSound.Format.SamplesPerSec / beepLength];
double xValue = 0;
short yValue;

double xStep = (2 * Math.PI) / waveSound.Format.SamplesPerSec; // 1 Hz
xStep = xStep * frequencyHz;

for (int n = 0; n < samples.Length; n++) {
xValue += xStep;
yValue = (short)(Math.Sin(xValue) * volumne);
samples[n] = yValue;
}

WaveSound beep = new WaveSound(waveSound.Format, samples);
return beep;
}






این یکی هم یک مقدار مییگیره که tolerance هست بقیش رو نمی دونم


public void FindAnything(short tolerance) {
//size of scan window in samples
int scanWindowSize = waveSound.Format.SamplesPerSec / beepLength;
//size of scan window in seconds
float scanWindowSizeSeconds = (float)scanWindowSize / (float)waveSound.Format.SamplesPerSec;

int startIndex = -1;
int endIndex = -1;
int countSilentSamples = 0;
for (int n = 0; n < waveSound.Count; n++) {
if (Math.Abs(WaveSound[n]) > tolerance) { //found a sound
countSilentSamples = 0;
if(startIndex < 0){
startIndex = n;
}
} else if (startIndex > -1) { //searched and found silence
countSilentSamples++;
if (countSilentSamples == scanWindowSize) {
endIndex = n - scanWindowSize;
NotifyOnBeep(startIndex, endIndex, scanWindowSizeSeconds);

//scan next time window
countSilentSamples = 0;
startIndex = -1;
}
}
}

if (startIndex > -1) { //wave ends with a beep
NotifyOnBeep(startIndex, waveSound.Count-1, scanWindowSizeSeconds);
}

private void NotifyOnBeep(int startIndex, int endIndex, float silentSeconds) {
if (BeepFound != null) {
//get the second in the wave at which the sound stops
float second = (float)endIndex / (float)waveSound.Format.SamplesPerSec;

//notify
BeepFound(this, new BeepFoundEventArgs(
new Beep(startIndex, endIndex,
second - silentSeconds, second)));
}







تشکر :قلب:

abbas.oveissi
چهارشنبه 25 تیر 1393, 04:09 صبح
من تابع اول رو نگاه کردم و تقریبا آسون هم هست. خط اول اومده بر اساس طول مدت صدا و نرخ نمونه برداری تعداد نمونه هارو پیدا کرده.بعد اومده محاسبه کرده که هر نمونه بر اساس فرکانسی که دادین بهش باید دامنه اش چقدر باشه.یک موج سینوسی با اون فرکانس شما درست میکنه دیگه.بعد هم آرایه نمونه هارو تبدیل میکنه به WaveSound تا بشه پخشش کرد.
دومی طولانیه،بقیه میان بهت میگن:لبخند:
این عکس هم برای اینکه بفهمید تابع سینوس و XStep به چه دردی میخوره ،در واقع با کمک اونا اومده این نقطه قرمز هارو حساب کرده.

121153