void AudioEngine::mixAudio(Uint8 *pDestBuffer, int destBufferLen) { int numFrames = destBufferLen/(2*getChannels()); // 16 bit samples. if (m_AudioSources.size() == 0) { return; } if (!m_pTempBuffer || m_pTempBuffer->getNumFrames() < numFrames) { if (m_pTempBuffer) { delete[] m_pMixBuffer; } m_pTempBuffer = AudioBufferPtr(new AudioBuffer(numFrames, m_AP)); m_pMixBuffer = new float[getChannels()*numFrames]; } for (int i = 0; i < getChannels()*numFrames; ++i) { m_pMixBuffer[i]=0; } { lock_guard lock(m_Mutex); AudioSourceMap::iterator it; for (it = m_AudioSources.begin(); it != m_AudioSources.end(); it++) { m_pTempBuffer->clear(); it->second->fillAudioBuffer(m_pTempBuffer); addBuffers(m_pMixBuffer, m_pTempBuffer); } } calcVolume(m_pMixBuffer, numFrames*getChannels(), getVolume()); for (int i = 0; i < numFrames; ++i) { m_pLimiter->process(m_pMixBuffer+i*getChannels()); for (int j = 0; j < getChannels(); ++j) { ((short*)pDestBuffer)[i*2+j]=short(m_pMixBuffer[i*2+j]*32768); } } }
// Same as above, but with the simplex where the worst vertex is replaced // by the input vertex. void NMFitting::calcVonAndDiamWithReplacement(const MatrixXf& v_n, double& volume_normalized, double& diameter) { c_tmp_ = ordered_vert_[num_coeffs_]->coeff; ordered_vert_[num_coeffs_]->coeff = v_n; diameter = calcSimplexDiameter(); volume_normalized = calcVolume(); volume_normalized = volume_normalized / pow(diameter, num_coeffs_); ordered_vert_[num_coeffs_]->coeff = c_tmp_; }
/** Generate an empty MDBox with 3 dimensions, split 10x5x2 !!! Box controller has to be deleted saparately to avoid memory leaks in tests !!!!**/ MDBox<MDLeanEvent<3>, 3> *makeMDBox3() { // Split at 5 events auto splitter = new BoxController(3); splitter->setSplitThreshold(5); // Splits into 10x5x2 boxes splitter->setSplitInto(10); splitter->setSplitInto(1, 5); splitter->setSplitInto(2, 2); // Set the size to 10.0 in all directions auto out = new MDBox<MDLeanEvent<3>, 3>(splitter); for (size_t d = 0; d < 3; ++d) { out->setExtents(d, 0.0, 10.0); } out->calcVolume(); return out; }
void ClothSimulation::volumeConstraint( float4* vtx, float* mass, const int4* tris, int nTris, float initVolume, float coeff ) { float vol = calcVolume( vtx, tris, nTris ); float force = (vol - initVolume)*coeff; int nVtx = 0; for(int i=0; i<nTris; i++) { nVtx = max2( nVtx, max2( tris[i].x, max2( tris[i].y, tris[i].z) ) ); } nVtx += 1; float4* disp = new float4[nVtx]; for(int i=0; i<nVtx; i++) disp[i] = make_float4(0,0,0,0); for(int i=0; i<nTris; i++) { const int4& t = tris[i]; float4& v0 = vtx[t.x]; float4& v1 = vtx[t.y]; float4& v2 = vtx[t.z]; const float4 n = cross3(v1-v0, v2-v0 ); float nl = length3( n ); float area = nl/2.f; // force = max2( 0.f, force ); force = min2( 0.f, force ); float4 f = force/3.f*(n/nl); if( mass[t.x] != FLT_MAX ) disp[t.x] += f; // v0 += f; if( mass[t.y] != FLT_MAX ) disp[t.y] += f; // v1 += f; if( mass[t.z] != FLT_MAX ) disp[t.z] += f; // v2 += f; } for(int i=0; i<nVtx; i++) vtx[i] += disp[i]; delete [] disp; }
void process(int x, int y, int d, realType depth) { if (x < 0 || y < 0 || x >= hilbertSize || y >= hilbertSize || !hilbert[x][y]) { return; } if (depth > 1 + tanAlpha) { depth = 1 + tanAlpha; } if (depth < eps) { return; } calcVolume(depth); for (int dir = 0; dir < 4; dir++) { if (dir == d) { continue; } process(x + dx[dir], y + dy[dir], (dir + 2) % 4, depth - dy[dir] + dx[dir] * tanAlpha); } }
// Page 146 of Derivative Free Optimization - Conn, Scheinburg, Vicente double NMFitting::calcNormalizedVolume() { double diam = calcSimplexDiameter(); double vol = calcVolume(); return vol / pow(diam, num_coeffs_); }