qDebug() << "Попугаев: " << i;
C++ (Qt)int a;short b;long c;strm >> a >> b >> c;
a = file.ReadInt();b = file.ReadShort();c = file.ReadLong();
void Widget::startrec(){ outFile.setFileName("record.raw"); outFile.open(QIODevice::WriteOnly|QIODevice::Truncate); // prepare to record QAudioFormat format; QTimer* timer = new QTimer; format.setFrequency(8000); format.setCodec("audio/pcm"); format.setChannels(2); format.setSampleSize(8); format.setByteOrder( QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); if (!info.isFormatSupported(format)) { qWarning()<<"default format not supported try to use nearest"; format = info.nearestFormat(format); } inSignal = new QAudioInput(format, reinterpret_cast<QObject*>(this)); inSignal->start(&outFile); timer->setSingleShot(true); connect(timer, SIGNAL(timeout()), this, SLOT(stoprec())); timer->setSingleShot(true); timer->start(10000); qDebug() << "file: " << outFile.size()<< " timer is singleshot:" << timer->isSingleShot(); ui->checkBox->setChecked(true);}void Widget::stoprec(){ inSignal->stop(); qDebug() << "file: " << outFile.size(); outFile.close(); delete inSignal; ui->checkBox->setChecked(false); //timer->stop();}
// QAudioFormat settings; // Задаем формат settings.setFrequency(8000); // Квантование по времени - 8000 замеров/с settings.setChannels(1); // 1 канал - моно settings.setSampleSize(8); // Глубина кодирования - 16 бит settings.setCodec("audio/pcm"); // Формат settings.setByteOrder(QAudioFormat::LittleEndian); // Порядок байтов settings.setSampleType(QAudioFormat::SignedInt); // Тип данных... audioInput = new QAudioInput(settings); // audioInput->setBufferSize(256); audioInput->start( &buffer); QTimer* timer = new QTimer; qDebug() << "Buffer1: " << buffer.bytesAvailable(); timer->setSingleShot(true); connect(timer, SIGNAL(timeout()), this, SLOT(stopRecording())); timer->start(100);void Widget::stopRecording(){ qDebug() << "2: " << buffer->bytesAvailable(); if(audioInput!=0) if(audioInput->state()==QAudio::ActiveState) audioInput->stop(); qDebug() << "2: " ; //<< buffer->bytesAvailable(); delete audioInput; delete buffer;}
//============= test block QByteArray output_bytes; QAudioInput* audioInput; QAudioFormat settings; QBuffer buffer; // Set up the format, eg. settings.setFrequency(8000); settings.setChannels(1); settings.setSampleSize(16); settings.setCodec("audio/pcm"); settings.setByteOrder(QAudioFormat::LittleEndian); settings.setSampleType(QAudioFormat::UnSignedInt); if (!buffer.isOpen()) buffer.setBuffer(&output_bytes); buffer.open(QIODevice::ReadWrite | QIODevice::Append);// :Truncate); if (!info.isFormatSupported(settings)) { qWarning() << "default format not supported try to use nearest"; this->settings = info.nearestFormat(settings); } audioInput = new QAudioInput(settings, this); audioInput->start( &buffer);