File indexing completed on 2024-05-26 04:52:53

0001 /*
0002   Copyright (C) 2000 Rik Hemsley (rikkus) <rik@kde.org>
0003   Copyright (C) 2000, 2001, 2002 Michael Matz <matz@kde.org>
0004   Copyright (C) 2001 Carsten Duvenhorst <duvenhorst@m2.uni-hannover.de>
0005   Copyright (C) 2001 Adrian Schroeter <adrian@suse.de>
0006   Copyright (C) 2003 Richard Lärkäng <richard@goteborg.utfors.se>
0007   Copyright (C) 2003 Scott Wheeler <wheeler@kde.org>
0008   Copyright (C) 2004, 2005 Benjamin Meyer <ben at meyerhome dot net>
0009 
0010   This program is free software; you can redistribute it and/or modify
0011   it under the terms of the GNU General Public License as published by
0012   the Free Software Foundation; either version 2 of the License, or
0013   (at your option) any later version.
0014 
0015   This program is distributed in the hope that it will be useful,
0016   but WITHOUT ANY WARRANTY; without even the implied warranty of
0017   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0018   GNU General Public License for more details.
0019 
0020   You should have received a copy of the GNU General Public License
0021   along with this program; if not, write to the Free Software
0022   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
0023   USA.
0024 */
0025 
0026 #include "encodercda.h"
0027 
0028 unsigned long EncoderCda::size(long time_secs) const {
0029     // return (time_secs *   (44100 * 2 * 16))/8;
0030     return (time_secs)*176400;
0031 }
0032 
0033 const char *EncoderCda::mimeType() const
0034 {
0035     return "audio/x-cda";
0036 }
0037 
0038 // Remove this by calculating CD_FRAMESIZE_RAW from the frames
0039 extern "C" {
0040 // cdda_interface.h in cdparanoia 10.2 has a member called 'private' which the
0041 // C++ compiler doesn't like we will thus use a generated local copy which
0042 // renames that member.
0043 #include "cdda_interface.hpp"
0044 }
0045 
0046 inline qint16 swap16(qint16 i)
0047 {
0048     return (((i >> 8) & 0xFF) | ((i << 8) & 0xFF00));
0049 }
0050 
0051 long EncoderCda::read(qint16 *buf, int frames)
0052 {
0053     QByteArray output;
0054     qint16 i16 = 1;
0055     /* WAV is defined to be little endian, so we need to swap it
0056        on big endian platforms.  */
0057     if (((char *)&i16)[0] == 0)
0058         for (int i = 0; i < 2 * frames; i++)
0059             buf[i] = swap16(buf[i]);
0060     char *cbuf = reinterpret_cast<char *>(buf);
0061     output = QByteArray::fromRawData(cbuf, CD_FRAMESIZE_RAW);
0062     ioWorker->data(output);
0063     output.clear();
0064     return CD_FRAMESIZE_RAW;
0065 }