void Audio::run() { if (!initialized) { init(); initialized = true; qDebug() << "Audio components initialized."; } if (synth->masterPlaying && synth->isPlaying()) { replaceBuffer(synth->genChunk()); playBuffer(); // resetBuffer(); } if (state != snd_pcm_state(handle)) { state = snd_pcm_state(handle); qDebug() << "State: " << state; } // Buffer underrun (not being written to fast enough) if (state == 4) { snd_pcm_drain(handle); prepareDevice(); } }
/** * This function initializes the socket connection and fetches the socket options, like the uid, pid, and gid of the client process. At the end of this function, the state is set to Server, initializing the service selection on the client side. */ void QtRpc::ServerProtocolInstanceSocket::init() { QMutexLocker locker(&qxt_d().mutex); qxt_d().socket = new QLocalSocket(); qxt_d().socket->setSocketDescriptor(qxt_d().sd); prepareDevice(qxt_d().socket); qxt_d().socket->flush(); #ifdef Q_OS_LINUX struct ucred cr; socklen_t cl = sizeof(cr); if (getsockopt(qxt_d().sd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) == 0) { qxt_d().pid = cr.pid; qxt_d().uid = cr.uid; qxt_d().gid = cr.gid; } else { qWarning() << "Failed to get socket optios"; } #endif //Immediatly put things in the service state changeState(Service); }
KIso::KIso(const QString& filename, const QString & _mimetype) : KArchive(0L) { KISOFUNC; KISODEBUG("Starting KIso: " << filename << " - type: " << _mimetype); m_startsec = -1; m_filename = filename; d = new KIsoPrivate; QString mimetype(_mimetype); bool forced = true; if (mimetype.isEmpty()) { QMimeDatabase db; QMimeType mt = db.mimeTypeForFile(filename, QMimeDatabase::MatchContent); if (mt.isValid()) mimetype = mt.name(); //qDebug() << "KIso::KIso mimetype=" << mimetype << endl; // Don't move to prepareDevice - the other constructor theoretically allows ANY filter if (mimetype == "application/x-tgz" || mimetype == "application/x-targz" || // the latter is deprecated but might still be around mimetype == "application/x-webarchive") // that's a gzipped tar file, so ask for gzip filter mimetype = "application/x-gzip"; else if (mimetype == "application/x-tbz") // that's a bzipped2 tar file, so ask for bz2 filter mimetype = "application/x-bzip2"; else { // Something else. Check if it's not really gzip though (e.g. for KOffice docs) QFile file(filename); if (file.open(QIODevice::ReadOnly)) { char firstByte; char secondByte; char thirdByte; file.getChar(&firstByte); file.getChar(&secondByte); file.getChar(&thirdByte); if (firstByte == 0037 && secondByte == (char)0213) mimetype = "application/x-gzip"; else if (firstByte == 'B' && secondByte == 'Z' && thirdByte == 'h') mimetype = "application/x-bzip2"; else if (firstByte == 'P' && secondByte == 'K' && thirdByte == 3) { char fourthByte; file.getChar(&fourthByte); if (fourthByte == 4) mimetype = "application/x-zip"; } } } forced = false; } prepareDevice(filename, mimetype, forced); }
/** * The constructor initializes the socket and the timeout timer and connects all the needed signals and slots. The constructor also calls ClientProtocolIODevice::prepareDevice() to prepare the socket for use. * @param parent Optional parent for the QObject */ ClientProtocolTcp::ClientProtocolTcp(QObject *parent) : ClientProtocolIODevice(parent) { QXT_INIT_PRIVATE(ClientProtocolTcp); qxt_d().timer.setInterval(10000); connect(&qxt_d().timer, SIGNAL(timeout()), &qxt_d(), SLOT(ping())); #ifndef QT_NO_OPENSSL connect(&qxt_d().socket, SIGNAL(sslErrors(QList<QSslError>)), &qxt_d().socket, SLOT(ignoreSslErrors())); #endif connect(&qxt_d().socket, SIGNAL(disconnected()), &qxt_d().timer, SLOT(stop())); connect(&qxt_d().socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); qxt_d().lastPing = QDateTime::currentDateTime(); prepareDevice(&qxt_d().socket); }
void Audio::init() { device = "default"; buffer = new float[CHUNK_SIZE](); synth = new Synth(&SAMPLE_RATE, &CHUNK_SIZE); // baseHz, octave, range, quantize, divisions, interpolate, steps translator = new Translator(110, 2, 3, false, 12, false, 3); synth->setTone(Wavetable::SINE); prepareDevice(); qDebug() << "Audio thread: " << QThread::currentThreadId(); for (int i = 0; i < CHUNK_SIZE; i++) buffertest.push_back(&buffer[i]); connect(translator, SIGNAL(sendDataToSynth(int,float,float)), synth, SLOT(sendData(int, float, float))); emit initDone(); }