bool RingResampler::open(int inSampleRate, int outSampleRate) { qDebug() << "RingResampler: open( " << inSampleRate << ", " << outSampleRate << " )"; // paSampleRate = outSampleRate; vacSampleRate = inSampleRate; if(vacSampleRate < paSampleRate) buffSize = qPow(2, 12 + ((int)(qLn(paSampleRate/vacSampleRate)/qLn(2.0f)) + 3)); else if(vacSampleRate == paSampleRate) buffSize = MAX_DSP_BUFFER_SIZE*4; else buffSize = qPow(2, 12 + ((int)(qLn(vacSampleRate/paSampleRate)/qLn(2.0f)) + 3)); if(!NUMBER_IS_2_POW_K(buffSize)) { qWarning() << "RingResampler: open: incorrect buffer size = " << buffSize << " !"; return (false); } resPaToVac->initialize(paSampleRate, vacSampleRate); resVacToPa->initialize(vacSampleRate, paSampleRate); pDataInputL->Resize(buffSize); pDataInputR->Resize(buffSize); pDataOutputL->Resize(buffSize); pDataOutputR->Resize(buffSize); pDataInputL->Clear(); pDataInputR->Clear(); pDataOutputL->Clear(); pDataOutputR->Clear(); qMemSet(pInDataL, 0, MAX_DSP_BUFFER_SIZE*sizeof(float)); qMemSet(pInDataR, 0, MAX_DSP_BUFFER_SIZE*sizeof(float)); qMemSet(pOutDataL, 0, MAX_DSP_BUFFER_SIZE*sizeof(float)); qMemSet(pOutDataR, 0, MAX_DSP_BUFFER_SIZE*sizeof(float)); isOpened = true; return (true); }
tSidebarControlTrim::tSidebarControlTrim(tMercuryStyle* pStyle, QGraphicsItem* pParent) : tSidebarControl(pStyle, true, pParent) , m_ValueLeft(0.f) , m_ValueRight(0.f) , m_Count(4) , m_TabsVisible(true) , m_TrimVisible(true) { Assert(pStyle != 0); qMemSet(m_Values, 0, sizeof(m_Values)); qMemSet(m_ZeroPoints, 0, sizeof(m_ZeroPoints)); qMemSet(m_TabZeroPoint, 0, sizeof(m_TabZeroPoint)); qMemSet(m_TrimValid, 0, sizeof(m_TrimValid)); qMemSet(m_TabValid, 0, sizeof(m_TabValid)); SetBackgroundColorRole(tMercuryStyle::eColorRoleSidebarDark); }
/*! Constructs an empty byte array matcher that won't match anything. Call setPattern() to give it a pattern to match. */ QByteArrayMatcher::QByteArrayMatcher() : d(0) { p.p = 0; p.l = 0; qMemSet(p.q_skiptable, 0, sizeof(p.q_skiptable)); }
bool DirectShowIOReader::nonBlockingRead( LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead, HRESULT *result) { const qint64 maxSize = qMin<qint64>(m_device->size(), position + length); if (position > m_device->size()) { *bytesRead = 0; *result = S_FALSE; return true; } else if (m_device->bytesAvailable() + m_device->pos() >= maxSize) { if (m_device->pos() != position && !m_device->seek(position)) { *bytesRead = 0; *result = S_FALSE; return true; } else { const qint64 maxBytes = qMin<qint64>(length, m_device->bytesAvailable()); *bytesRead = m_device->read(reinterpret_cast<char *>(buffer), maxBytes); if (*bytesRead != length) { qMemSet(buffer + *bytesRead, 0, length - *bytesRead); *result = S_FALSE; } else { *result = S_OK; } return true; } } else { return false; } }
HRESULT DirectShowIOReader::blockingRead( LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead) { *bytesRead = 0; if (qint64(position) > m_device->size()) return S_FALSE; const qint64 maxSize = qMin<qint64>(m_device->size(), position + length); while (m_device->bytesAvailable() + m_device->pos() < maxSize) { if (!m_device->waitForReadyRead(-1)) return S_FALSE; } if (m_device->pos() != position && !m_device->seek(position)) return S_FALSE; const qint64 maxBytes = qMin<qint64>(length, m_device->bytesAvailable()); *bytesRead = m_device->read(reinterpret_cast<char *>(buffer), maxBytes); if (*bytesRead != length) { qMemSet(buffer + *bytesRead, 0, length - *bytesRead); return S_FALSE; } else { return S_OK; } }
void tst_QItemDelegate::decoration() { if (QByteArray(QTest::currentDataTag()) == QByteArray("pixmap 30x30 big")) QSKIP("Skipping this as it demands too much memory and potential hangs", SkipSingle); Q_CHECK_PAINTEVENTS QFETCH(int, type); QFETCH(QSize, size); QFETCH(QSize, expected); QTableWidget table(1, 1); TestItemDelegate delegate; table.setItemDelegate(&delegate); table.show(); #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&table); #endif QApplication::setActiveWindow(&table); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&table)); QVariant value; switch ((QVariant::Type)type) { case QVariant::Pixmap: { QPixmap pm(size); pm.fill(Qt::black); value = pm; break; } case QVariant::Image: { QImage img(size, QImage::Format_Mono); qMemSet(img.bits(), 0, img.byteCount()); value = img; break; } case QVariant::Icon: { QPixmap pm(size); pm.fill(Qt::black); value = QIcon(pm); break; } case QVariant::Color: value = QColor(Qt::green); break; default: break; } QTableWidgetItem *item = new QTableWidgetItem; item->setData(Qt::DecorationRole, value); table.setItem(0, 0, item); item->setSelected(true); QApplication::processEvents(); QTRY_COMPARE(delegate.decorationRect.size(), expected); }
static void initializePadding(QImage *image) { int effectiveBytesPerLine = (image->width() * image->depth() + 7) / 8; int paddingBytes = image->bytesPerLine() - effectiveBytesPerLine; if (paddingBytes == 0) return; for (int y = 0; y < image->height(); ++y) { qMemSet(image->scanLine(y) + effectiveBytesPerLine, 0, paddingBytes); } }
void tst_QByteArray::qvsnprintf() { char buf[20]; qMemSet(buf, 42, sizeof(buf)); QCOMPARE(::qsnprintf(buf, 10, "%s", "bubu"), 4); QCOMPARE(static_cast<const char *>(buf), "bubu"); QCOMPARE(buf[5], char(42)); qMemSet(buf, 42, sizeof(buf)); QCOMPARE(::qsnprintf(buf, 5, "%s", "bubu"), 4); QCOMPARE(static_cast<const char *>(buf), "bubu"); QCOMPARE(buf[5], char(42)); qMemSet(buf, 42, sizeof(buf)); #ifdef Q_OS_WIN // VS 2005 uses the Qt implementation of vsnprintf. # if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) QCOMPARE(::qsnprintf(buf, 3, "%s", "bubu"), -1); QCOMPARE(static_cast<const char*>(buf), "bu"); # else // windows has to do everything different, of course. QCOMPARE(::qsnprintf(buf, 3, "%s", "bubu"), -1); buf[19] = '\0'; QCOMPARE(static_cast<const char *>(buf), "bub****************"); # endif #else #ifdef Q_OS_IRIX // Irix reports back the amount of characters written without the \0 QCOMPARE(::qsnprintf(buf, 3, "%s", "bubu"), 2); #else // Every other system in this world reports the amount of data that could have been written QCOMPARE(::qsnprintf(buf, 3, "%s", "bubu"), 4); #endif QCOMPARE(static_cast<const char*>(buf), "bu"); #endif QCOMPARE(buf[4], char(42)); #ifndef Q_OS_WIN qMemSet(buf, 42, sizeof(buf)); QCOMPARE(::qsnprintf(buf, 10, ""), 0); #endif }
QByteArray composePreprocessorOutput(const Symbols &symbols) { QByteArray output; int lineNum = 1; Token last = PP_NOTOKEN; Token secondlast = last; int i = 0; while (hasNext(symbols, i)) { Symbol sym = next(symbols, i); switch (sym.token) { case PP_NEWLINE: case PP_WHITESPACE: if (last != PP_WHITESPACE) { secondlast = last; last = PP_WHITESPACE; output += ' '; } continue; case PP_STRING_LITERAL: if (last == PP_STRING_LITERAL) output.chop(1); else if (secondlast == PP_STRING_LITERAL && last == PP_WHITESPACE) output.chop(2); else break; output += sym.lexem().mid(1); secondlast = last; last = PP_STRING_LITERAL; continue; case MOC_INCLUDE_BEGIN: lineNum = 0; continue; case MOC_INCLUDE_END: lineNum = sym.lineNum; continue; default: break; } secondlast = last; last = sym.token; const int padding = sym.lineNum - lineNum; if (padding > 0) { output.resize(output.size() + padding); qMemSet(output.data() + output.size() - padding, '\n', padding); lineNum = sym.lineNum; } output += sym.lexem(); } return output; }
QMallocPoolPrivate(void * _pool, unsigned int _poolLen, QMallocPool::PoolType type, const QString &_name) : name(_name), pool((char *)_pool), poolLength(_poolLen), poolPtr(0) { Q_ASSERT(pool); Q_ASSERT(poolLength > 0); if(QMallocPool::Owned == type) { qMemSet(&owned_mstate, 0, sizeof(struct malloc_state)); mstate = &owned_mstate; } else if(QMallocPool::NewShared == type) { Q_ASSERT(poolLength >= sizeof(struct malloc_state)); qMemSet(pool, 0, sizeof(struct malloc_state)); mstate = (struct malloc_state *)pool; pool += sizeof(struct malloc_state); poolLength -= sizeof(struct malloc_state); } else if(QMallocPool::Shared == type) { Q_ASSERT(poolLength >= sizeof(struct malloc_state)); mstate = (struct malloc_state *)pool; pool += sizeof(struct malloc_state); poolLength -= sizeof(struct malloc_state); } }
void QPAGenerator::writeGMap() { const quint16 glyphCount = fe->glyphCount(); writeUInt16(QFontEngineQPA::GMapBlock); writeUInt16(0); // padding writeUInt32(glyphCount * 4); QByteArray &buffer = dev->buffer(); const int numBytes = glyphCount * sizeof(quint32); qint64 pos = buffer.size(); buffer.resize(pos + numBytes); qMemSet(buffer.data() + pos, 0xff, numBytes); dev->seek(pos + numBytes); }
VideoWidget::VideoWidget(QWidget *parent) : BackendNode(parent), m_aspectRatio(Phonon::VideoWidget::AspectRatioAuto), m_scaleMode(Phonon::VideoWidget::FitInView), m_brightness(0.), m_contrast(0.), m_hue(0.), m_saturation(0.), m_noNativeRendererSupported(false) { //initialisation of the widget m_widget = new VideoWindow(parent, this); //initialization of the renderers qMemSet(m_renderers, 0, sizeof(m_renderers)); for(int i = 0; i< FILTER_COUNT ;++i) { //This might return a non native (ie Qt) renderer in case native is not supported AbstractVideoRenderer *renderer = getRenderer(i, Native, true); m_filters[i] = renderer->getFilter(); } //by default, we take the first VideoWindow object setCurrentGraph(0); }
/*! Constructs an empty byte array matcher that won't match anything. Call setPattern() to give it a pattern to match. */ QByteArrayMatcher::QByteArrayMatcher() : d(0) { qMemSet(q_skiptable, 0, sizeof(q_skiptable)); }
QImage QFontEngineDirectWrite::imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform) { UINT16 glyphIndex = t; FLOAT glyphAdvance = 0; DWRITE_GLYPH_OFFSET glyphOffset; glyphOffset.advanceOffset = 0; glyphOffset.ascenderOffset = 0; DWRITE_GLYPH_RUN glyphRun; glyphRun.fontFace = m_directWriteFontFace; glyphRun.fontEmSize = fontDef.pixelSize; glyphRun.glyphCount = 1; glyphRun.glyphIndices = &glyphIndex; glyphRun.glyphAdvances = &glyphAdvance; glyphRun.isSideways = false; glyphRun.bidiLevel = 0; glyphRun.glyphOffsets = &glyphOffset; DWRITE_MATRIX transform; transform.dx = subPixelPosition.toReal(); transform.dy = 0; transform.m11 = xform.m11(); transform.m12 = xform.m12(); transform.m21 = xform.m21(); transform.m22 = xform.m22(); IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; HRESULT hr = m_directWriteFactory->CreateGlyphRunAnalysis( &glyphRun, 1.0f, &transform, DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC, DWRITE_MEASURING_MODE_NATURAL, 0.0, 0.0, &glyphAnalysis ); if (SUCCEEDED(hr)) { RECT rect; glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect); rect.left -= margin; rect.top -= margin; rect.right += margin; rect.bottom += margin; int width = rect.right - rect.left; int height = rect.bottom - rect.top; int size = width * height * 3; if (size > 0) { BYTE *alphaValues = new BYTE[size]; qMemSet(alphaValues, size, 0); hr = glyphAnalysis->CreateAlphaTexture(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect, alphaValues, size); if (SUCCEEDED(hr)) { QImage img(width, height, QImage::Format_RGB32); img.fill(0xffffffff); for (int y=0; y<height; ++y) { uint *dest = reinterpret_cast<uint *>(img.scanLine(y)); BYTE *src = alphaValues + width * 3 * y; for (int x=0; x<width; ++x) { dest[x] = *(src) << 16 | *(src + 1) << 8 | *(src + 2); src += 3; } } delete[] alphaValues; glyphAnalysis->Release(); return img; } else { delete[] alphaValues; glyphAnalysis->Release(); qErrnoWarning("QFontEngineDirectWrite::imageForGlyph: CreateAlphaTexture failed"); } } } else { qErrnoWarning("QFontEngineDirectWrite::imageForGlyph: CreateGlyphRunAnalysis failed"); } return QImage(); }
/*! Constructs an empty string matcher that won't match anything. Call setPattern() to give it a pattern to match. */ QStringMatcher::QStringMatcher() : d_ptr(0), q_cs(Qt::CaseSensitive) { qMemSet(q_data, 0, sizeof(q_data)); }
void tst_QVolatileImage::bitmap() { #ifdef Q_OS_SYMBIAN CFbsBitmap *bmp = new CFbsBitmap; QVERIFY(bmp->Create(TSize(100, 50), EColor64K) == KErrNone); QVolatileImage bmpimg(bmp); CFbsBitmap *dupbmp = static_cast<CFbsBitmap *>(bmpimg.duplicateNativeImage()); QVERIFY(dupbmp); QVERIFY(dupbmp != bmp); QCOMPARE(dupbmp->DataAddress(), bmp->DataAddress()); delete dupbmp; delete bmp; bmpimg.beginDataAccess(); qMemSet(bmpimg.bits(), 0, bmpimg.byteCount()); qMemSet(bmpimg.bits(), 1, bmpimg.bytesPerLine() * bmpimg.height()); bmpimg.endDataAccess(); // Test bgr->rgb conversion in case of EColor16M. bmp = new CFbsBitmap; QVERIFY(bmp->Create(TSize(101, 89), EColor16M) == KErrNone); bmp->BeginDataAccess(); TUint32 *addr = bmp->DataAddress(); uint rgb = QColor(10, 20, 30).rgb(); qMemCopy(bmp->DataAddress(), &rgb, 3); bmp->EndDataAccess(); TRgb symrgb; bmp->GetPixel(symrgb, TPoint(0, 0)); QVERIFY(symrgb.Red() == 10 && symrgb.Green() == 20 && symrgb.Blue() == 30); bmpimg = QVolatileImage(bmp); QVERIFY(bmpimg.toImage().pixel(0, 0) == rgb); // check if there really was a conversion bmp->BeginDataAccess(); bmpimg.beginDataAccess(); qMemCopy(&rgb, bmpimg.constBits(), 3); uint rgb2 = rgb; qMemCopy(&rgb2, bmp->DataAddress(), 3); QVERIFY(rgb != rgb2); bmpimg.endDataAccess(true); bmp->EndDataAccess(true); delete bmp; bmp = new CFbsBitmap; QVERIFY(bmp->Create(TSize(101, 89), EGray2) == KErrNone); bmpimg = QVolatileImage(bmp); // inverts pixels, but should do it in place QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress()); QCOMPARE(bmpimg.format(), QImage::Format_MonoLSB); bmpimg.ensureFormat(QImage::Format_ARGB32_Premultiplied); QVERIFY(bmpimg.constBits() != (const uchar *) bmp->DataAddress()); QCOMPARE(bmpimg.format(), QImage::Format_ARGB32_Premultiplied); delete bmp; // The following two formats must be optimal always. bmp = new CFbsBitmap; QVERIFY(bmp->Create(TSize(101, 89), EColor16MAP) == KErrNone); bmpimg = QVolatileImage(bmp); QCOMPARE(bmpimg.format(), QImage::Format_ARGB32_Premultiplied); QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress()); bmpimg.ensureFormat(QImage::Format_ARGB32_Premultiplied); QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress()); delete bmp; bmp = new CFbsBitmap; QVERIFY(bmp->Create(TSize(101, 89), EColor16MU) == KErrNone); bmpimg = QVolatileImage(bmp); QCOMPARE(bmpimg.format(), QImage::Format_RGB32); QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress()); bmpimg.ensureFormat(QImage::Format_RGB32); QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress()); delete bmp; #else QSKIP("CFbsBitmap is only available on Symbian, skipping bitmap test", SkipSingle); #endif }
/*! Constructs an empty string matcher that won't match anything. Call setPattern() to give it a pattern to match. */ QStringMatcher::QStringMatcher() : d_ptr(0), q_cs(Qt::CaseSensitive) { qMemSet(q_skiptable, 0, sizeof(q_skiptable)); }
TWtVehicle TWtDev::GetVehFromDev(int AIndex) { int ret, ZhouZuShu; long TyreWeight[4]; long AxisWeight[10]; TAxis A; TWtVehicle V; double Speed; quint32 ZhouZuWeight; int AxisType; //取轴组数 //取各轴组轴型以及各轴重 //取车速 // Result= nil; ret = Dev_AxisCount(AIndex); if(ret == -1) { V.Clear(); LogMsg("lane",tr("[TWtDev.GetVehFromDev]WimDev_AxisCount失败")); return V; } if (ret==0) { V.Clear(); LogMsg("lane",tr("[TWtDev.GetVehFromDev]WimDev_AxisCount返回0,车辆序号不存在")); return V; } //V = TWtVehicle; ZhouZuShu= ret; for(int i= 1; i<= ZhouZuShu; i++) { qMemSet(TyreWeight, 0, sizeof(TyreWeight)); ret =Dev_AxisData(AIndex, i, &AxisType, TyreWeight); if( ret==-1) { LogMsg("lane",tr("[TWtDev.GetVehFromDev]WimDev_AxisData调用失败")); V.clear(); //只要取任何轴组出错,就返回nil return V; } ZhouZuWeight = 0; for( int j= 0;j<sizeof(TyreWeight);j++) { if( TyreWeight[j] > 0) { A.setWeight((quint32)qRound(TyreWeight[j] * (1 -FDiscountRate))); V.append(A); ZhouZuWeight = ZhouZuWeight + A.getFWeight(); } } if (i <= 12 ) //最多12个轴组信息 { QString info= V.GetFAxisInfo() + QObject::tr("%1").arg(AxisType) +QObject::tr("%1").arg(ZhouZuWeight,6,10,QLatin1Char('0')); V.setFAxisInfo(info); } } //取车速 Speed = 0; qMemSet(AxisWeight,0, sizeof(AxisWeight)); ret = Dev_AxisInfo(AIndex, AxisWeight, Speed); if( ret==0) { V.setFSpeed(Speed); } else { V.Clear(); LogMsg("lane",tr("[TWtDev.GetVehFromDev]WimDev_AxisInfo调用失败")); } return V; }
/*! Compares a string using a natural comparison algorithm. In other words, it sorts the numbers in value order and the remaining characters in ASCII order. The code is based on the LGPL C++ implementation found at http://www.davekoelle.com/alphanum.html See this header file for license details. */ int Movida::naturalCompare(const QString &string_a, const QString &string_b, Qt::CaseSensitivity cs) { if (string_a.unicode() == string_b.unicode()) return 0; if (string_a.isEmpty()) return -1; if (string_b.isEmpty()) return +1; const bool _cs = cs == Qt::CaseSensitive; enum Mode { String, Number } mode = String; const QChar* a_begin = string_a.unicode(); const QChar* a_end = a_begin + string_a.length(); const QChar* a = a_begin; const QChar* b_begin = string_b.unicode(); const QChar* b_end = b_begin + string_b.length(); const QChar* b = b_begin; bool mode_change = false; int last_num_compare = 0; while (a != a_end && b != b_end) { last_num_compare = 0; switch (mode) { case String: { while (a != a_end && b != b_end) { // Check if this are digit characters const bool a_digit = a->isDigit(); const bool b_digit = b->isDigit(); // If both characters are digits, we continue in Number mode if (a_digit && b_digit) { mode = Number; mode_change = true; break; } // If only the left character is a digit, we have a result if (a_digit) return -1; // If only the right character is a digit, we have a result if (b_digit) return +1; // Compute the difference of both characters const quint16 u_a = a->unicode(); const quint16 u_b = b->unicode(); const quint16 diff = _cs ? (u_a - u_b) : (QChar::toCaseFolded(u_a) - QChar::toCaseFolded(u_b)); // If they differ we have a result if (diff != 0) return diff; // Otherwise process the next characters ++a; ++b; } } break; case Number: { // Get the left number CharBuff a_buff; qMemSet(a_buff.data(), 0, a_buff.capacity()); a = extractNumber(a, a_end, a_buff); quint64 a_num = qstrtoll(a_buff.constData(), 0, 10, 0); // Get the right number CharBuff b_buff; qMemSet(b_buff.data(), 0, b_buff.capacity()); b = extractNumber(b, b_end, b_buff); quint64 b_num = qstrtoll(b_buff.constData(), 0, 10, 0); // If the difference is not equal to zero, we have a comparison result const long diff = a_num - b_num; if (diff != 0) return diff; // If the strings differ only by the number of padding zeros // in the current number, we should take it into account and // simulate a lexical comparison by comparing the number of // digits. last_num_compare = a_buff.size() - b_buff.size(); // Otherwise we process the next substring in String mode mode = String; } break; } if (!mode_change && a != a_end && b != b_end) { ++a; ++b; } else mode_change = false; } if (a == a_end && b == b_end) return last_num_compare; if (a == a_end) return -1; if (b == b_end) return +1; return last_num_compare; }
void VoiceRecorder::BufferIO(void *pInL, void *pInR, quint32 FrameCount) { if(!isOpened) return; float scale = voiceFromDb(scaleDb); if(isPlaying) { QByteArray dataBuf; float *pL, *pR; pL = (float*)pInL; pR = (float*)pInR; uint step = wavHeader.channels*(wavHeader.bitsPerSample/8); dataBuf = waveFile.read(FrameCount*wavHeader.channels*(wavHeader.bitsPerSample/8)); float *pData = new float[FrameCount*2]; qMemSet(pData, 0, sizeof(float)*FrameCount); if(dataBuf.size() == (int)(FrameCount * step)) { memcpy(reinterpret_cast<char *>(pData), dataBuf.data(), dataBuf.size()); for(uint i = 0, j = 0; i < FrameCount; i++, j += 2) { if(isTx) { pL[i] = pData[j]*scale; pR[i] = pData[j+1]*scale; } else { pL[i] = pData[j]; pR[i] = pData[j+1]; } } delete pData; } else { memcpy(reinterpret_cast<char *>(pData), dataBuf.data(), dataBuf.size()); for(uint i = 0, j = 0; i < FrameCount; i++, j += 2) { if(isTx) { pL[i] = pData[j]*scale; pR[i] = pData[j+1]*scale; } else { pL[i] = pData[j]; pR[i] = pData[j+1]; } } delete pData; emit statePlay(false); isPlaying = false; isOpened = false; waveFile.close(); } } else if(isRecording) { float *pL, *pR, *pData = new float[FrameCount*2]; pL = (float*)pInL; pR = (float*)pInR; for(uint i = 0, j = 0; i < FrameCount; i++, j += 2) { pData[j] = pL[i]; pData[j+1] = pR[i]; } voiceArray = QByteArray(reinterpret_cast<char *>(pData), (FrameCount*2*sizeof(float))); waveFile.write(voiceArray); delete pData; } }
std::string InchiLineFormat::write(const chemkit::Molecule *molecule) { // check for valid molecule if(molecule->atomCount() > 1024){ setErrorString("InChI does not support molecules with more that 1024 atoms."); return std::string(); } // setup inchi input structure inchi_Input input; input.atom = new inchi_Atom[molecule->atomCount()]; input.stereo0D = 0; input.szOptions = 0; input.num_atoms = molecule->atomCount(); input.num_stereo0D = 0; inchi_Atom *inputAtom = &input.atom[0]; QList<const chemkit::Atom *> chiralAtoms; foreach(const chemkit::Atom *atom, molecule->atoms()){ // coordinates inputAtom->x = 0; inputAtom->y = 0; inputAtom->z = 0; // bonds and neighbors int neighborCount = 0; foreach(const chemkit::Bond *bond, atom->bonds()){ const chemkit::Atom *neighbor = bond->otherAtom(atom); if(neighbor->index() < atom->index()) continue; inputAtom->neighbor[neighborCount] = neighbor->index(); inputAtom->bond_type[neighborCount] = bond->order(); inputAtom->bond_stereo[neighborCount] = INCHI_BOND_STEREO_NONE; neighborCount++; } inputAtom->num_bonds = neighborCount; // element symbol strncpy(inputAtom->elname, atom->symbol().c_str(), ATOM_EL_LEN); // isotopic hydrogens inputAtom->num_iso_H[0] = -1; inputAtom->num_iso_H[1] = 0; inputAtom->num_iso_H[2] = 0; inputAtom->num_iso_H[3] = 0; // misc data inputAtom->isotopic_mass = 0; inputAtom->radical = 0; inputAtom->charge = 0; // chiral atoms if(atom->isChiral()){ chiralAtoms.append(atom); } // move pointer to the next position in the atom array inputAtom++; } // add stereochemistry if enabled bool stereochemistry = option("stereochemistry").toBool(); if(stereochemistry){ input.stereo0D = new inchi_Stereo0D[chiralAtoms.size()]; input.num_stereo0D = chiralAtoms.size(); int chiralIndex = 0; foreach(const chemkit::Atom *atom, chiralAtoms){ inchi_Stereo0D *stereo = &input.stereo0D[chiralIndex]; qMemSet(stereo, 0, sizeof(*stereo)); stereo->central_atom = atom->index(); int neighborIndex = 0; foreach(const chemkit::Atom *neighbor, atom->neighbors()){ stereo->neighbor[neighborIndex++] = neighbor->index(); } stereo->type = INCHI_StereoType_Tetrahedral; if(atom->chirality() == chemkit::Atom::R){ stereo->parity = INCHI_PARITY_EVEN; } else if(atom->chirality() == chemkit::Atom::S){ stereo->parity = INCHI_PARITY_ODD; } else if(atom->chirality() == chemkit::Atom::UnspecifiedChirality){ stereo->parity = INCHI_PARITY_UNDEFINED; } else{ stereo->parity = INCHI_PARITY_UNKNOWN; } chiralIndex++; } }