2006-10-09 18:02:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "sound.h"
|
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QVariant>
|
2007-04-19 18:30:20 +00:00
|
|
|
|
2006-10-09 18:02:59 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
class Sound::Private
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
public:
|
|
|
|
Private(const QByteArray &data)
|
|
|
|
: m_data(QVariant(data))
|
|
|
|
, m_type(Sound::Embedded)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
Private(const QString &url)
|
|
|
|
: m_data(QVariant(url))
|
|
|
|
, m_type(Sound::External)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
void init()
|
|
|
|
{
|
|
|
|
m_samplingRate = 44100.0;
|
|
|
|
m_channels = 1;
|
|
|
|
m_bitsPerSample = 8;
|
|
|
|
m_soundEncoding = Sound::Raw;
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
QVariant m_data;
|
|
|
|
Sound::SoundType m_type;
|
|
|
|
double m_samplingRate;
|
|
|
|
int m_channels;
|
|
|
|
int m_bitsPerSample;
|
|
|
|
SoundEncoding m_soundEncoding;
|
|
|
|
};
|
2006-10-09 18:02:59 +00:00
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
Sound::Sound(const QByteArray &data)
|
|
|
|
: d(new Private(data))
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
Sound::Sound(const QString &url)
|
|
|
|
: d(new Private(url))
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound()
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
delete d;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::SoundType Sound::soundType() const
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
return d->m_type;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Sound::url() const
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
return d->m_type == Sound::External ? d->m_data.toString() : QString();
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Sound::data() const
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
return d->m_type == Sound::Embedded ? d->m_data.toByteArray() : QByteArray();
|
2006-10-10 07:17:02 +00:00
|
|
|
}
|
2006-10-09 18:02:59 +00:00
|
|
|
|
|
|
|
double Sound::samplingRate() const
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
return d->m_samplingRate;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
void Sound::setSamplingRate(double samplingRate)
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
d->m_samplingRate = samplingRate;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Sound::channels() const
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
return d->m_channels;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
void Sound::setChannels(int channels)
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
d->m_channels = channels;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Sound::bitsPerSample() const
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
return d->m_bitsPerSample;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
void Sound::setBitsPerSample(int bitsPerSample)
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
d->m_bitsPerSample = bitsPerSample;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::SoundEncoding Sound::soundEncoding() const
|
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
return d->m_soundEncoding;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 08:04:41 +00:00
|
|
|
void Sound::setSoundEncoding(Sound::SoundEncoding soundEncoding)
|
2006-10-09 18:02:59 +00:00
|
|
|
{
|
2006-11-27 08:04:41 +00:00
|
|
|
d->m_soundEncoding = soundEncoding;
|
2006-10-09 18:02:59 +00:00
|
|
|
}
|