File indexing completed on 2024-04-21 04:48:16

0001 /* AUDEX CDDA EXTRACTOR
0002  * SPDX-FileCopyrightText: Copyright (C) 2007 Marco Nelles
0003  * <https://userbase.kde.org/Audex>
0004  *
0005  * SPDX-License-Identifier: GPL-3.0-or-later
0006  */
0007 
0008 #ifndef WAVEFILEWRITER_HEADER
0009 #define WAVEFILEWRITER_HEADER
0010 
0011 #include <QDataStream>
0012 #include <QFile>
0013 #include <QString>
0014 
0015 #include <KLocalizedString>
0016 
0017 class WaveFileWriter : public QObject
0018 {
0019     Q_OBJECT
0020 public:
0021     WaveFileWriter();
0022     ~WaveFileWriter() override;
0023 
0024     enum Endianess { BigEndian, LittleEndian };
0025 
0026     /**
0027      * open a new wave file.
0028      * closes any opened file.
0029      */
0030     bool open(const QString &filename);
0031     bool isOpen();
0032     QString filename() const;
0033 
0034     void setEndianess(const Endianess e);
0035     Endianess endianess();
0036 
0037     /**
0038      * closes the file.
0039      * Length of the wave file will be written into the header.
0040      * If no data has been written to the file except the header
0041      * it will be removed.
0042      */
0043     void close();
0044 
0045 public Q_SLOTS:
0046     /**
0047      * write 16bit samples to the file.
0048      */
0049     void write(const QByteArray &data);
0050 
0051 Q_SIGNALS:
0052     void error(const QString &errorstr);
0053 
0054 private:
0055     void p_write_empty_header();
0056     void p_update_header();
0057 
0058     Endianess p_endianess;
0059 
0060     QFile p_output_file;
0061     QDataStream p_output_stream;
0062     QString p_filename;
0063 
0064     long p_data_written;
0065 };
0066 
0067 #endif