SQLStorageBackend::SQLStorageBackend (StorageBackend::Type type) : Type_ (type) { QString strType; switch (Type_) { case SBSQLite: strType = "QSQLITE"; break; case SBPostgres: strType = "QPSQL"; break; case SBMysql: qWarning () << Q_FUNC_INFO << "it's not MySQL"; break; } DB_ = QSqlDatabase::addDatabase (strType, "PoshukuConnection"); switch (Type_) { case SBSQLite: { QDir dir = QDir::home (); dir.cd (".leechcraft"); dir.cd ("poshuku"); DB_.setDatabaseName (dir.filePath ("poshuku.db")); } break; case SBPostgres: { DB_.setDatabaseName (XmlSettingsManager::Instance ()-> property ("PostgresDBName").toString ()); DB_.setHostName (XmlSettingsManager::Instance ()-> property ("PostgresHostname").toString ()); DB_.setPort (XmlSettingsManager::Instance ()-> property ("PostgresPort").toInt ()); DB_.setUserName (XmlSettingsManager::Instance ()-> property ("PostgresUsername").toString ()); DB_.setPassword (XmlSettingsManager::Instance ()-> property ("PostgresPassword").toString ()); } break; case SBMysql: qWarning () << Q_FUNC_INFO << "it's not MySQL"; break; } if (!DB_.open ()) { LeechCraft::Util::DBLock::DumpError (DB_.lastError ()); throw std::runtime_error (QString ("Could not initialize database: %1") .arg (DB_.lastError ().text ()).toUtf8 ().constData ()); } InitializeTables (); CheckVersions (); }
void Storage::InitializeTables () { Impl_->AccountInfo_ = oral::Adapt<Account> (Impl_->DB_); Impl_->NakedExpenseEntryInfo_ = oral::Adapt<NakedExpenseEntry> (Impl_->DB_); Impl_->ReceiptEntryInfo_ = oral::Adapt<ReceiptEntry> (Impl_->DB_); Impl_->CategoryInfo_ = oral::Adapt<Category> (Impl_->DB_); Impl_->CategoryLinkInfo_ = oral::Adapt<CategoryLink> (Impl_->DB_); Impl_->RateInfo_ = oral::Adapt<Rate> (Impl_->DB_); const auto& tables = Impl_->DB_.tables (); QMap<QString, QString> queryCreates; queryCreates [Account::ClassName ()] = Impl_->AccountInfo_.CreateTable_; queryCreates [NakedExpenseEntry::ClassName ()] = Impl_->NakedExpenseEntryInfo_.CreateTable_; queryCreates [ReceiptEntry::ClassName ()] = Impl_->ReceiptEntryInfo_.CreateTable_; queryCreates [Category::ClassName ()] = Impl_->CategoryInfo_.CreateTable_; queryCreates [CategoryLink::ClassName ()] = Impl_->CategoryLinkInfo_.CreateTable_; queryCreates [Rate::ClassName ()] = Impl_->RateInfo_.CreateTable_; Util::DBLock lock (Impl_->DB_); lock.Init (); QSqlQuery query (Impl_->DB_); bool tablesCreated = false; for (const auto& key : queryCreates.keys ()) if (!tables.contains (key)) { tablesCreated = true; if (!query.exec (queryCreates [key])) { Util::DBLock::DumpError (query); throw std::runtime_error ("cannot create tables"); } } lock.Good (); // Otherwise queries created by oral::Adapt() don't work. if (tablesCreated) InitializeTables (); }
GslRandomgen::GslRandomgen( const bool def ) : defined( def ) { // the simple constructor if( !initialized ) { InitializeTables(); } myType = gsl_rng_defaultIndex; mySeed = gsl_rng_default_seed; if( def ) { me = gsl_rng_alloc(GetRngType(myType)); assert( me != NULL ); gsl_rng_set(me, mySeed); } else { me = NULL; } }
GslRandomgen::GslRandomgen( const int typeNo, const unsigned long seed ) : defined( true ) { // the fully parameterized constructor if( !initialized ) { InitializeTables(); } if(typeNo < 0 || typeNo >= gslalg_randomgeneratorTableSize) { defined = false; me = NULL; } else { myType = typeNo; const gsl_rng_type *T = GetRngType(myType); me = gsl_rng_alloc(T); assert( me != NULL ); mySeed = seed; gsl_rng_set(me, mySeed); } }
void AudioEngine::StartAudio( int cpuFreq, int pulseMinFreq, int pulseMaxFreq, int triangleMinFreq, int triangleMaxFreq) { if (_audioProvider != nullptr) { _audioProvider->Initialize(AudioGenerateCallback, this); _sampleRate = _audioProvider->GetSampleRate(); _silenceValue = _audioProvider->GetSilenceValue(); } _cpuFreq = cpuFreq; _nyquistFreq = _sampleRate / 2; _pulseMinFreq = pulseMinFreq; _pulseMaxFreq = pulseMaxFreq; _pulseFreqStep = (int)((_pulseMaxFreq - _pulseMinFreq) / WAVETABLE_FREQUENCY_STEPS); _triangleMinFreq = triangleMinFreq; _triangleMaxFreq = triangleMaxFreq; _triangleFreqStep = (int)((_triangleMaxFreq - _triangleMinFreq) / WAVETABLE_FREQUENCY_STEPS); _phaseDivider = _sampleRate / WAVETABLE_SAMPLES; _cyclesPerSample = (double)_cpuFreq / _sampleRate; // We can't synthesize any frequency above the Nyquist frequency. // Clip the max frequencies at the Nyquist frequency. if (_pulseMaxFreq > _nyquistFreq) _pulseMaxFreq = _nyquistFreq; if (_triangleMaxFreq > _nyquistFreq) _triangleMaxFreq = _nyquistFreq; InitializeTables(); InitializeChannels(); UnpauseAudio(); }
Storage::Storage (QObject *parent) : QObject (parent) , Impl_ (new StorageImpl) { Impl_->DB_ = QSqlDatabase::addDatabase ("QSQLITE", "Poleemery_Connection"); const auto& dir = Util::CreateIfNotExists ("poleemeery"); Impl_->DB_.setDatabaseName (dir.absoluteFilePath ("database.db")); if (!Impl_->DB_.open ()) { qWarning () << Q_FUNC_INFO << "unable to open database:" << Impl_->DB_.lastError ().text (); throw std::runtime_error ("Poleemery database creation failed"); } { QSqlQuery query (Impl_->DB_); query.exec ("PRAGMA foreign_keys = ON;"); } InitializeTables (); LoadCategories (); }
SQLStorageBackendMysql::SQLStorageBackendMysql (StorageBackend::Type type) : Type_ (type) { DB_ = QSqlDatabase::addDatabase ("QMYSQL", "PoshukuConnection"); DB_.setDatabaseName (XmlSettingsManager::Instance ()-> property ("MySQLDBName").toString ()); DB_.setHostName (XmlSettingsManager::Instance ()-> property ("MySQLHostname").toString ()); DB_.setPort (XmlSettingsManager::Instance ()-> property ("MySQLPort").toInt ()); DB_.setUserName (XmlSettingsManager::Instance ()-> property ("MySQLUsername").toString ()); DB_.setPassword (XmlSettingsManager::Instance ()-> property ("MySQLPassword").toString ()); if (!DB_.open ()) { LeechCraft::Util::DBLock::DumpError (DB_.lastError ()); throw std::runtime_error (QString ("Could not initialize database: %1") .arg (DB_.lastError ().text ()).toUtf8 ().constData ()); } InitializeTables (); }
int main(void) { InitializeTables(); FILE *fp; fp = fopen(SONG, "rb"); if (fp == NULL) { printf("Failed to open the song data.\n"); return -1; } struct stat songstat; int error = fstat(fileno(fp), &songstat); if (error != 0) { printf("Failed to stat the song data.\n"); return -1; } char *songdata = malloc(songstat.st_size); if (songdata == NULL) { printf("Failed to malloc for song data.\n"); return -1; } size_t bytesRead = fread(songdata, 1, songstat.st_size, fp); if (bytesRead != songstat.st_size) { printf("Failed to read song data. Got %zu of %u bytes.\n", bytesRead, (uint32_t)songstat.st_size); return -1; } fclose(fp); InitializeSong(songdata); outputfp = fopen("tonetest.wav", "w"); if (outputfp == NULL) { printf("Failed to open output file.\n"); return -1; } // Write the .wave file header fwrite("RIFF", 4, 1, outputfp); // Total size of the rest of the file (4 unsigned bytes to be filled in later) unsigned int value = 0; fwrite(&value, 4, 1, outputfp); fwrite("WAVE", 4, 1, outputfp); fwrite("fmt ", 4, 1, outputfp); // Chunk size (4 bytes) value = 16; fwrite(&value, 4, 1, outputfp); // Format code (2 bytes) value = 1; // WAVE_FORMAT_PCM fwrite(&value, 2, 1, outputfp); //Number of interleaved channels (2 bytes) uint16_t shortvalue = 1; // # WAVE_FORMAT_PCM fwrite(&shortvalue, 2, 1, outputfp); //Sample rate (4 bytes) value = BITRATE; fwrite(&value, 4, 1, outputfp); // Data rate (average bytes per second) (4 bytes) // Same as bitrate since we have 1 byte per sample value = BITRATE; fwrite(&value, 4, 1, outputfp); // Data block size (2 bytes) shortvalue = 1; fwrite(&shortvalue, 2, 1, outputfp); // Bits per sample (2 bytes) shortvalue = 8; fwrite(&shortvalue, 2, 1, outputfp); fwrite("data", 4, 1, outputfp); // Now calculate and write all the rest of the data while (!OutputAudioAndCalculateNextByte()); // Go back and fill in the final length fseek(outputfp, 4, SEEK_SET); gTotalBytesWritten += 24; // 24 is the length of the header fwrite(&gTotalBytesWritten, sizeof(gTotalBytesWritten), 1, outputfp); fclose(outputfp); }
bool DocumentConverter::Initialize() { InitializeTables(); return true; }