void setTickSample (void const* audioData, int dataBytes) { ScopedPointer <MemoryInputStream> mis (new MemoryInputStream (audioData, dataBytes, false)); m_synth.clearVoices (); m_synth.clearSounds (); AudioFormatManager afm; afm.registerBasicFormats (); { ScopedPointer <AudioFormatReader> afr (afm.createReaderFor (mis)); if (afr != nullptr) { mis.release (); BigInteger midiNotes; midiNotes.setRange (0, 127, true); SynthesiserSound::Ptr sound = new SamplerSound ( "Tick", *afr, midiNotes, 60, 0, 0, 60./40.); m_synth.addSound (sound); m_synth.addVoice (new SamplerVoice); } } }
BigInteger BigInteger::modExp(const BigInteger &power, const BigInteger &modulo, const BigInteger &recip, short nb) const { BigInteger r; BigNum::modExp(r, *this, power, modulo,recip,nb); r.debugInitStr(); return r; }
BigInteger BigInteger::modExp(const BigInteger &power, const BigInteger &modulo) const { BigInteger r; BigNum::modExp(r, *this, power, modulo); r.debugInitStr(); return r; }
BigInteger BigInteger::sub(const BigInteger &b) const { BigInteger r; BigNum::sub(r, *this, b); r.debugInitStr(); return r; }
BigInteger operator - (BigInteger &in){ if(sign() != in.sign()) return add(*this, in, sign()); else if(compare(in, true) == LESS) return sub(in, *this, in.sign()); else return sub(*this, in, sign()); }
BigInteger *Pow(unsigned int x, unsigned int y){ BigInteger *output = new BigInteger(n_digits,x); for(unsigned int i=2; i<=y; i++) output->Multiply(x); return output; }
void OptionsDialog::updateOutputChannelComboBox() { m_ui->comboBox_OutputChannels->clear(); if ( isJackAudioEnabled() ) { m_ui->comboBox_OutputChannels->setVisible( false ); m_ui->label_OutputChannels->setVisible( false ); } else { m_ui->comboBox_OutputChannels->setVisible( true ); m_ui->label_OutputChannels->setVisible( true ); AudioIODevice* const currentAudioDevice = m_deviceManager.getCurrentAudioDevice(); if ( currentAudioDevice != NULL ) { m_ui->comboBox_OutputChannels->setEnabled( true ); StringArray channelNames; channelNames = currentAudioDevice->getOutputChannelNames(); StringArray channelPairNames; for ( int i = 0; i < channelNames.size(); i += 2 ) { const String& name = channelNames[i]; if ( i + 1 >= channelNames.size() ) channelPairNames.add( name.trim() ); else channelPairNames.add( getNameForChannelPair( name, channelNames[i + 1] ) ); } channelNames = channelPairNames; int startBit; const int numBits = 2; const bool shouldBeSet = true; for ( int i = 0; i < channelNames.size(); ++i ) { // Each set bit represents an audio channel startBit = i * 2; BigInteger channels; channels.setRange( startBit, numBits, shouldBeSet ); m_ui->comboBox_OutputChannels->addItem( channelNames[i].toRawUTF8(), channels.toInt64() ); } } else { m_ui->comboBox_OutputChannels->addItem( getNoDeviceString() ); m_ui->comboBox_OutputChannels->setEnabled( false ); } } }
BigInteger BigInteger::inverseModN(const BigInteger &n) const { BigInteger r; BigNum::inverseModN(r,*this, n); r.debugInitStr(); return r; }
BigInteger getActiveOutputChannels() const { BigInteger outputBits; for (int i = 0; i < outputPorts.size(); i++) if (juce::jack_port_connected ((jack_port_t*) outputPorts [i])) outputBits.setBit (i); return outputBits; }
// q = this->divBy(divisor) is equilvalent to: q = this->quickDivMod(divisor,remainderResult); this = remainderResult; BigInteger* BigInteger::divBy(const BigInteger* divisor, BigInteger* divResult) { BigInteger tempInt; tempInt.setFromInteger(0); quickDivMod(divisor, &tempInt, divResult); // this has been hard to get right. If bugs do show up, //divResult = divideByReciprocalMethod(divisor,tempInt,divResult); // try this version instead Its slower, but less likely to be buggy this->copyFrom(&tempInt); return divResult; }
const BigInteger getActiveInputChannels() const { BigInteger inputBits; for (int i = 0; i < inputPorts.size(); i++) if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i])) inputBits.setBit (i); return inputBits; }
void BigInteger::subtract(const BigInteger &a, const BigInteger &b) { ALIASED(this == &a || this == &b, add(a, b)); if (a.sign() == Zero) { _mag = b._mag; _sign = (b.sign() == Pos) ? Neg : (b.sign() == Zero) ? Zero : Pos; } else if (b.sign() == Zero) { *this = a; } else if (a.sign() != b.sign()) { _sign = a.sign(); _mag.add(a._mag, b._mag); } else { switch (a._mag.compareTo(b._mag)) { case equal: _mag = 0; _sign = Zero; break; case greater: _sign = a.sign(); _mag.subtract(a._mag, b._mag); break; case less: _sign = (b.sign() == Pos) ? Neg : (b.sign() == Zero) ? Zero : Pos; _mag.subtract(b._mag, a._mag); break; } } }// subtract
void Test_BigMersennePrime() { BigInteger mersenne (1); BigInteger two (2); for (int i = 0; i < 11213; i ++) mersenne = mersenne * two; mersenne = mersenne - 1; cout << "Mersenne: " << endl << mersenne << endl; cout << "Number of Digits: " << mersenne.Cardinality() << endl; }
int compare(BigInteger &in, bool abs) { if(sign() != in.sign() && !abs) return (sign())? GREATER : LESS; if(size() != in.size()) return (size() > in.size())? GREATER : LESS; for(int i=in.size()-1; i>=0; i--) { if(value[i] == in.value[i])continue; return (value[i] > in.value[i])? GREATER : LESS; } return EQUAL; }
BigInteger operator-(BigInteger& x) { BigInteger res; res.size = max(size,x.size) + 1; for(int i = 0; i < res.size; i++) res.M[i] = M[i] - x.M[i]; res.Normalize(); return res; }
BigInteger operator / (const BigInteger& b) const { assert(b > 0); // 除数必须大于0 BigInteger c = *this; // 商:主要是让c.s和(*this).s的vector一样大 BigInteger m; // 余数:初始化为0 for (int i = s.size()-1; i >= 0; i--) { m = m*BASE + s[i]; c.s[i] = bsearch(b, m); m -= b*c.s[i]; } return c.clean(); }
void YSE::SYNTH::implementationObject::addVoices(const YSE::SYNTH::samplerConfig & voice, int numVoices) { for (int i = 0; i < numVoices; i++) { synthesizer.addVoice(new SamplerVoice()); } File ioFile; ioFile = File::getCurrentWorkingDirectory().getChildFile(juce::String(voice.file())); ScopedPointer<AudioFormatReader> audioreader(SOUND::Manager().getReader(ioFile)); BigInteger allNotes; allNotes.setRange(voice.lowestNote(), voice.highestNote(), true); synthesizer.addSound(new samplerSoundWithChannel(voice.name(), *audioreader, voice.channel(), allNotes, voice.root(), voice.attackTime(), voice.releaseTime(), voice.maxLength())); }
BigInteger operator*(BigInteger& x) { BigInteger res; res.size = size + x.size + 2; for(int i = 0; i < size; i++) for(int j = 0; j < x.size; j++) res.M[i+j] += M[i]*x.M[j]; res.Normalize(); return res; }
int compare(BigInteger &in, bool abs){ if(sign() != in.sign() && !abs) return (sign())? LESS : GREATER; if(size() != in.size()) return (size() < in.size())? LESS : GREATER; for(int i=in.size()-1; i>=0; i--){ if(in[i] == value[i]) continue; return (value[i] < value[i])? LESS : GREATER; } return EQUAL; }
BigInteger operator - (BigInteger &in){ if(sign() != in.sign()) return add(*this, in, sign()); else if(compare(in, true) == LESS){ // cout << toString() << " > " << in.toString() << endl; return sub(*this, in, sign()); } else{ //cout << toString() << " < " << in.toString() << endl; return sub(in, *this, !in.sign()); } }
BigInteger operator - (const BigInteger& b) const { assert(b <= *this); // 减数不能大于被减数 BigInteger c; c.s.clear(); for (int i = 0, g = 0; ; i++) { if (g == 0 && i >= s.size() && i >= b.s.size()) break; int x = s[i] + g; if (i < b.s.size()) x -= b.s[i]; if (x < 0) {g = -1; x += BASE;} else g = 0; c.s.push_back(x); } return c.clean(); }
//============================================================================== static String encryptXML (const XmlElement& xml, RSAKey privateKey) { MemoryOutputStream text; text << xml.createDocument (StringRef(), true); BigInteger val; val.loadFromMemoryBlock (text.getMemoryBlock()); privateKey.applyToValue (val); return val.toString (16); }
BigInteger operator * (const BigInteger& b) const { BigInteger c; c.s.resize(s.size() + b.s.size() + 1); fill(c.s.begin(), c.s.end(), 0); for(int i = 0; i < s.size(); i++) for(int j = 0; j < b.s.size(); j++) { long long sum = (long long)s[i] * b.s[j] + c.s[i+j]; c.s[i+j+1] += sum / BASE; c.s[i+j] = sum % BASE; } c.adjust(); return c; }
BigInteger operator - (const BigInteger& b) const { BigInteger c; c.s.resize(s.size()); for(int i = 0, g = 0; i < s.size(); i++) { c.s[i] = s[i] - g; g = 0; int sub = (i < b.s.size() ? b.s[i] : 0); if(c.s[i] < sub) { g = 1; c.s[i] += BASE; } c.s[i] -= sub; } c.adjust(); return c; }
BigInteger divmod (int b, int& d) const { BigInteger c; c.s.clear(); d = 0; for(int i = s.size()-1; i >= 0; i--) { long long v = (long long)d * BASE + s[i]; c.s.push_back(v / b); d = v % b; } reverse(c.s.begin(), c.s.end()); c.adjust(); return c; }
BigInteger operator * (const BigInteger& b) const { int i, j; LL g; vector<LL> v(s.size()+b.s.size(), 0); BigInteger c; c.s.clear(); for(i=0;i<s.size();i++) for(j=0;j<b.s.size();j++) v[i+j]+=LL(s[i])*b.s[j]; for (i = 0, g = 0; ; i++) { if (g ==0 && i >= v.size()) break; LL x = v[i] + g; c.s.push_back(x % BASE); g = x / BASE; } return c.clean(); }
ECPoint ECCurve::toAffine(ECPointJacobian &p) { BigInteger z = p.getZ(); BigInteger zInv = z.invm(_p); BigInteger z2Inv = (zInv * zInv) % _p; BigInteger z3Inv = (z2Inv * zInv) % _p; BigInteger x = p.getX(); BigInteger y = p.getY(); return ECPoint((x * z2Inv) % _p, (y * z3Inv) % _p); }
BigInteger operator * (const BigInteger &multiplier) const { BigInteger res; res.data.assign(data.size() + multiplier.data.size(), 0); res.sign = sign * multiplier.sign; for (size_t i = 0; i < data.size(); ++i) for (size_t j = 0, carry = 0; j < multiplier.data.size() || carry; ++j) { long long cur = res.data[i + j] + data[i] * 1LL * (j < multiplier.data.size() ? multiplier.data[j] : 0) + carry; res.data[i + j] = (int) (cur % base); carry = (size_t) (cur / base); } res.removeLeadingZeros(); return res; }
bool ElGamal::decrypt(const BigInteger &a, const BigInteger &b, BigInteger &out) const { try { out = b.modMulRecip(a.modExp(x, p, recip, nb).inverseModN(p), p, recip, nb); return true; } catch (ArithmeticException &) { } return false; }
// 高精度整数减法。 BigInteger operator-(const BigInteger& x, const BigInteger& y) { BigInteger z; // 当 x 和 y 至少有一个是负数,转换为加法运算。 if (x.sign == NEGATIVE || y.sign == NEGATIVE) { z = y; z.sign = -y.sign; return x + z; } // 都为正数,确保 x 大于 y,便于计算。 if (x < y) { z = y - x; z.sign = NEGATIVE; return z; } // 设置符号位并预先分配存储空间。 z.sign = POSITIVE; z.digits.resize(max(x.digits.size(), y.digits.size())); fill(z.digits.begin(), z.digits.end(), 0); // 逐位相减,考虑借位。 int index = 0, borrow = 0; for (; index < x.digits.size(); index++) { // 获取对应位的差。 int difference = x.digits[index] - borrow; difference -= index < y.digits.size() ? y.digits[index] : 0; // 确定是否有借位。 borrow = 0; if (difference < 0) { difference += z.base; borrow = 1; } // 保存相应位差的结果。 z.digits[index] = difference % z.base; } // 移除前导零。 z.zeroJustify(); return z; }