本文整理汇总了C++中Partial类的典型用法代码示例。如果您正苦于以下问题:C++ Partial类的具体用法?C++ Partial怎么用?C++ Partial使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Partial类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generatePar
std::vector<typename Partial::SolutionT> generatePar(int depth, Partial const & part, Constraint constr)
{
using SolutionVec = std::vector<typename Partial::SolutionT>;
if (depth == 0)
{
return generate(part, constr);
}
else if (part.isFinished(constr))
{
SolutionVec result{ part.getSolution() };
return result;
}
else
{
Stream<Partial> partList = part.refine(constr);
std::vector<std::future<SolutionVec>> futResult;
forEach(std::move(partList), [&constr, &futResult, depth](Partial const & part)
{
std::future<SolutionVec> futLst =
std::async([constr, part, depth]() {
return generatePar(depth - 1, part, constr);
});
futResult.push_back(std::move(futLst));
});
std::vector<SolutionVec> all = when_all_vec(futResult);
return concatAll(all);
}
}
示例2: harmonify
// ---------------------------------------------------------------------------
// harmonify
// ---------------------------------------------------------------------------
//! Apply the reference envelope to a Partial.
//!
//! \pre The Partial p must be labeled with its harmonic number.
//
void Harmonifier::harmonify( Partial & p ) const
{
// compute absolute magnitude thresholds:
static const double FadeRangeDB = 10;
const double BeginFade = std::pow( 10., 0.05 * (_freqFixThresholdDb+FadeRangeDB) );
const double Threshold = std::pow( 10., 0.05 * _freqFixThresholdDb );
const double OneOverFadeSpan = 1. / ( BeginFade - Threshold );
double fscale = (double)p.label() / _refPartial.label();
for ( Partial::iterator it = p.begin(); it != p.end(); ++it )
{
Breakpoint & bp = it.breakpoint();
if ( bp.amplitude() < BeginFade )
{
// alpha is the harmonic frequency weighting:
// when alpha is 1, the harmonic frequency is used,
// when alpha is 0, the breakpoint frequency is
// unmodified.
double alpha =
std::min( ( BeginFade - bp.amplitude() ) * OneOverFadeSpan, 1. );
// alpha is scaled by the weigthing envelope
alpha *= _weight->valueAt( it.time() );
double fRef = _refPartial.frequencyAt( it.time() );
bp.setFrequency( ( alpha * ( fRef * fscale ) ) +
( (1 - alpha) * bp.frequency() ) );
}
}
}
示例3:
// ---------------------------------------------------------------------------
// BandwidthSetter function call operator
// ---------------------------------------------------------------------------
// Set the bandwidth of the specified Partial according to
// an envelope representing a time-varying bandwidth value.
//
void
BandwidthSetter::operator()( Partial & p ) const
{
for ( Partial::iterator pos = p.begin(); pos != p.end(); ++pos )
{
pos.breakpoint().setBandwidth( env->valueAt( pos.time() ) );
}
}
示例4: better_match
bool PartialBuilder::better_match( const Partial & part1,
const Partial & part2, const SpectralPeak & pk )
{
Assert( part1.numBreakpoints() > 0 );
Assert( part2.numBreakpoints() > 0 );
return freq_distance( part1, pk ) < freq_distance( part2, pk );
}
示例5: fixPhaseBefore
// ---------------------------------------------------------------------------
// fixPhaseBefore
//
//! Recompute phases of all Breakpoints earlier than the specified time
//! so that the synthesize phases of those earlier Breakpoints matches
//! the stored phase, and the synthesized phase at the specified
//! time matches the stored (not recomputed) phase.
//!
//! Backward phase-fixing stops if a null (zero-amplitude) Breakpoint
//! is encountered, because nulls are interpreted as phase reset points
//! in Loris. If a null is encountered, the remainder of the Partial
//! (the front part) is fixed in the forward direction, beginning at
//! the start of the Partial.
//!
//! \param p The Partial whose phases should be fixed.
//! \param t The time before which phases should be adjusted.
//
void fixPhaseBefore( Partial & p, double t )
{
if ( 1 < p.numBreakpoints() )
{
Partial::iterator pos = p.findNearest( t );
Assert( pos != p.end() );
fixPhaseBackward( p.begin(), pos );
}
}
示例6: fabs
// ---------------------------------------------------------------------------
// freq_distance
// ---------------------------------------------------------------------------
// Helper function, used in formPartials().
// Returns the (positive) frequency distance between a Breakpoint
// and the last Breakpoint in a Partial.
//
inline double
PartialBuilder::freq_distance( const Partial & partial, const SpectralPeak & pk )
{
double normBpFreq = pk.frequency() / mFreqWarping->valueAt( pk.time() );
double normPartialEndFreq =
partial.last().frequency() / mFreqWarping->valueAt( partial.endTime() );
return std::fabs( normPartialEndFreq - normBpFreq );
}
示例7: peakAmplitude
// ---------------------------------------------------------------------------
// peakAmplitude
// ---------------------------------------------------------------------------
//! Return the maximum amplitude achieved by a partial.
//!
//! \param p is the Partial to evaluate
//! \return the maximum (absolute) amplitude achieved by
//! the partial p
//
double peakAmplitude( const Partial & p )
{
double peak = 0;
for ( Partial::const_iterator it = p.begin();
it != p.end();
++it )
{
peak = std::max( peak, it->amplitude() );
}
return peak;
}
示例8: fixPhaseAfter
// ---------------------------------------------------------------------------
// fixPhaseAfter
//
//! Recompute phases of all Breakpoints later than the specified time
//! so that the synthesize phases of those later Breakpoints matches
//! the stored phase, as long as the synthesized phase at the specified
//! time matches the stored (not recomputed) phase.
//!
//! Phase fixing is only applied to non-null (nonzero-amplitude) Breakpoints,
//! because null Breakpoints are interpreted as phase reset points in
//! Loris. If a null is encountered, its phase is simply left unmodified,
//! and future phases wil be recomputed from that one.
//!
//! \param p The Partial whose phases should be fixed.
//! \param t The time after which phases should be adjusted.
//
void fixPhaseAfter( Partial & p, double t )
{
// nothing to do it there are not at least
// two Breakpoints in the Partial
if ( 1 < p.numBreakpoints() )
{
Partial::iterator pos = p.findNearest( t );
Assert( pos != p.end() );
fixPhaseForward( pos, --p.end() );
}
}
示例9: startAbort
bool Poly::startAbort() {
if (state == POLY_Inactive) {
return false;
}
for (int t = 0; t < 4; t++) {
Partial *partial = partials[t];
if (partial != NULL) {
partial->startAbort();
}
}
return true;
}
示例10: fixFrequency
// ---------------------------------------------------------------------------
// fixFrequency
//
//! Adjust frequencies of the Breakpoints in the
//! specified Partial such that the rendered Partial
//! achieves (or matches as nearly as possible, within
//! the constraint of the maximum allowable frequency
//! alteration) the analyzed phases.
//!
//! This just iterates over the Partial calling
//! matchPhaseFwd, should probably name those similarly.
//!
//! \param partial The Partial whose frequencies,
//! and possibly phases (if the frequencies
//! cannot be sufficiently altered to match
//! the phases), will be recomputed.
//! \param maxFixPct The maximum allowable frequency
//! alteration, default is 0.2%.
//
void fixFrequency( Partial & partial, double maxFixPct )
{
if ( partial.numBreakpoints() > 1 )
{
Partial::iterator next = partial.begin();
Partial::iterator prev = next++;
while ( next != partial.end() )
{
matchPhaseFwd( prev.breakpoint(), next.breakpoint(),
next.time() - prev.time(), 0.5, maxFixPct );
prev = next++;
}
}
}
示例11: startDecay
bool Poly::startDecay() {
if (state == POLY_Inactive || state == POLY_Releasing) {
return false;
}
state = POLY_Releasing;
for (int t = 0; t < 4; t++) {
Partial *partial = partials[t];
if (partial != NULL) {
partial->startDecayAll();
}
}
return true;
}
示例12: pow
// ---------------------------------------------------------------------------
// channelize (one Partial)
// ---------------------------------------------------------------------------
//! Label a Partial with the number of the frequency channel corresponding to
//! the average frequency over all the Partial's Breakpoints.
//!
//! \param partial is the Partial to label.
//
void
Channelizer::channelize( Partial & partial ) const
{
using std::pow;
// debugger << "channelizing Partial with " << partial.numBreakpoints() << " Breakpoints" << endl;
// compute an amplitude-weighted average channel
// label for each Partial:
//double ampsum = 0.;
double weightedlabel = 0.;
Partial::const_iterator bp;
for ( bp = partial.begin(); bp != partial.end(); ++bp )
{
double f = bp.breakpoint().frequency();
double t = bp.time();
double weight = 1;
if ( 0 != _ampWeighting )
{
// This used to be an amplitude-weighted avg, but for many sounds,
// particularly those for which the weighted avg would be very
// different from the simple avg, the amplitude-weighted avg
// emphasized the part of the sound in which the frequency estimates
// are least reliable (e.g. a piano tone). The unweighted
// average should give more intuitive results in most cases.
// use sinusoidal amplitude:
double a = bp.breakpoint().amplitude() * std::sqrt( 1. - bp.breakpoint().bandwidth() );
weight = pow( a, _ampWeighting );
}
weightedlabel += weight * computeFractionalChannelNumber( t, f );
}
int label = 0;
if ( 0 < partial.numBreakpoints() ) // should always be the case
{
label = (int)((weightedlabel / partial.numBreakpoints()) + 0.5);
}
Assert( label >= 0 );
// assign label, and remember it, but
// only if it is a valid (positive)
// distillation label:
partial.setLabel( label );
}
示例13: giveMeN
// ---------------------------------------------------------------------------
// channelize (one Partial)
// ---------------------------------------------------------------------------
//! Label a Partial with the number of the frequency channel corresponding to
//! the average frequency over all the Partial's Breakpoints.
//!
//! \param partial is the Partial to label.
//
void
Channelizer::channelize( Partial & partial ) const
{
debugger << "channelizing Partial with " << partial.numBreakpoints() << " Breakpoints" << endl;
// compute an amplitude-weighted average channel
// label for each Partial:
double ampsum = 0.;
double weightedlabel = 0.;
Partial::const_iterator bp;
for ( bp = partial.begin(); bp != partial.end(); ++bp )
{
// use sinusoidal amplitude:
double a = bp.breakpoint().amplitude() * std::sqrt( 1. - bp.breakpoint().bandwidth() );
// This used to be an amplitude-weighted avg, but for many sounds,
// particularly those for which the weighted avg would be very
// different from the simple avg, the amplitude-weighted avg
// emphasized the part of the sound in which the frequency estimates
// are least reliable (e.g. a piano tone). The unweighted
// average should give more intuitive results in most cases.
double f = bp.breakpoint().frequency();
double t = bp.time();
double refFreq = _refChannelFreq->valueAt( t ) / _refChannelLabel;
// weightedlabel += a * (f / refFreq);
weightedlabel += a * giveMeN( f, refFreq, _stretchFactor );
ampsum += a;
}
int label;
if ( ampsum > 0. )
// if ( 0 < partial.numBreakpoints() )
{
label = (int)((weightedlabel / ampsum) + 0.5);
}
else // this should never happen, but just in case:
{
label = 0;
}
Assert( label >= 0 );
// assign label, and remember it, but
// only if it is a valid (positive)
// distillation label:
partial.setLabel( label );
}
示例14:
Partial *PartialManager::allocPartial(int partNum) {
Partial *outPartial = NULL;
// Get the first inactive partial
for (unsigned int partialNum = 0; partialNum < synth->getPartialCount(); partialNum++) {
if (!partialTable[partialNum]->isActive()) {
outPartial = partialTable[partialNum];
break;
}
}
if (outPartial != NULL) {
outPartial->activate(partNum);
}
return outPartial;
}
示例15:
Partial *PartialManager::allocPartial(int partNum) {
Partial *outPartial = NULL;
// Get the first inactive partial
for (int partialNum = 0; partialNum < MT32EMU_MAX_PARTIALS; partialNum++) {
if (!partialTable[partialNum]->isActive()) {
outPartial = partialTable[partialNum];
break;
}
}
if (outPartial != NULL) {
outPartial->activate(partNum);
}
return outPartial;
}