Ejemplo n.º 1
0
QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
{
    if (isFormatSupported(settings))
        return settings;

    QAudioFormat nearest = settings;

    nearest.setCodec(QLatin1String("audio/pcm"));

    if (nearest.sampleType() == QAudioFormat::Unknown) {
        QAudioFormat preferred = preferredFormat();
        nearest.setSampleType(preferred.sampleType());
    }

    QMap<int,int> testFrequencies;
    QList<int> frequenciesAvailable = supportedFrequencies();
    QMap<int,int> testSampleSizes;
    QList<int> sampleSizesAvailable = supportedSampleSizes();

    // Get sorted sampleSizes (equal to and ascending values only)
    if (sampleSizesAvailable.contains(settings.sampleSize()))
        testSampleSizes.insert(0,settings.sampleSize());
    sampleSizesAvailable.removeAll(settings.sampleSize());
    foreach (int size, sampleSizesAvailable) {
        int larger  = (size > settings.sampleSize()) ? size : settings.sampleSize();
        int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size;
        if (size >= settings.sampleSize()) {
            int diff = larger - smaller;
            testSampleSizes.insert(diff, size);
        }
    }
Ejemplo n.º 2
0
bool ViAudioFormat::isValid(bool includingCodec) const
{
	ViFormatMap sizes = supportedSampleSizes();
	if(!sizes.contains(mSampleSize))
	{
		return false;
	}
	ViFormatMap rates = supportedSampleRates();
	if(!rates.contains(mSampleRate))
	{
		return false;
	}
	ViFormatMap types = supportedSampleTypes();
	if(!types.contains(mSampleType))
	{
		return false;
	}
	ViFormatMap endianness = supportedEndianness();
	if(!endianness.contains(mByteOrder))
	{
		return false;
	}
	ViFormatMap channels = supportedChannels();
	if(!channels.contains(mChannelCount))
	{
		return false;
	}
	if(includingCodec && !hasCodec())
	{
		return false;
	}
	return true;
}
Ejemplo n.º 3
0
ViAudioFormat ViAudioFormat::defaultFormat()
{
	ViAudioFormat format;
	format.setSampleSize(supportedSampleSizes().defaultValue());
	format.setSampleRate(supportedSampleRates().defaultValue());
	format.setSampleType(ViAudioFormat::SampleType(supportedSampleTypes().defaultValue()));
	format.setChannelCount(supportedChannels().defaultValue());
	format.setBitrate(ViAudioBitrate(ViAudioBitrate::Mode(supportedBitrateModes().defaultValue()), supportedBitrates().defaultValue()));
	format.setByteOrder(ViAudioFormat::Endian(supportedEndianness().defaultValue()));
	format.setQuality(ViAudioFormat::Quality(supportedQualities().defaultValue()));
	format.setCodec(ViAudioManager::codec("WAVE"));
	return format;
}
Ejemplo n.º 4
0
/*!
    Returns the closest QAudioFormat to the supplied \a settings that the system supports.

    These settings are provided by the platform/audio plugin being used.

    They are also dependent on the \l {QAudio}::Mode being used.
*/
QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
{
    if (isFormatSupported(settings))
        return settings;

    QAudioFormat nearest = settings;

    QList<QString> testCodecs = supportedCodecs();
    QList<int> testChannels = supportedChannelCounts();
    QList<QAudioFormat::Endian> testByteOrders = supportedByteOrders();
    QList<QAudioFormat::SampleType> testSampleTypes;
    QList<QAudioFormat::SampleType> sampleTypesAvailable = supportedSampleTypes();
    QMap<int,int> testSampleRates;
    QList<int> sampleRatesAvailable = supportedSampleRates();
    QMap<int,int> testSampleSizes;
    QList<int> sampleSizesAvailable = supportedSampleSizes();

    // Get sorted lists for checking
    if (testCodecs.contains(settings.codec())) {
        testCodecs.removeAll(settings.codec());
        testCodecs.insert(0, settings.codec());
    }
    testChannels.removeAll(settings.channelCount());
    testChannels.insert(0, settings.channelCount());
    testByteOrders.removeAll(settings.byteOrder());
    testByteOrders.insert(0, settings.byteOrder());

    if (sampleTypesAvailable.contains(settings.sampleType()))
        testSampleTypes.append(settings.sampleType());
    if (sampleTypesAvailable.contains(QAudioFormat::SignedInt))
        testSampleTypes.append(QAudioFormat::SignedInt);
    if (sampleTypesAvailable.contains(QAudioFormat::UnSignedInt))
        testSampleTypes.append(QAudioFormat::UnSignedInt);
    if (sampleTypesAvailable.contains(QAudioFormat::Float))
        testSampleTypes.append(QAudioFormat::Float);

    if (sampleSizesAvailable.contains(settings.sampleSize()))
        testSampleSizes.insert(0,settings.sampleSize());
    sampleSizesAvailable.removeAll(settings.sampleSize());
    foreach (int size, sampleSizesAvailable) {
        int larger  = (size > settings.sampleSize()) ? size : settings.sampleSize();
        int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size;
        bool isMultiple = ( 0 == (larger % smaller));
        int diff = larger - smaller;
        testSampleSizes.insert((isMultiple ? diff : diff+100000), size);
    }