⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen_05.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
    return Error::handle(name(), L"computePulse",			 ERR_ZFREQ, __FILE__, __LINE__);  }  // check if the sample frequency is at least twice the signal  // frequency  //  if ((Float)sample_freq_d < ( 2 * frequency_d)) {    return false;  }  // compute the nomner of samples in a frame  //  long length;  length = (long)(Integral::round(frame_dur_d * sample_freq_d));  // set the length of the output vector  //  pulse_wave_a.setLength(length);  // declare local variables  //  float pulse_width;  float pulse_duration;  long shift_samples;  // compute the width, duration and shift of the pulse  //  pulse_width = ((float)duty_cycle_d * (float)sample_freq_d)    / ((float)frequency_d * 100.0);    pulse_duration = (double)sample_freq_d / frequency_d;    shift_samples = (long)((long)accum_frame_d(channel_index_a) *			 (double)sample_freq_d * (double)frame_dur_d +			 phase_d * pulse_duration / (2.0 * Integral::PI)			 + 0.5);  float ratio = shift_samples / pulse_duration;  long k = (long)ratio + 1;  long last_frame_length = 0;  long last_frame_index    = (long)(Integral::ceil(signal_duration_d / frame_dur_d));    // dealing with computing last frame  //  if (accum_frame_d(channel_index_a) >= last_frame_index - 1) {    last_frame_length = (long)(signal_duration_d * sample_freq_d -			       frame_dur_d * sample_freq_d *			       accum_frame_d(channel_index_a));        // case when shift is greater than or equal to zero    //    if (shift_samples >= 0) {      for (long i = 0; i < last_frame_length; i++) {		// compute the positive portion of the pulse	//	if (((shift_samples + i) >= (long)((k - 1) * pulse_duration + 0.5)) &&	    ((shift_samples + i) < (long)((k - 1) * pulse_duration +					  pulse_width + 0.5))) {	  pulse_wave_a(i) = amplitude_d + bias_d;	}	// compute the non-pulse portion	//	else {	  pulse_wave_a(i) = 0.0 + bias_d;	}	// increment the counter	//	if (k * pulse_duration == shift_samples + i + 1) {	  k = k + 1;	}      }    }    // case when shift is less than zero    //    if (shift_samples < 0) {      for (long i = 0; i < last_frame_length; i++) {	// set pulse wave signal point to zero when the x coordinate of the	// point < 0	//	if ((shift_samples + i - 1) < 0) {	  pulse_wave_a(i) = 0.0 + bias_d;	  k = 0;	}	else {	  	  // compute the positive portion of the pulse	  //	  if (((shift_samples + i) >= (long)((k - 1) * pulse_duration + 0.5))	      && ((shift_samples + i) <= (long)((k - 1) * pulse_duration +						pulse_width + 0.5))) {	    pulse_wave_a(i) = amplitude_d + bias_d;	  }	  // compute the non-pulse portion	  //	  else {	    pulse_wave_a(i) = 0.0 + bias_d;	  }	}	// increment the counter	//	if ((k * pulse_duration) == (shift_samples + i)) {	  k = k + 1;	}      }    }        for (long i = last_frame_length; i < length; i++) {            // set pulse wave signal point to zero for the unspecified points of      // last frame      //      pulse_wave_a(i) = 0.0;    }          }    // dealing with computing other frames  //  else {    // case when shift is greater than or equal to zero    //    if (shift_samples >= 0) {      for (long i = 0; i < length; i++) {		// compute the positive portion of the pulse	//	if (((shift_samples + i) >= (long)((k - 1) * pulse_duration + 0.5)) &&	    ((shift_samples + i) < (long)((k - 1) * pulse_duration +				      pulse_width + 0.5))) {	  pulse_wave_a(i) = amplitude_d + bias_d;	}	// compute the non-pulse portion	//	else {	  pulse_wave_a(i) = 0.0 + bias_d;	}	// increment the counter	//	if (k * pulse_duration == shift_samples + i + 1) {	  k = k + 1;	}      }    }    // case when shift is less than zero    //    if (shift_samples < 0) {      for (long i = 0; i < length; i++) {		// set pulse wave signal point to zero when the x coordinate of the	// point < 0	//	if ((shift_samples + i - 1) < 0) {	  pulse_wave_a(i) = 0.0 + bias_d;	  k = 0;	}	else {	  // compute the positive portion of the pulse	  //	  if (((shift_samples + i) >= (long)((k - 1) * pulse_duration + 0.5))	      && ((shift_samples + i) <= (long)((k - 1) * pulse_duration +						pulse_width + 0.5))) {	    pulse_wave_a(i) = amplitude_d + bias_d;	  }	  // compute the non-pulse portion	  //	  else {	    pulse_wave_a(i) = 0.0 + bias_d;	  }	}	// increment the counter	//	if ((k * pulse_duration) == (shift_samples + i)) {	  k = k + 1;	}      }    }  }    //  exit gracefully  //  return true;}// method: computeTriangle//// arguments://  VectorFloat& triangle_wave: (output) triangle wave//  long channel_index: (input) channel_index//// return: a boolean value indicating status//// this method computes triangle wave sample points//boolean Generator::computeTriangle(VectorFloat& triangle_wave_a,				   long channel_index_a) {  // check if the frequency is not zero  //  if (frequency_d == (Float)0) {    return Error::handle(name(), L"computeTriangle",			 ERR_ZFREQ, __FILE__, __LINE__);  }    // check if the sample frequency is at least twice the signal  // frequency  //  if ((Float)sample_freq_d < (2 * frequency_d)) {    return false;  }  // compute the number of samples in a frame  //  long length;  length = (long)(Integral::round(frame_dur_d * sample_freq_d));  // set the length of the output vector  //  triangle_wave_a.setLength(length);  // declare local variables  //  float triangle_width;  float triangle_duration;  long shift_samples;    triangle_width = ((float)duty_cycle_d * (float)sample_freq_d)    / (100.0 * (float)frequency_d);    triangle_duration = (double)sample_freq_d / frequency_d;    shift_samples = (long)((long)accum_frame_d(channel_index_a) *			 (double)sample_freq_d *			 (double)frame_dur_d +			 phase_d * triangle_duration / (2.0 * Integral::PI)			 + 0.5);    float ratio = shift_samples / triangle_duration;  long k = (long)ratio + 1;  float slope = ((float)amplitude_d * 2.0) / ((float)triangle_width);  long last_frame_length = 0;  long last_frame_index = (long)(Integral::				 ceil(signal_duration_d / frame_dur_d));    // dealing with computing last frame  //  if (accum_frame_d(channel_index_a) >= last_frame_index - 1) {    last_frame_length = (long)(signal_duration_d * sample_freq_d -			       frame_dur_d * sample_freq_d *			       accum_frame_d(channel_index_a));    // case when shift is greater than or equal to zero    //    if (shift_samples >= 0) {      for (long i = 0; i < last_frame_length; i++) {	// compute samples of the positive slope	//	if (((shift_samples + i) >= (long)((k - 1) * triangle_duration + 0.5))	    && ((shift_samples + i) < (long)((k - 1) * triangle_duration +					     triangle_width + 0.5))) {	  if (((shift_samples + i) >= (long)((k - 1)* triangle_duration + 0.5))	      && ((shift_samples + i) < (long)((k - 1) * triangle_duration + 1					       + ((float)triangle_width / 2.0)					       + 0.5))) {	    triangle_wave_a(i) = 	      ((shift_samples + i) - (k - 1) * triangle_duration) * slope +	      bias_d;	  }	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					     1 + ((float)triangle_width / 2.0)					     + 0.5)) &&	      ((shift_samples + i) <= (long)((k - 1) * triangle_duration +					     triangle_width + 0.5))) {	    triangle_wave_a(i) = (float)amplitude_d -	      ((shift_samples + i) - (k - 1) * triangle_duration -	       ((float)triangle_width / 2.0)) * slope + bias_d;	  }	}	// compute samples of the negative slope	//	else {	  	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					     + triangle_width + 0.5)) &&	      ((shift_samples + i) < (long)((k - 1) * triangle_duration + 1 +					    ((float)triangle_width) +					    (triangle_duration -					     triangle_width) / 2.0 + 0.5))) {	    triangle_wave_a(i) =	      -((shift_samples + i) - ((float)triangle_width)		- (k - 1) * triangle_duration) * slope + bias_d;	  }	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					     1 + ((float)triangle_width) +					     (triangle_duration -					      triangle_width) / 2.0 + 0.5)) &&	      ((shift_samples + i) <= (long)((k - 1) * triangle_duration +					     triangle_duration + 0.5))) {	    triangle_wave_a(i) = -((float)amplitude_d -				   ((shift_samples + i) - (k - 1) *				    triangle_duration -				    ((float)triangle_width) -				    (float)(triangle_duration -					    triangle_width) / 2.0) * slope)	      + bias_d;	  }		}	// increment the counter	//	if ((k * triangle_duration) == (shift_samples + i)) {	  k = k + 1;	}      }    }        // case when shift is less than zero    //    if (shift_samples < 0) {      for (long i = 0; i < last_frame_length; i++) {		// set triangle wave signal point to zero when the x coordinate of the	// point < 0	//	if ((shift_samples + i - 1) < 0) {	  triangle_wave_a(i) = 0.0 + bias_d;	  k = 0;	}	else {	  // compute samples of the positive slope	  //	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					     + 0.5)) &&	      ((shift_samples + i) <= (long)((k - 1) * triangle_duration					     + triangle_width + 0.5))) {	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					       + 0.5)) &&		((shift_samples + i) < (long)((k - 1) * triangle_duration + 1 +					      ((float)triangle_width / 2.0)					      + 0.5))) {	      triangle_wave_a(i) =		((shift_samples + i) - (k - 1) * triangle_duration) * slope		+ bias_d;	    }	  	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					       1 + ((float)triangle_width						    / 2.0) + 0.5)) &&		((shift_samples + i) <= (long)((k - 1) * triangle_duration +					       triangle_width + 0.5))) {	      triangle_wave_a(i) = (float)amplitude_d -		((shift_samples + i) - (k - 1) * triangle_duration		 - ((float)triangle_width / 2.0)) * slope + bias_d;	    	    }	  }	  // compute samples of the negative slope	  //	  else {	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					       + triangle_width + 0.5)) &&		((shift_samples + i) < (long)((k - 1) * triangle_duration + 1 +					      ((float)triangle_width					       * 3.0 / 2.0) + 0.5))) {	      triangle_wave_a(i) =		-((shift_samples + i)-((float)triangle_width) - (k - 1)		  * triangle_duration) * slope + bias_d;	    }	  	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					       1 + ((float)triangle_width * 3.0						    / 2.0) + 0.5)) &&		((shift_samples + i) <= (long)((k - 1) * triangle_duration +					       triangle_duration + 0.5))) {	      triangle_wave_a(i) = -((float)amplitude_d -				     ((shift_samples + i) - (k - 1) *				      triangle_duration -				      ((float)triangle_width * 3.0 / 2.0))				     * slope) + bias_d;	    }	  	  }	}	// increment the counter	//	if ((k*triangle_duration) == (shift_samples + i)) {	  k = k + 1;	}      }    }        for (long i = last_frame_length; i < length; i++) {            // set triangle wave signal point to zero for the unspecified points of      // last frame      //      triangle_wave_a(i) = 0.0;    }            }    // dealing with computing other frames  //  else {    // case when shift is greater than or equal to zero    //    if (shift_samples >= 0) {      for (long i = 0; i < length; i++) {		if (((shift_samples + i) >= (long)((k - 1) * triangle_duration + 0.5))	    && ((shift_samples + i) < (long)((k - 1) * triangle_duration +					     triangle_width + 0.5))) {	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					     + 0.5))	      && ((shift_samples + i) < (long)((k - 1) * triangle_duration					       + 1 + ((float)triangle_width						      / 2.0) + 0.5))) {	    triangle_wave_a(i) = 	      ((shift_samples + i) - (k - 1) * triangle_duration) * slope +	      bias_d;	  }	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					     1 + ((float)triangle_width / 2.0)					     + 0.5)) &&	      ((shift_samples + i) <= (long)((k - 1) * triangle_duration +					     triangle_width + 0.5))) {	    triangle_wave_a(i) = (float)amplitude_d -	      ((shift_samples + i) - (k - 1) * triangle_duration -	       ((float)triangle_width / 2.0)) * slope + bias_d;	  }	}	else {	  	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					     + triangle_width + 0.5)) &&	      ((shift_samples + i) < (long)((k - 1) * triangle_duration + 1 +					    ((float)triangle_width) +					    (triangle_duration -					     triangle_width) / 2.0 + 0.5))) {	    triangle_wave_a(i) =	      -((shift_samples + i) - ((float)triangle_width)		- (k - 1) * triangle_duration) * slope + bias_d;	  }	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					     1 + ((float)triangle_width) +					     (triangle_duration -					      triangle_width) / 2.0 + 0.5)) &&	      ((shift_samples + i) <= (long)((k - 1) * triangle_duration +					     triangle_duration + 0.5))) {	    triangle_wave_a(i) = -((float)amplitude_d -				   ((shift_samples + i) - (k - 1)				    * triangle_duration -				    ((float)triangle_width) -				    (float)(triangle_duration -					    triangle_width) / 2.0)				   * slope) + bias_d;	  }		}	if ((k * triangle_duration) == (shift_samples + i)) {	  k = k + 1;	}      }    }      // case when shift is less than zero    //    if (shift_samples < 0) {      for (long i = 0; i < length; i++) {	if ((shift_samples + i - 1) < 0) {	  // set triangle wave signal point to zero when the x	  // coordinate of the point < 0	  //	  triangle_wave_a(i) = 0.0 + bias_d;	  k = 0;	}	else {	  if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					     + 0.5)) &&	      ((shift_samples + i) <= (long)((k - 1) * triangle_duration					     + triangle_width + 0.5))) {	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					       + 0.5)) &&		((shift_samples + i) < (long)((k - 1) * triangle_duration + 1 +					      ((float)triangle_width / 2.0)					      + 0.5))) {	      triangle_wave_a(i) =		((shift_samples + i) - (k - 1) * triangle_duration) * slope		+ bias_d;	    }	  	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					       1 + ((float)triangle_width						    / 2.0) + 0.5)) &&		((shift_samples + i) <= (long)((k - 1) * triangle_duration +					       triangle_width + 0.5))) {	      triangle_wave_a(i) = (float)amplitude_d -		((shift_samples + i) - (k - 1) * triangle_duration		 - ((float)triangle_width / 2.0)) * slope + bias_d;	      	    }	  }	  else {	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration					       + triangle_width + 0.5)) &&		((shift_samples + i) < (long)((k - 1) * triangle_duration + 1 +					      ((float)triangle_width					       * 3.0 / 2.0) + 0.5))) {	      triangle_wave_a(i) =		-((shift_samples + i)-((float)triangle_width) - (k - 1)		  * triangle_duration) * slope + bias_d;	    }	  	    if (((shift_samples + i) >= (long)((k - 1) * triangle_duration +					       1 + ((float)triangle_width * 3.0						    / 2.0) + 0.5)) &&		((shift_samples + i) <= (long)((k - 1) * triangle_duration +					       triangle_duration + 0.5))) {	      triangle_wave_a(i) = -((float)amplitude_d -				     ((shift_samples + i) - (k - 1) *				      triangle_duration -				      ((float)triangle_width * 3.0 / 2.0))				     * slope) + bias_d;	    }	  	  }	}	if ((k*triangle_duration) == (shift_samples + i)) {	  k = k + 1;	}      }    }  }    // exit gracefully  //  return true;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -