void SoundInput::start(qint32 device)
{
	stop();

//---------------------------------------------------- Soundcard Setup
	m_callbackData.kin=0;                              //Buffer pointer
	m_callbackData.ncall=0;                            //Number of callbacks
	m_callbackData.bzero=false;                        //Flag to request reset of kin
	m_callbackData.monitoring=m_monitoring;

	//### Temporary: hardwired device selection
	QAudioDeviceInfo  DeviceInfo;
	QList<QAudioDeviceInfo> m_InDevices;
	QAudioDeviceInfo  m_InDeviceInfo;
	m_InDevices = DeviceInfo.availableDevices(QAudio::AudioInput);
	inputDevice = m_InDevices.at(0);
	//###
//  qDebug() << "B" << m_InDevices.length() << inputDevice.deviceName();

	const char* pcmCodec = "audio/pcm";
	QAudioFormat audioFormat = inputDevice.preferredFormat();
	audioFormat.setChannelCount(1);
	audioFormat.setCodec(pcmCodec);
	audioFormat.setSampleRate(12000);
	audioFormat.setSampleType(QAudioFormat::SignedInt);
	audioFormat.setSampleSize(16);

//  qDebug() << "C" << audioFormat << audioFormat.isValid();

	if (!audioFormat.isValid()) {
		emit error(tr("Requested audio format is not available."));
		return;
	}

	audioInput = new QAudioInput(inputDevice, audioFormat);
//  qDebug() << "D" << audioInput->error() << QAudio::NoError;
  if (audioInput->error() != QAudio::NoError) {
		emit error(reportAudioError(audioInput->error()));
		return;
	}

	stream = audioInput->start();
//  qDebug() << "E" << stream->errorString();

	m_ntr0 = 99;		     // initial value higher than any expected
	m_nBusy = 0;
	m_intervalTimer.start(100);
	m_ms0 = QDateTime::currentMSecsSinceEpoch();
	m_nsps0 = 0;
}
/* channelCount() API property test. */
void tst_QAudioFormat::checkChannelCount()
{
    // channels is the old name for channelCount, so
    // they should always be equal
    QAudioFormat audioFormat;
    QVERIFY(audioFormat.channelCount() == -1);
    QVERIFY(audioFormat.channelCount() == -1);

    audioFormat.setChannelCount(123);
    QVERIFY(audioFormat.channelCount() == 123);
    QVERIFY(audioFormat.channelCount() == 123);

    audioFormat.setChannelCount(5);
    QVERIFY(audioFormat.channelCount() == 5);
    QVERIFY(audioFormat.channelCount() == 5);
}
Beispiel #3
0
void Airplay :: start()
{
	// read the airplay pipe
	file.setFileName("/tmp/shairport-sync-pipe");
	file.open(QIODevice::ReadOnly);

	// set the audio format
	// https://github.com/mikebrady/shairport-sync/issues/126
	// Playing raw data 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
	QAudioFormat format;
	format.setSampleRate(44100); // rate
	format.setChannelCount(2); // stereo
	format.setCodec("audio/pcm"); // raw
	format.setSampleSize(16); // 16 bit
	format.setByteOrder(QAudioFormat::LittleEndian);
	format.setSampleType(QAudioFormat::SignedInt);

	// check format is supported
	if (!deviceInfo.isFormatSupported(format))
		qWarning() << "Output format not supported";

	// connect signals
	audio = new QAudioOutput(deviceInfo, format, this);
	connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChange(QAudio::State)));

	// start playing
	audio->start(&file);
}
BeatController::BeatController(QAudioDeviceInfo inputDevice, uint16_t recordSize, uint32_t sampleRate, uint16_t m_bandCount, QObject *parent) : QObject(parent)
{
    m_RecordSize = recordSize;
    m_Buffer = new SoundBuffer(recordSize);
    m_Analyser = new BeatAnalyser(m_bandCount,sampleRate,recordSize);
    m_inputDevice = QAudioDeviceInfo(inputDevice);

    m_FFT = new FFT(recordSize);
    m_FFT->setSoundBuffer(m_Buffer);
    m_Analyser->setFFT(m_FFT);

    QAudioFormat audioFormat;
    audioFormat.setSampleRate(sampleRate);
    audioFormat.setChannelCount(1);
    audioFormat.setSampleSize(16);
    audioFormat.setSampleType(QAudioFormat::SignedInt);
    audioFormat.setByteOrder(QAudioFormat::LittleEndian);
    audioFormat.setCodec("audio/pcm");

    //QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());

    if (!m_inputDevice.isFormatSupported(audioFormat)) {
        qWarning() << "Default format not supported - trying to use nearest";
        audioFormat = m_inputDevice.nearestFormat(audioFormat);
    }

    m_audioInput = new QAudioInput(m_inputDevice, audioFormat, this);
    m_ioDevice = m_audioInput->start();
    connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(readAudio()));

}
Beispiel #5
0
int CRecordData::StartRecord(bool bIsSection)
{
    if(true == bIsSection)
    {

    }
    else
    {
        SetNumofRecDatSec(0);

        // 初始化一个buffer储存raw数据
        QBuffer* bufRecord = new QBuffer();
        bufRecord->open( QIODevice::WriteOnly | QIODevice::Truncate );

        SetRecDatSec(m_iNumOfRecDatSec, bufRecord);
        SetNumofRecDatSec(m_iNumOfRecDatSec+1);

        // 设置录音格式
        QAudioFormat format;
        format.setSampleRate(8000);
        format.setChannelCount(1);
        format.setSampleSize(8);
        format.setCodec("audio/pcm");
        format.setByteOrder(QAudioFormat::LittleEndian);
        format.setSampleType(QAudioFormat::UnSignedInt);

        // 设置录音设备
        audioInput = new QAudioInput(format, this);
        audioInput->start(bufRecord);
    }

}
Beispiel #6
0
void AudioReflector::processLocalAudio(unsigned int sampleTime, const QByteArray& samples, const QAudioFormat& format) {
    bool processLocalAudio = true; // Menu::getInstance()->isOptionChecked(MenuOption::AudioSpatialProcessingProcessLocalAudio)
    if (processLocalAudio) {
        const int NUM_CHANNELS_INPUT = 1;
        const int NUM_CHANNELS_OUTPUT = 2;
        const int EXPECTED_SAMPLE_RATE = 24000;
        if (format.channelCount() == NUM_CHANNELS_INPUT && format.sampleRate() == EXPECTED_SAMPLE_RATE) {
            QAudioFormat outputFormat = format;
            outputFormat.setChannelCount(NUM_CHANNELS_OUTPUT);
            QByteArray stereoInputData(samples.size() * NUM_CHANNELS_OUTPUT, 0);
            int numberOfSamples = (samples.size() / sizeof(int16_t));
            int16_t* monoSamples = (int16_t*)samples.data();
            int16_t* stereoSamples = (int16_t*)stereoInputData.data();
            
            for (int i = 0; i < numberOfSamples; i++) {
                stereoSamples[i* NUM_CHANNELS_OUTPUT] = monoSamples[i] * _localAudioAttenuationFactor;
                stereoSamples[(i * NUM_CHANNELS_OUTPUT) + 1] = monoSamples[i] * _localAudioAttenuationFactor;
            }
            _localAudioDelays.clear();
            _localEchoesSuppressed.clear();
            echoAudio(LOCAL_AUDIO, sampleTime, stereoInputData, outputFormat);
            _localEchoesCount = _localAudioDelays.size();
            _localEchoesSuppressedCount = _localEchoesSuppressed.size();
        }
    }
}
void QSpotifyAudioThreadWorker::startStreaming(int channels, int sampleRate)
{
    qDebug() << "QSpotifyAudioThreadWorker::startStreaming";
    if (!m_audioOutput) {
        QAudioFormat af;
        af.setChannelCount(channels);
        af.setCodec("audio/pcm");
        af.setSampleRate(sampleRate);
        af.setSampleSize(16);
        af.setSampleType(QAudioFormat::SignedInt);

        QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
        if (!info.isFormatSupported(af)) {
            QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
            for (int i = 0; i < devices.size(); i++) {
                QAudioDeviceInfo dev = devices[i];
                qWarning() << dev.deviceName();
            }
            QCoreApplication::postEvent(QSpotifySession::instance(), new QEvent(QEvent::Type(StopEventType)));
            return;
        }

        m_audioOutput = new QAudioOutput(af);
        connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), QSpotifySession::instance(), SLOT(audioStateChange(QAudio::State)));
        m_audioOutput->setBufferSize(BUF_SIZE);

        startAudioOutput();
    }
}
Beispiel #8
0
int test_2()
{
    qyvlik::FFmpegStream* ffmpegStream = new qyvlik::FFmpegStream();

    QAudioFormat format;
    // Set up the format, eg.

    format.setSampleRate(44100);
    format.setChannelCount(2);
    format.setCodec("audio/pcm");
    format.setSampleType(QAudioFormat::SignedInt);
    format.setSampleSize(16);
    format.setByteOrder(QAudioFormat::LittleEndian);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(format)) {
        qDebug() << "Raw audio format not supported by backend, cannot play audio.";
        return -1;
    }

    ffmpegStream->setFileName("E:/Test/1.mp3");

    QAudioOutput *audio;
    audio = new QAudioOutput(format);
    audio->start(ffmpegStream);

    qDebug() << "Play Finished~";

}
Beispiel #9
0
void AudioCore::recordAudioSample(int t = 500, bool writeToFile = false)
{
    latestSampleDuration = t;
    writeSampleToFile    = writeToFile;

    sampleAudioBuffer.open(QBuffer::ReadWrite);
    QAudioFormat format;

    // Настраиваем желаемый формат, например:
    format.setSampleRate(AudioCore::SampleRate);
    format.setSampleSize(8 * AudioCore::SampleSize);
    format.setChannelCount(1);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    // ВЫбрать устройство ввода 0:
    QAudioDeviceInfo info(QAudioDeviceInfo::availableDevices(QAudio::AudioInput).at(0));
    qDebug() << "Selected input device =" << info.deviceName();

    if (!info.isFormatSupported(format)) {
       qWarning() << "Default format not supported, trying to use the nearest.";
       format = info.nearestFormat(format);
    }

    audio = new QAudioInput(format);

    // Очень важно, иначе будут шумы и все картинки ужасно некрасивые.
    audio->setVolume(AudioCore::AudioLevel);
    connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));

    QTimer::singleShot(t, this, SLOT(stopRecording()));
    audio->start(&sampleAudioBuffer);
}
FrequencyAnalyzer::FrequencyAnalyzer(QObject *parent) :
    QObject(parent),
    d_ptr(new FrequencyAnalyzerPrivate(this))
{
    Q_D(FrequencyAnalyzer);

    QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();

    qDebug() << "device name: " << info.deviceName() << "\n"
             << "supported frequency:" << info.supportedFrequencies() << "\n"
             << "supported codecs" << info.supportedCodecs() << "\n"
             << "supported sample sizes" << info.supportedSampleSizes() << "\n"
             << "supported sample types" << info.supportedSampleTypes() << "\n";

    QAudioFormat format = info.preferredFormat();
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);
    format.setSampleSize(32);
    //format.setFrequency(d->sampling = 11025);
    //format.setFrequency(d->sampling = 22050);
    format.setFrequency(d->sampling = info.supportedFrequencies().last());
    format.setChannelCount(1);

    if (!info.isFormatSupported(format)) {
        qWarning("Format is unsupported");
        return;
    }

    d->input = new QAudioInput(info, format, this);
    connect(d->input, SIGNAL(stateChanged(QAudio::State)), SLOT(_q_onStateChanged()));
}
void RtpAudioStream::startPlaying()
{
    if (audio_output_) return;

    QAudioFormat format;
    format.setSampleRate(audio_out_rate_);
    format.setSampleSize(sample_bytes_ * 8); // bits
    format.setSampleType(QAudioFormat::SignedInt);
    format.setChannelCount(1);
    format.setCodec("audio/pcm");

    // RTP_STREAM_DEBUG("playing %s %d samples @ %u Hz",
    //                 tempfile_->fileName().toUtf8().constData(),
    //                 (int) tempfile_->size(), audio_out_rate_);

    audio_output_ = new QAudioOutput(format, this);
    audio_output_->setNotifyInterval(65); // ~15 fps
    connect(audio_output_, SIGNAL(stateChanged(QAudio::State)), this, SLOT(outputStateChanged()));
    connect(audio_output_, SIGNAL(notify()), this, SLOT(outputNotify()));
    tempfile_->seek(0);
    audio_output_->start(tempfile_);
    emit startedPlaying();
    // QTBUG-6548 StoppedState is not always emitted on error, force a cleanup
    // in case playback fails immediately.
    if (audio_output_ && audio_output_->state() == QAudio::StoppedState) {
        outputStateChanged();
    }
}
Beispiel #12
0
AudioDecoder::AudioDecoder(bool isPlayback, bool isDelete)
    : m_cout(stdout, QIODevice::WriteOnly)
{
    m_isPlayback = isPlayback;
    m_isDelete = isDelete;

    // Make sure the data we receive is in correct PCM format.
    // Our wav file writer only supports SignedInt sample type.
    QAudioFormat format;
    format.setChannelCount(2);
    format.setSampleSize(16);
    format.setSampleRate(48000);
    format.setCodec("audio/pcm");
    format.setSampleType(QAudioFormat::SignedInt);
    m_decoder.setAudioFormat(format);

    connect(&m_decoder, SIGNAL(bufferReady()), this, SLOT(bufferReady()));
    connect(&m_decoder, SIGNAL(error(QAudioDecoder::Error)), this, SLOT(error(QAudioDecoder::Error)));
    connect(&m_decoder, SIGNAL(stateChanged(QAudioDecoder::State)), this, SLOT(stateChanged(QAudioDecoder::State)));
    connect(&m_decoder, SIGNAL(finished()), this, SLOT(finished()));
    connect(&m_decoder, SIGNAL(positionChanged(qint64)), this, SLOT(updateProgress()));
    connect(&m_decoder, SIGNAL(durationChanged(qint64)), this, SLOT(updateProgress()));

    connect(&m_soundEffect, SIGNAL(statusChanged()), this, SLOT(playbackStatusChanged()));
    connect(&m_soundEffect, SIGNAL(playingChanged()), this, SLOT(playingChanged()));

    m_progress = -1.0;
}
Beispiel #13
0
void MainWindow::on_pushButton_clicked()
{
      QIODevice *QID;
      //QID->open( QIODevice::WriteOnly);
      QBuffer myQB;

     //QID(myQB);
    //cb(128000,64000);
     //dFile.setFileName("../RecordTest.raw");
     microphoneBuffer->open( QIODevice::ReadWrite);
     QAudioFormat format;
     // Set up the desired format, for example:
     format.setSampleRate(16000);
     format.setChannelCount(1);
     format.setSampleSize(16);
     format.setCodec("audio/pcm");
     format.setByteOrder(QAudioFormat::LittleEndian);
     format.setSampleType(QAudioFormat::UnSignedInt);

     QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
     if (!info.isFormatSupported(format))
     {
         qWarning() << "Default format not supported, trying to use the nearest.";
         format = info.nearestFormat(format);
     }

     audio = new QAudioInput(format, this);
     connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State)));

     //QTimer::singleShot(5000, this, SLOT(on_pushButton_2_clicked()));
     isRecording = true;
     audio->start(microphoneBuffer);
}
void xmppClient::slotAudioModeChanged(QIODevice::OpenMode mode)
{
    QXmppCall *call = qobject_cast<QXmppCall*>(sender());
    Q_ASSERT(call);
    QXmppRtpAudioChannel *channel = call->audioChannel();

    // prepare audio format
    QAudioFormat format;
    format.setSampleRate(channel->payloadType().clockrate());
    format.setChannelCount(channel->payloadType().channels());
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    // the size in bytes of the audio buffers to/from sound devices
    // 160 ms seems to be the minimum to work consistently on Linux/Mac/Windows
    const int bufferSize = (format.sampleRate() * format.channelCount() * (format.sampleSize() / 8) * 160) / 1000;

    if (mode & QIODevice::ReadOnly) {
        // initialise audio output
        QAudioOutput *audioOutput = new QAudioOutput(format, this);
        audioOutput->setBufferSize(bufferSize);
        audioOutput->start(channel);
    }

    if (mode & QIODevice::WriteOnly) {
        // initialise audio input
        QAudioInput *audioInput = new QAudioInput(format, this);
        audioInput->setBufferSize(bufferSize);
        audioInput->start(channel);
    }
}
Beispiel #15
0
void InitializeAudio()
{
    m_format.setSampleRate(SampleRate); //set frequency to 44100
    m_format.setChannelCount(1); //set channels to mono
    m_format.setSampleSize(16); //set sample sze to 16 bit
    m_format.setSampleType(QAudioFormat::SignedInt ); //Sample type as usigned integer sample UnSignedInt
    m_format.setByteOrder(QAudioFormat::LittleEndian); //Byte order
    m_format.setCodec("audio/pcm"); //set codec as simple audio/pcm

    QAudioDeviceInfo infoIn(QAudioDeviceInfo::defaultInputDevice());
    if (!infoIn.isFormatSupported(m_format))
    {
        //Default format not supported - trying to use nearest
        m_format = infoIn.nearestFormat(m_format);
    }

    QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice());

    if (!infoOut.isFormatSupported(m_format))
    {
       //Default format not supported - trying to use nearest
        m_format = infoOut.nearestFormat(m_format);
    }

    m_audioInput = new QAudioInput(m_Inputdevice, m_format);
    m_audioOutput = new QAudioOutput(m_Outputdevice, m_format);
}
Beispiel #16
0
void AudioProcessorQt::start() {
	if (!input()) {
		return;
	}

	if (!m_device) {
		m_device = new AudioDevice(this);
	}

	if (!m_audioOutput) {
		QAudioFormat format;
		format.setSampleRate(44100);
		format.setChannelCount(2);
		format.setSampleSize(16);
		format.setCodec("audio/pcm");
		format.setByteOrder(QAudioFormat::LittleEndian);
		format.setSampleType(QAudioFormat::SignedInt);

		m_audioOutput = new QAudioOutput(format, this);
		m_audioOutput->setCategory("game");
	}

	m_device->setInput(input());
	m_device->setFormat(m_audioOutput->format());
	m_audioOutput->setBufferSize(input()->audioBuffers * 4);

	m_audioOutput->start(m_device);
}
Beispiel #17
0
bool Engine::selectFormat()
{
    bool foundSupportedFormat = false;

    if (m_file || QAudioFormat() != m_format) {
        QAudioFormat format = m_format;
        if (m_file)
            // Header is read from the WAV file; just need to check whether
            // it is supported by the audio output device
            format = m_file->fileFormat();
        if (m_audioOutputDevice.isFormatSupported(format)) {
            setFormat(format);
            foundSupportedFormat = true;
        }
    } else {

        QList<int> sampleRatesList;

        if (!m_generateTone)

            sampleRatesList += m_audioOutputDevice.supportedSampleRates();
        sampleRatesList = sampleRatesList.toSet().toList(); // remove duplicates
        qSort(sampleRatesList);
        ENGINE_DEBUG << "Engine::initialize frequenciesList" << sampleRatesList;

        QList<int> channelsList;
        channelsList += m_audioOutputDevice.supportedChannelCounts();
        channelsList = channelsList.toSet().toList();
        qSort(channelsList);
        ENGINE_DEBUG << "Engine::initialize channelsList" << channelsList;

        QAudioFormat format;
        format.setByteOrder(QAudioFormat::LittleEndian);
        format.setCodec("audio/pcm");
        format.setSampleSize(16);
        format.setSampleType(QAudioFormat::SignedInt);
        int sampleRate, channels;
        foreach (sampleRate, sampleRatesList) {
            if (foundSupportedFormat)
                break;
            format.setSampleRate(sampleRate);
            foreach (channels, channelsList) {
                format.setChannelCount(channels);
                const bool outputSupport = m_audioOutputDevice.isFormatSupported(format);
                ENGINE_DEBUG << "Engine::initialize checking " << format
                             << "output" << outputSupport;
                if (outputSupport)
                {
                    foundSupportedFormat = true;
                    break;
                }
            }
        }

        if (!foundSupportedFormat)
            format = QAudioFormat();

        setFormat(format);
    }
Beispiel #18
0
QAudioFormat audioFormat( const int channels, const int sampleRate, AVSampleFormat sampleFormat )
{
    QAudioFormat format;
    format.setChannelCount( channels );
    format.setCodec( "audio/pcm" );
    switch (sampleFormat)
    {
    case AV_SAMPLE_FMT_U8:          ///< unsigned 8 bits
        format.setSampleSize(8);
        format.setSampleType( QAudioFormat::UnSignedInt  );
        break;
    case AV_SAMPLE_FMT_S16:         ///< signed 16 bits
        format.setSampleSize(16);
        format.setSampleType( QAudioFormat::SignedInt  );
        break;

    case AV_SAMPLE_FMT_S32:         ///< signed 32 bits
        format.setSampleSize(32);
        format.setSampleType( QAudioFormat::SignedInt  );
        break;
    case AV_SAMPLE_FMT_FLT:         ///< float
        format.setSampleSize(16);
        format.setSampleType( QAudioFormat::Float  );
        break;
    case AV_SAMPLE_FMT_DBL:         ///< double
        format.setSampleSize(32);
        format.setSampleType( QAudioFormat::Float  );
        break;

    case AV_SAMPLE_FMT_U8P:         ///< unsigned 8 bits: planar
        format.setSampleSize(8);
        format.setSampleType( QAudioFormat::UnSignedInt  );
        break;
    case AV_SAMPLE_FMT_S16P:        ///< signed 16 bits: planar
        format.setSampleSize(16);
        format.setSampleType( QAudioFormat::SignedInt  );
        break;
    case AV_SAMPLE_FMT_S32P:        ///< signed 32 bits: planar
        format.setSampleSize(32);
        format.setSampleType( QAudioFormat::SignedInt  );
        break;
    case AV_SAMPLE_FMT_FLTP:        ///< float: planar
        format.setSampleSize(16);
        format.setSampleType( QAudioFormat::SignedInt  );
        break;
    case AV_SAMPLE_FMT_DBLP:        ///< double, planar
        format.setSampleSize(32);
        format.setSampleType( QAudioFormat::SignedInt  );
        break;
    default:
        qWarning() << "codec format: " << sampleFormat << AV_SAMPLE_FMT_NONE;
        return QAudioFormat();
    }

    format.setSampleRate( sampleRate );
    return format;
}
Beispiel #19
0
QAudioFormat format() {
    QAudioFormat format;
    format.setSampleRate(8000);
    format.setChannelCount(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);
    return format;
}
Beispiel #20
0
void TSoundOutputDeviceImp::play(const TSoundTrackP &st, TINT32 s0, TINT32 s1,
                                 bool loop, bool scrubbing) {
  if (!doSetStreamFormat(st->getFormat())) return;

  MyData *myData = new MyData();

  myData->imp              = shared_from_this();
  myData->totalPacketCount = s1 - s0;
  myData->fileByteCount    = (s1 - s0) * st->getSampleSize();
  myData->entireFileBuffer = new char[myData->fileByteCount];

  memcpy(myData->entireFileBuffer, st->getRawData() + s0 * st->getSampleSize(),
         myData->fileByteCount);

  m_isPlaying       = true;
  myData->isLooping = loop;

  QAudioFormat format;
  QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());

  format.setSampleSize(st->getBitPerSample());
  format.setCodec("audio/pcm");
  format.setChannelCount(st->getChannelCount());
  format.setByteOrder(QAudioFormat::LittleEndian);
  format.setSampleType(st->getFormat().m_signedSample
                           ? QAudioFormat::SignedInt
                           : QAudioFormat::UnSignedInt);
  format.setSampleRate(st->getSampleRate());
  QList<QAudioFormat::Endian> sbos        = info.supportedByteOrders();
  QList<int> sccs                         = info.supportedChannelCounts();
  QList<int> ssrs                         = info.supportedSampleRates();
  QList<QAudioFormat::SampleType> sstypes = info.supportedSampleTypes();
  QList<int> ssss                         = info.supportedSampleSizes();
  QStringList supCodes                    = info.supportedCodecs();
  if (!info.isFormatSupported((format))) {
    format                                 = info.nearestFormat(format);
    int newChannels                        = format.channelCount();
    int newBitsPerSample                   = format.sampleSize();
    int newSampleRate                      = format.sampleRate();
    QAudioFormat::SampleType newSampleType = format.sampleType();
    QAudioFormat::Endian newBo             = format.byteOrder();
  }
  int test = st->getSampleCount() / st->getSampleRate();
  QByteArray *data =
      new QByteArray(myData->entireFileBuffer, myData->fileByteCount);
  QBuffer *newBuffer = new QBuffer;
  newBuffer->setBuffer(data);
  newBuffer->open(QIODevice::ReadOnly);
  newBuffer->seek(0);
  if (m_audioOutput == NULL) {
    m_audioOutput = new QAudioOutput(format, NULL);
  }
  m_audioOutput->start(newBuffer);
  m_audioOutput->setVolume(m_volume);
}
Beispiel #21
0
QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
{
    QAudioFormat nearest;
    if(mode == QAudio::AudioOutput) {
        nearest.setFrequency(44100);
        nearest.setChannelCount(2);
        nearest.setByteOrder(QAudioFormat::LittleEndian);
        nearest.setSampleType(QAudioFormat::SignedInt);
        nearest.setSampleSize(16);
        nearest.setCodec(QLatin1String("audio/pcm"));
    } else {
        nearest.setFrequency(11025);
        nearest.setChannelCount(1);
        nearest.setByteOrder(QAudioFormat::LittleEndian);
        nearest.setSampleType(QAudioFormat::SignedInt);
        nearest.setSampleSize(8);
        nearest.setCodec(QLatin1String("audio/pcm"));
    }
    return nearest;
}
Beispiel #22
0
QAudioFormat AudioHandler::createFormat() {
    QAudioFormat f;

    f.setCodec("audio/pcm");
    f.setChannelCount(2);
    f.setSampleRate(48000);
    f.setSampleSize(16);
    f.setSampleType(QAudioFormat::UnSignedInt);
    f.setByteOrder(QAudioFormat::LittleEndian);

    return f;
}
void MainWindow::PlaySound() {


    //QSound *sound = new QSound("/home/mike/TediumRemedy/sample.wav", this);
    //sound->play();
    //return;

    sourceFile.setFileName("/home/mike/TediumRemedy/sample.wav");
    sourceFile.open(QIODevice::ReadOnly);

    QAudioFormat format;
    // Set up the format, eg.
    format.setSampleRate(44100);
    format.setChannelCount(2);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(format)) {
        qWarning() << "Raw audio format not supported by backend, cannot play audio.";
        return;
    }



    return;


    /*QSound::play(":resources/connected.wav");
    return;
*/
    QList<QAudioDeviceInfo> l = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
    foreach(QAudioDeviceInfo i, l) {
        qDebug() << i.supportedCodecs();
    }



    QTextStream out(stdout);
    out << "START-OUTPUT" << endl;
    QList<QAudioDeviceInfo> outputList = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
    foreach(QAudioDeviceInfo outputInfo, outputList) {
       out << outputInfo.deviceName() << endl;
    }
    out << "END-OUTPUT" << endl;
    return;

    /*QMediaPlayer *p  = new QMediaPlayer(0);
    p->setMedia(QMediaContent(QUrl::fromLocalFile(":/resources/connected.wav")));
    p->play();*/
}
Beispiel #24
0
	QAudioFormat MediaCall::GetAudioReadFormat () const
	{
		const auto& payload = Call_->audioChannel ()->payloadType ();
		QAudioFormat result;
		result.setSampleRate (payload.clockrate ());
		result.setChannelCount (payload.channels ());
		result.setSampleSize (16);
		result.setCodec ("audio/pcm");
		result.setByteOrder (QAudioFormat::LittleEndian);
		result.setSampleType (QAudioFormat::SignedInt);
		return result;
	}
Beispiel #25
0
void VideoItem::updateAudioFormat()
{
    QAudioFormat format;
    format.setSampleSize(16);
    format.setSampleRate(core->getSampleRate());
    format.setChannelCount(2);
    format.setSampleType(QAudioFormat::SignedInt);
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setCodec("audio/pcm");
    // TODO test format
    audio->setFormat(format);
}
QAudioFormat Settings::audioFormat() const
{
    QAudioFormat format;
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setChannelCount(1);
    format.setCodec("audio/pcm");
    format.setSampleRate(d->sampleRate);
    format.setSampleSize(d->sampleSize);
    format.setSampleType(QAudioFormat::SignedInt);

    return d->inputDevice.nearestFormat(format);
}
QAudioFormat MultimediaWidget::getAudioFormat( AVInfo const & aAvInfo ) const
{
    QAudioFormat audioFormat;
    audioFormat.setSampleRate( aAvInfo.getAudioSampleRate() );
    audioFormat.setChannelCount( aAvInfo.getAudioChannel() );
    audioFormat.setSampleSize( aAvInfo.getAudioBitsPerSample() );
    audioFormat.setCodec( "audio/pcm" );
    audioFormat.setByteOrder(QAudioFormat::LittleEndian);
    audioFormat.setSampleType(QAudioFormat::UnSignedInt);

    return audioFormat;
}
void AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings)
{
    QAudioFormat fmt = m_session->format();

    if (settings.encodingMode() == QMultimedia::ConstantQualityEncoding) {
        if (settings.quality() == QMultimedia::LowQuality) {
            fmt.setSampleSize(8);
            fmt.setChannelCount(1);
            fmt.setSampleRate(8000);
            fmt.setSampleType(QAudioFormat::UnSignedInt);

        } else if (settings.quality() == QMultimedia::NormalQuality) {
            fmt.setSampleSize(16);
            fmt.setChannelCount(1);
            fmt.setSampleRate(22050);
            fmt.setSampleType(QAudioFormat::SignedInt);

        } else {
            fmt.setSampleSize(16);
            fmt.setChannelCount(1);
            fmt.setSampleRate(44100);
            fmt.setSampleType(QAudioFormat::SignedInt);
        }

    } else {
        fmt.setChannelCount(settings.channelCount());
        fmt.setSampleRate(settings.sampleRate());
        if (settings.sampleRate() == 8000 && settings.bitRate() == 8000) {
            fmt.setSampleType(QAudioFormat::UnSignedInt);
            fmt.setSampleSize(8);
        } else {
            fmt.setSampleSize(16);
            fmt.setSampleType(QAudioFormat::SignedInt);
        }
    }
    fmt.setCodec("audio/pcm");

    m_session->setFormat(fmt);
    m_settings = settings;
}
QAudioFormat QAlsaAudioDeviceInfo::preferredFormat() const
{
    QAudioFormat nearest;
    if(mode == QAudio::AudioOutput) {
        nearest.setSampleRate(44100);
        nearest.setChannelCount(2);
        nearest.setByteOrder(QAudioFormat::LittleEndian);
        nearest.setSampleType(QAudioFormat::SignedInt);
        nearest.setSampleSize(16);
        nearest.setCodec(QLatin1String("audio/pcm"));
    } else {
        nearest.setSampleRate(8000);
        nearest.setChannelCount(1);
        nearest.setSampleType(QAudioFormat::UnSignedInt);
        nearest.setSampleSize(8);
        nearest.setCodec(QLatin1String("audio/pcm"));
        if(!testSettings(nearest)) {
            nearest.setChannelCount(2);
            nearest.setSampleSize(16);
            nearest.setSampleType(QAudioFormat::SignedInt);
        }
    }
    return nearest;
}
Beispiel #30
0
QAudioFormat MediaCall::GetAudioFormat ()
{
    const QXmppJinglePayloadType& payload =
        Call_->audioChannel ()->payloadType ();
    QAudioFormat result;
#if QT_VERSION >= 0x040700
    result.setSampleRate (payload.clockrate ());
    result.setChannelCount (payload.channels ());
#endif
    result.setSampleSize (16);
    result.setCodec ("audio/pcm");
    result.setByteOrder (QAudioFormat::LittleEndian);
    result.setSampleType (QAudioFormat::SignedInt);
    return result;
}