本文整理汇总了C++中NUMdefined函数的典型用法代码示例。如果您正苦于以下问题:C++ NUMdefined函数的具体用法?C++ NUMdefined怎么用?C++ NUMdefined使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NUMdefined函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: menu_cb_addPointAtCursor
static void menu_cb_addPointAtCursor (RealTierEditor me, EDITOR_ARGS_DIRECT) {
if (NUMdefined (my v_minimumLegalValue ()) && my ycursor < my v_minimumLegalValue ())
Melder_throw (U"Cannot add a point below ", my v_minimumLegalValue (), my v_rightTickUnits (), U".");
if (NUMdefined (my v_maximumLegalValue ()) && my ycursor > my v_maximumLegalValue ())
Melder_throw (U"Cannot add a point above ", my v_maximumLegalValue (), my v_rightTickUnits (), U".");
Editor_save (me, U"Add point");
RealTier_addPoint ((RealTier) my data, 0.5 * (my d_startSelection + my d_endSelection), my ycursor);
RealTierEditor_updateScaling (me);
FunctionEditor_redraw (me);
Editor_broadcastDataChanged (me);
}
示例2: Sound_findExtremum
static double Sound_findExtremum (Sound me, double tmin, double tmax, int includeMaxima, int includeMinima) {
long imin = Sampled_xToLowIndex (me, tmin), imax = Sampled_xToHighIndex (me, tmax);
double iextremum;
Melder_assert (NUMdefined (tmin));
Melder_assert (NUMdefined (tmax));
if (imin < 1) imin = 1;
if (imax > my nx) imax = my nx;
iextremum = findExtremum_3 (my z [1], my ny > 1 ? my z [2] : NULL, imin - 1, imax - imin + 1, includeMaxima, includeMinima);
if (iextremum)
return my x1 + (imin - 1 + iextremum - 1) * my dx;
else
return (tmin + tmax) / 2;
}
示例3: menu_cb_MoveCursorToZero
static void menu_cb_MoveCursorToZero (SoundEditor me, EDITOR_ARGS_DIRECT) {
double zero = Sound_getNearestZeroCrossing ((Sound) my data, 0.5 * (my d_startSelection + my d_endSelection), 1); // STEREO BUG
if (NUMdefined (zero)) {
my d_startSelection = my d_endSelection = zero;
FunctionEditor_marksChanged (me, true);
}
}
示例4: Sound_getNearestZeroCrossing
int SoundEditor::menu_cb_MoveCursorToZero (EDITOR_ARGS) {
SoundEditor *editor = (SoundEditor *)editor_me;
double zero = Sound_getNearestZeroCrossing ((Sound) editor->_data, 0.5 * (editor->_startSelection + editor->_endSelection), 1); // STEREO BUG
if (NUMdefined (zero)) {
editor->_startSelection = editor->_endSelection = zero;
editor->marksChanged ();
}
return 1;
}
示例5: PointProcess_isPeriod
static bool PointProcess_isPeriod (PointProcess me, long ileft, double minimumPeriod, double maximumPeriod, double maximumPeriodFactor) {
/*
* This function answers the question: is the interval from point 'ileft' to point 'ileft+1' a period?
*/
long iright = ileft + 1;
/*
* Period condition 1: both 'ileft' and 'iright' have to be within the point process.
*/
if (ileft < 1 || iright > my nt) {
return false;
} else {
/*
* Period condition 2: the interval has to be within the boundaries, if specified.
*/
if (minimumPeriod == maximumPeriod) {
return true; // all intervals count as periods, irrespective of absolute size and relative size
} else {
double interval = my t [iright] - my t [ileft];
if (interval <= 0.0 || interval < minimumPeriod || interval > maximumPeriod) {
return false;
} else if (! NUMdefined (maximumPeriodFactor) || maximumPeriodFactor < 1.0) {
return true;
} else {
/*
* Period condition 3: the interval cannot be too different from both of its neigbours, if any.
*/
double previousInterval = ileft <= 1 ? NUMundefined : my t [ileft] - my t [ileft - 1];
double nextInterval = iright >= my nt ? NUMundefined : my t [iright + 1] - my t [iright];
double previousIntervalFactor = NUMdefined (previousInterval) && previousInterval > 0.0 ? interval / previousInterval : NUMundefined;
double nextIntervalFactor = NUMdefined (nextInterval) && nextInterval > 0.0 ? interval / nextInterval : NUMundefined;
if (! NUMdefined (previousIntervalFactor) && ! NUMdefined (nextIntervalFactor)) {
return true; // no neighbours: this is a period
}
if (NUMdefined (previousIntervalFactor) && previousIntervalFactor > 0.0 && previousIntervalFactor < 1.0) {
previousIntervalFactor = 1.0 / previousIntervalFactor;
}
if (NUMdefined (nextIntervalFactor) && nextIntervalFactor > 0.0 && nextIntervalFactor < 1.0) {
nextIntervalFactor = 1.0 / nextIntervalFactor;
}
if (NUMdefined (previousIntervalFactor) && previousIntervalFactor > maximumPeriodFactor &&
NUMdefined (nextIntervalFactor) && nextIntervalFactor > maximumPeriodFactor)
{
return false;
}
}
}
}
return true;
}
示例6: BandFilterSpectrogram_drawFrequencyScale
// xmin, xmax in hz versus bark/mel or lin
void BandFilterSpectrogram_drawFrequencyScale (BandFilterSpectrogram me, Graphics g, double xmin, double xmax, double ymin, double ymax, int garnish) {
if (xmin < 0 || xmax < 0 || ymin < 0 || ymax < 0) {
Melder_warning (U"Frequencies must be >= 0.");
return;
}
// scale is in hertz
if (xmin >= xmax) { // autoscaling
xmin = 0;
xmax = my v_frequencyToHertz (my ymax);
}
if (ymin >= ymax) { // autoscaling
ymin = my ymin;
ymax = my ymax;
}
long n = 2000;
Graphics_setInner (g);
Graphics_setWindow (g, xmin, xmax, ymin, ymax);
double dx = (xmax - xmin) / (n - 1);
double x1 = xmin, y1 = my v_hertzToFrequency (x1);
for (long i = 2; i <= n; i++) {
double x2 = x1 + dx, y2 = my v_hertzToFrequency (x2);
if (NUMdefined (y1) && NUMdefined (y2)) {
double xo1, yo1, xo2, yo2;
if (NUMclipLineWithinRectangle (x1, y1, x2, y2, xmin, ymin, xmax, ymax, &xo1, &yo1, &xo2, &yo2)) {
Graphics_line (g, xo1, yo1, xo2, yo2);
}
}
x1 = x2; y1 = y2;
}
Graphics_unsetInner (g);
if (garnish) {
Graphics_drawInnerBox (g);
Graphics_marksLeft (g, 2, 1, 1, 0);
Graphics_textLeft (g, 1, Melder_cat (U"Frequency (", my v_getFrequencyUnit (), U")"));
Graphics_marksBottom (g, 2, 1, 1, 0);
Graphics_textBottom (g, 1, U"Frequency (Hz)");
}
}
示例7: menu_cb_MoveEtoZero
static void menu_cb_MoveEtoZero (SoundEditor me, EDITOR_ARGS_DIRECT) {
double zero = Sound_getNearestZeroCrossing ((Sound) my data, my d_endSelection, 1); // STEREO BUG
if (NUMdefined (zero)) {
my d_endSelection = zero;
if (my d_startSelection > my d_endSelection) {
double dummy = my d_startSelection;
my d_startSelection = my d_endSelection;
my d_endSelection = dummy;
}
FunctionEditor_marksChanged (me, true);
}
}
示例8: PointProcess_Sound_to_AmplitudeTier_point
autoAmplitudeTier PointProcess_Sound_to_AmplitudeTier_point (PointProcess me, Sound thee) {
try {
long imin, imax, numberOfPeaks = PointProcess_getWindowPoints (me, my xmin, my xmax, & imin, & imax);
if (numberOfPeaks < 3) return nullptr;
autoAmplitudeTier him = AmplitudeTier_create (my xmin, my xmax);
for (long i = imin; i <= imax; i ++) {
double value = Vector_getValueAtX (thee, my t [i], Vector_CHANNEL_AVERAGE, Vector_VALUE_INTERPOLATION_SINC700);
if (NUMdefined (value)) RealTier_addPoint (him.peek(), my t [i], value);
}
return him;
} catch (MelderError) {
Melder_throw (me, U" & ", thee, U": not converted to AmplitudeTier.");
}
}
示例9: Sound_FormantGrid_filter_inline
void Sound_FormantGrid_filter_inline (Sound me, FormantGrid formantGrid) {
double dt = my dx;
if (formantGrid -> formants -> size && formantGrid -> bandwidths -> size)
for (long iformant = 1; iformant <= formantGrid -> formants -> size; iformant ++) {
RealTier formantTier = (RealTier) formantGrid -> formants -> item [iformant];
RealTier bandwidthTier = (RealTier) formantGrid -> bandwidths -> item [iformant];
for (long isamp = 1; isamp <= my nx; isamp ++) {
double t = my x1 + (isamp - 1) * my dx;
/*
* Compute LP coefficients.
*/
double formant, bandwidth;
formant = RealTier_getValueAtTime (formantTier, t);
bandwidth = RealTier_getValueAtTime (bandwidthTier, t);
if (NUMdefined (formant) && NUMdefined (bandwidth)) {
double cosomdt = cos (2 * NUMpi * formant * dt);
double r = exp (- NUMpi * bandwidth * dt);
/* Formants at 0 Hz or the Nyquist are single poles, others are double poles. */
if (fabs (cosomdt) > 0.999999) { /* Allow for round-off errors. */
/* single pole: D(z) = 1 - r z^-1 */
for (long channel = 1; channel <= my ny; channel ++) {
if (isamp > 1) my z [channel] [isamp] += r * my z [channel] [isamp - 1];
}
} else {
/* double pole: D(z) = 1 + p z^-1 + q z^-2 */
double p = - 2 * r * cosomdt;
double q = r * r;
for (long channel = 1; channel <= my ny; channel ++) {
if (isamp > 1) my z [channel] [isamp] -= p * my z [channel] [isamp - 1];
if (isamp > 2) my z [channel] [isamp] -= q * my z [channel] [isamp - 2];
}
}
}
}
}
}
示例10: v_getValueAtSample
double structVector :: v_getValueAtSample (long isamp, long ilevel, int unit) {
// Preconditions:
// 1 <= isamp <= my nx
// 0 <= ilevel <= my ny
double value;
if (ilevel > Vector_CHANNEL_AVERAGE) {
value = z [ilevel] [isamp];
} else if (ny == 1) {
value = z [1] [isamp]; // optimization
} else if (ny == 2) {
value = 0.5 * (z [1] [isamp] + z [2] [isamp]); // optimization
} else {
double sum = 0.0;
for (long channel = 1; channel <= ny; channel ++) {
sum += z [channel] [isamp];
}
value = sum / ny;
}
return NUMdefined (value) ? v_convertStandardToSpecialUnit (value, ilevel, unit) : NUMundefined;
}
示例11: Sampled_getQuantile
double Sampled_getQuantile (I, double xmin, double xmax, double quantile, long ilevel, int unit) {
iam (Sampled);
long i, imin, imax, numberOfDefinedSamples = 0;
double *values = NUMdvector (1, my nx), result = NUMundefined;
iferror return NUMundefined;
Function_unidirectionalAutowindow (me, & xmin, & xmax);
if (! Function_intersectRangeWithDomain (me, & xmin, & xmax)) return NUMundefined;
Sampled_getWindowSamples (me, xmin, xmax, & imin, & imax);
for (i = imin; i <= imax; i ++) {
double value = our getValueAtSample (me, i, ilevel, unit);
if (NUMdefined (value)) {
values [++ numberOfDefinedSamples] = value;
}
}
if (numberOfDefinedSamples >= 1) {
NUMsort_d (numberOfDefinedSamples, values);
result = NUMquantile (numberOfDefinedSamples, values, quantile);
}
NUMdvector_free (values, 1);
return result;
}
示例12: Pitch_Intensity_draw
void Pitch_Intensity_draw (Pitch pitch, Intensity intensity, Graphics g,
double f1, double f2, double s1, double s2, int garnish, int connect)
{
if (f2 <= f1) Pitch_getExtrema (pitch, & f1, & f2);
if (f1 == 0.0) return; /* All voiceless. */
if (f1 == f2) { f1 -= 1.0; f2 += 1.0; }
if (s2 <= s1) Matrix_getWindowExtrema (intensity, 0, 0, 1, 1, & s1, & s2);
if (s1 == s2) { s1 -= 1.0; s2 += 1.0; }
Graphics_setWindow (g, f1, f2, s1, s2);
Graphics_setInner (g);
long previousI = 0;
double previousX = NUMundefined, previousY = NUMundefined;
for (long i = 1; i <= pitch -> nx; i ++) {
double t = Sampled_indexToX (pitch, i);
double x = pitch -> frame [i]. candidate [1]. frequency;
double y = Sampled_getValueAtX (intensity, t, Pitch_LEVEL_FREQUENCY, kPitch_unit_HERTZ, TRUE);
if (x == 0) {
continue; /* Voiceless. */
}
if (connect & 1) Graphics_speckle (g, x, y);
if ((connect & 2) && NUMdefined (previousX)) {
if (previousI >= 1 && previousI < i - 1) {
Graphics_setLineType (g, Graphics_DOTTED);
}
Graphics_line (g, previousX, previousY, x, y);
Graphics_setLineType (g, Graphics_DRAWN);
}
previousX = x;
previousY = y;
previousI = i;
}
Graphics_unsetInner (g);
if (garnish) {
Graphics_drawInnerBox (g);
Graphics_textBottom (g, 1, L"Fundamental frequency (Hz)");
Graphics_marksBottom (g, 2, 1, 1, 0);
Graphics_textLeft (g, 1, L"Intensity (dB)");
Graphics_marksLeft (g, 2, 1, 1, 0);
}
}
示例13: Sampled_speckleInside
static void Sampled_speckleInside (Sampled me, Graphics g, double xmin, double xmax, double ymin, double ymax,
double speckle_mm, long ilevel, int unit)
{
Function_unidirectionalAutowindow (me, & xmin, & xmax);
long ixmin, ixmax;
Sampled_getWindowSamples (me, xmin, xmax, & ixmin, & ixmax);
if (Function_isUnitLogarithmic (me, ilevel, unit)) {
ymin = Function_convertStandardToSpecialUnit (me, ymin, ilevel, unit);
ymax = Function_convertStandardToSpecialUnit (me, ymax, ilevel, unit);
}
if (ymax <= ymin) return;
Graphics_setWindow (g, xmin, xmax, ymin, ymax);
for (long ix = ixmin; ix <= ixmax; ix ++) {
double value = Sampled_getValueAtSample (me, ix, ilevel, unit);
if (NUMdefined (value)) {
double x = Sampled_indexToX (me, ix);
if (value >= ymin && value <= ymax) {
Graphics_fillCircle_mm (g, x, value, speckle_mm);
}
}
}
}
示例14: Sampled_getQuantile
double Sampled_getQuantile (Sampled me, double xmin, double xmax, double quantile, long ilevel, int unit) {
try {
autoNUMvector <double> values (1, my nx);
Function_unidirectionalAutowindow (me, & xmin, & xmax);
if (! Function_intersectRangeWithDomain (me, & xmin, & xmax)) return NUMundefined;
long imin, imax, numberOfDefinedSamples = 0;
Sampled_getWindowSamples (me, xmin, xmax, & imin, & imax);
for (long i = imin; i <= imax; i ++) {
double value = my v_getValueAtSample (i, ilevel, unit);
if (NUMdefined (value)) {
values [++ numberOfDefinedSamples] = value;
}
}
double result = NUMundefined;
if (numberOfDefinedSamples >= 1) {
NUMsort_d (numberOfDefinedSamples, values.peek());
result = NUMquantile (numberOfDefinedSamples, values.peek(), quantile);
}
return result;
} catch (MelderError) {
Melder_throw (me, ": quantile not computed.");
}
}
示例15: PointProcess_Sound_to_AmplitudeTier_period
autoAmplitudeTier PointProcess_Sound_to_AmplitudeTier_period (PointProcess me, Sound thee, double tmin, double tmax,
double pmin, double pmax, double maximumPeriodFactor)
{
try {
if (tmax <= tmin) tmin = my xmin, tmax = my xmax;
long imin, imax;
long numberOfPeaks = PointProcess_getWindowPoints (me, tmin, tmax, & imin, & imax);
if (numberOfPeaks < 3) Melder_throw (U"Too few pulses between ", tmin, U" and ", tmax, U" seconds.");
autoAmplitudeTier him = AmplitudeTier_create (tmin, tmax);
for (long i = imin + 1; i < imax; i ++) {
double p1 = my t [i] - my t [i - 1], p2 = my t [i + 1] - my t [i];
double intervalFactor = p1 > p2 ? p1 / p2 : p2 / p1;
if (pmin == pmax || (p1 >= pmin && p1 <= pmax && p2 >= pmin && p2 <= pmax && intervalFactor <= maximumPeriodFactor)) {
double peak = Sound_getHannWindowedRms (thee, my t [i], 0.2 * p1, 0.2 * p2);
if (NUMdefined (peak) && peak > 0.0)
RealTier_addPoint (him.peek(), my t [i], peak);
}
}
return him;
} catch (MelderError) {
Melder_throw (me, U" & ", thee, U": not converted to AmplitudeTier.");
}
}