p30better
چهارشنبه 25 تیر 1393, 03: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)));
}
تشکر :قلب:
این پایین دو مقدار فرکانس و صدا رو میگیره بقیش رو نمی دونم
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)));
}
تشکر :قلب: