21 #include <audiofile.h> 25 #include <KLocalizedString> 41 :
Kwave::
Decoder(), m_source(Q_NULLPTR), m_src_adapter(Q_NULLPTR)
45 i18n(
"NeXT, Sun Audio"),
50 i18n(
"Amiga IFF/8SVX Sound File Format"),
53 i18n(
"Compressed Audio Interchange Format"),
56 i18n(
"Audio Interchange Format"),
59 i18n(
"Audio Visual Research File Format"),
62 i18n(
"Core Audio File Format"),
65 i18n(
"Berkeley, IRCAM, Carl Sound Format"),
68 i18n(
"NIST SPHERE Audio File Format"),
71 i18n(
"Sample Vision Format"),
74 i18n(
"Creative Voice"),
96 if (
m_source) qWarning(
"AudiofileDecoder::open(), already open !");
99 if (!src.open(QIODevice::ReadOnly)) {
100 qWarning(
"AudiofileDecoder::open(), failed to open source !");
118 case AF_BAD_NOT_IMPLEMENTED:
119 reason = i18n(
"Format or function is not implemented");
122 reason = i18n(
"Out of memory");
125 reason = i18n(
"File header is damaged");
127 case AF_BAD_CODEC_TYPE:
128 reason = i18n(
"Invalid codec type");
131 reason = i18n(
"Opening the file failed");
134 reason = i18n(
"Read access failed");
137 reason = i18n(
"Invalid sample format");
143 QString text= i18n(
"An error occurred while opening the "\
144 "file:\n'%1'", reason);
150 AFframecount length = afGetFrameCount(fh, AF_DEFAULT_TRACK);
151 unsigned int tracks = qMax(afGetVirtualChannels(fh, AF_DEFAULT_TRACK), 0);
152 unsigned int bits = 0;
154 int af_sample_format;
155 afGetVirtualSampleFormat(fh, AF_DEFAULT_TRACK, &af_sample_format,
156 reinterpret_cast<int *>(&bits));
158 switch (af_sample_format)
160 case AF_SAMPFMT_TWOSCOMP:
163 case AF_SAMPFMT_UNSIGNED:
166 case AF_SAMPFMT_FLOAT:
169 case AF_SAMPFMT_DOUBLE:
178 rate = afGetRate(fh, AF_DEFAULT_TRACK);
180 qWarning(
"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"\
181 "WARNING: file has no sample rate!\n"\
182 " => using 8000 samples/sec as fallback\n"\
183 "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
190 if (static_cast<signed int>(bits) < 0) bits = 0;
192 int af_compression = afGetCompression(fh, AF_DEFAULT_TRACK);
205 qDebug(
"-------------------------");
207 qDebug(
"compression = %d", af_compression);
208 qDebug(
"channels = %d", info.
tracks());
209 qDebug(
"rate = %0.0f", info.
rate());
210 qDebug(
"bits/sample = %d", info.
bits());
211 qDebug(
"length = %lu samples",
212 static_cast<unsigned long int>(info.
length()));
213 qDebug(
"format = %d (%s)", af_sample_format,
214 DBG(sample_format_name));
215 qDebug(
"-------------------------");
218 #if Q_BYTE_ORDER == Q_BIG_ENDIAN 219 afSetVirtualByteOrder(fh, AF_DEFAULT_TRACK, AF_BYTEORDER_BIGENDIAN);
221 afSetVirtualByteOrder(fh, AF_DEFAULT_TRACK, AF_BYTEORDER_LITTLEENDIAN);
223 afSetVirtualSampleFormat(fh, AF_DEFAULT_TRACK,
240 if (!fh)
return false;
243 afGetVirtualFrameSize(fh, AF_DEFAULT_TRACK, 1));
246 const unsigned int buffer_frames = (8 * 1024);
250 if (!buffer)
return false;
256 unsigned int frames = buffer_frames;
258 int buffer_used = afReadFrames(fh,
259 AF_DEFAULT_TRACK, reinterpret_cast<char *>(buffer), frames);
262 if (buffer_used <= 0)
break;
267 unsigned int count = buffer_used;
269 for (
unsigned int track = 0; track < tracks; track++) {
279 *(dst[track]) << static_cast<sample_t>(s);
289 if (buffer) free(buffer);
static Kwave::Compression::Type fromAudiofile(int af_compression)
virtual Kwave::Decoder * instance() Q_DECL_OVERRIDE
QString description(IDX type, bool localized) const
virtual void close() Q_DECL_OVERRIDE
virtual void open(Kwave::VirtualAudioFile *x, AFfilesetup setup)
void set(FileProperty key, const QVariant &value)
void setRate(double rate)
virtual void addMimeType(const char *name, const QString &description, const char *patterns)
static int error(QWidget *widget, QString message, QString caption=QString())
sample_index_t length() const
void setLength(sample_index_t length)
void setTracks(unsigned int tracks)
virtual bool decode(QWidget *widget, Kwave::MultiWriter &dst) Q_DECL_OVERRIDE
virtual Kwave::MetaDataList & metaData()
virtual ~AudiofileDecoder() Q_DECL_OVERRIDE
unsigned int tracks() const
void setBits(unsigned int bits)
Kwave::VirtualAudioFile * m_src_adapter
#define SAMPLE_STORAGE_BITS
unsigned int bits() const
virtual bool open(QWidget *widget, QIODevice &source) Q_DECL_OVERRIDE