int ModelAssemble::GetStartFileId(){ double temp = RandomF(0,1); double sum = 0.0; for(int i = mFileNum - 1;i >= 0;i--){ sum += mProbability[i]; if(sum > temp){ return i + 1; } } return 0; }
void ModelAssemble::CreateStartTime(){ double temp; mStartTime.push_back(0.0); double sum = 0.0; for(int i = 1;i < mMaxClientNum;i++){ temp = RandomF(0,1); temp = 1 - temp; temp = 0 - log(temp) / mLambda; //秒 sum += temp; mStartTime.push_back(sum); } // for(int i = 0;i < mMaxClientNum;i++) // cout << mStartTime[i] << endl; }
DataServer::DataServer(int fileNum,int minLength,int maxLength,int blockSize, double minBitRate,double maxBitRate){ mFileNum = fileNum; for(int i = 1;i <= MAX_FILE_NUM;i++){ mFileInfo[i].bitRate = RandomF(minBitRate,maxBitRate); mFileInfo[i].fileId = i; mFileInfo[i].segNum = 0; mFileInfo[i].info.clear(); } for(int i = 1;i <= fileNum;i++){ int length = RandomI(minLength,maxLength); mFileInfo[i].segNum = (length * 1000) / blockSize; } }
YSE::DSP::buffer & YSE::DSP::lfo::operator()(LFO_TYPE type, Flt frequency) { // avoid divisions by zero if (frequency == 0) type = LFO_NONE; switch (type) { case LFO_NONE: { result = 1; previousType = type; break; } case LFO_RANDOM: case LFO_SQUARE: { // shorten current value if new frequency is lower UInt phaseLength = SAMPLERATE / frequency * 0.5; if (phaseLength < lineLength) lineLength = phaseLength; if (previousType != type) { lineLength = phaseLength; currentLineValue = type == LFO_SQUARE ? 1.f : RandomF(); previousType = type; } if (lineLength > result.getLength()) { lineLength -= result.getLength(); result = currentLineValue; } else { UInt samplesToProcess = result.getLength(); UInt pos = 0; while (samplesToProcess) { UInt steps = lineLength > samplesToProcess ? samplesToProcess : lineLength; if (previousLineValue != currentLineValue) { UInt rampSteps = steps > 200 ? 200 : steps; result.drawLine(pos, pos + rampSteps, previousLineValue, currentLineValue); result.drawLine(pos + rampSteps, pos + steps, currentLineValue); previousLineValue = currentLineValue; } else { result.drawLine(pos, pos + steps, currentLineValue); } lineLength -= steps; if (!lineLength) { previousLineValue = currentLineValue; if (type == LFO_SQUARE) currentLineValue = currentLineValue > 0.9f ? 0.f : 1.f; else { // type = LFO_RANDOM currentLineValue = RandomF(); } lineLength = phaseLength; } pos += steps; samplesToProcess -= steps; } } break; } case LFO_SAW: { previousType = LFO_SAW; UInt samplesToProcess = result.getLength(); Flt * out = result.getPtr(); Flt * in = LfoSawTable.getPtr(); while (samplesToProcess) { *out++ = in[(UInt)cursor]; cursor += frequency; if (cursor >= SAMPLERATE) cursor -= SAMPLERATE; samplesToProcess--; } break; } case LFO_SAW_REVERSED: { previousType = LFO_SAW_REVERSED; UInt samplesToProcess = result.getLength(); Flt * out = result.getPtr(); Flt * in = LfoSawTable.getPtr(); while (samplesToProcess) { *out++ = in[(UInt)cursor]; cursor -= frequency; if (cursor < 0) cursor += SAMPLERATE; samplesToProcess--; } break; } case LFO_TRIANGLE: { previousType = LFO_TRIANGLE; UInt samplesToProcess = result.getLength(); Flt * out = result.getPtr(); Flt * in = LfoTriangleTable.getPtr(); while (samplesToProcess) { *out++ = in[(UInt)cursor]; cursor += frequency; if (cursor >= SAMPLERATE) cursor -= SAMPLERATE; samplesToProcess--; } break; } case LFO_SINE: { previousType = LFO_SINE; UInt samplesToProcess = result.getLength(); Flt * out = result.getPtr(); Flt * in = LfoTriangleTable.getPtr(); while (samplesToProcess) { *out++ = in[(UInt)cursor]; cursor += frequency; if (cursor >= SAMPLERATE) cursor -= SAMPLERATE; samplesToProcess--; } break; } } previousLineValue = result.getBack(); return result; }