File indexing completed on 2024-04-28 04:49:54

0001 /*
0002     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 
0007 #ifndef K3BWAVEFILEWRITER_H
0008 #define K3BWAVEFILEWRITER_H
0009 
0010 #include "k3b_export.h"
0011 
0012 #include <QDataStream>
0013 #include <QFile>
0014 #include <QString>
0015 
0016 namespace K3b {
0017     /**
0018      * @author Sebastian Trueg
0019      * Creates wave files from 16bit stereo little or big endian
0020      * sound samples
0021      */
0022     class LIBK3B_EXPORT WaveFileWriter
0023     {
0024     public:
0025 
0026         enum Endianess { BigEndian, LittleEndian };
0027 
0028         WaveFileWriter();
0029         ~WaveFileWriter();
0030 
0031         /**
0032          * open a new wave file.
0033          * closes any opened file.
0034          */
0035         bool open( const QString& filename );
0036 
0037         bool isOpen();
0038         const QString& filename() const;
0039 
0040         /**
0041          * closes the file.
0042          * Length of the wave file will be written into the header.
0043          * If no data has been written to the file except the header
0044          * it will be removed.
0045          */
0046         void close();
0047 
0048         /**
0049          * write 16bit samples to the file.
0050          * @param e the endianess of the data
0051          *          (it will be swapped to little endian byte order if necessary)
0052          */
0053         void write( const char* data, int len, Endianess e = BigEndian );
0054 
0055         /**
0056          * returns a filedescriptor with the already opened file
0057          * or -1 if isOpen() is false
0058          */
0059         int fd() const;
0060 
0061     private:
0062         void writeEmptyHeader();
0063         void updateHeader();
0064         void padTo2352();
0065 
0066         QFile m_outputFile;
0067         QDataStream m_outputStream;
0068         QString m_filename;
0069     };
0070 }
0071 
0072 #endif