Debian Codegraph @

plugins/wav/encodercda.cpp

raw
1 /*
2 Copyright (C) 2000 Rik Hemsley (rikkus) <[email protected]>
3 Copyright (C) 2000, 2001, 2002 Michael Matz <[email protected]>
4 Copyright (C) 2001 Carsten Duvenhorst <[email protected]>
5 Copyright (C) 2001 Adrian Schroeter <[email protected]>
6 Copyright (C) 2003 Richard Lärkäng <[email protected]>
7 Copyright (C) 2003 Scott Wheeler <[email protected]>
8 Copyright (C) 2004, 2005 Benjamin Meyer <ben at meyerhome dot net>
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 USA.
24 */
25
26 #include "encodercda.h"
27
28 unsigned long EncoderCda::size(long time_secs) const
29 {
30 // return (time_secs * (44100 * 2 * 16))/8;
31 return (time_secs) * 176400;
32 }
33
34 const char *EncoderCda::mimeType() const
35 {
36 return "audio/x-cda";
37 }
38
39 // Remove this by calculating CD_FRAMESIZE_RAW from the frames
40 extern "C" {
41 // cdda_interface.h in cdparanoia 10.2 has a member called 'private' which the
42 // C++ compiler doesn't like we will thus use a generated local copy which
43 // renames that member.
44 #include "cdda_interface.hpp"
45 }
46
47 inline qint16 swap16(qint16 i)
48 {
49 return (((i >> 8) & 0xFF) | ((i << 8) & 0xFF00));
50 }
51
52 long EncoderCda::read(qint16 *buf, int frames)
53 {
54 QByteArray output;
55 qint16 i16 = 1;
56 /* WAV is defined to be little endian, so we need to swap it
57 on big endian platforms. */
58 if (((char *)&i16)[0] == 0)
59 for (int i = 0; i < 2 * frames; i++)
60 buf[i] = swap16(buf[i]);
61 char *cbuf = reinterpret_cast<char *>(buf);
62 output = QByteArray::fromRawData(cbuf, CD_FRAMESIZE_RAW);
63 ioWorker->data(output);
64 output.clear();
65 return CD_FRAMESIZE_RAW;
66 }