Debian Codegraph @

plugins/wav/encoderwav.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 "encoderwav.h"
27 #include <QList>
28
29 extern "C" {
30 AUDIOCDPLUGINS_EXPORT void create_audiocd_encoders(KIO::WorkerBase *worker, QList<AudioCDEncoder *> &encoders)
31 {
32 encoders.append(new EncoderWav(worker));
33 encoders.append(new EncoderCda(worker));
34 }
35 }
36
37 unsigned long EncoderWav::size(long time_secs) const
38 {
39 return (EncoderCda::size(time_secs) + 44);
40 }
41
42 const char *EncoderWav::mimeType() const
43 {
44 return "audio/x-wav";
45 }
46
47 long EncoderWav::readInit(long byteCount)
48 {
49 static unsigned char riffHeader[] = {
50 0x52, 0x49, 0x46, 0x46, // 0 "AIFF"
51 0x00, 0x00, 0x00, 0x00, // 4 wavSize
52 0x57, 0x41, 0x56, 0x45, // 8 "WAVE"
53 0x66, 0x6d, 0x74, 0x20, // 12 "fmt "
54 0x10, 0x00, 0x00, 0x00, // 16
55 0x01, 0x00, 0x02, 0x00, // 20
56 0x44, 0xac, 0x00, 0x00, // 24
57 0x10, 0xb1, 0x02, 0x00, // 28
58 0x04, 0x00, 0x10, 0x00, // 32
59 0x64, 0x61, 0x74, 0x61, // 36 "data"
60 0x00, 0x00, 0x00, 0x00 // 40 byteCount
61 };
62
63 qint32 wavSize(byteCount + 44 - 8);
64
65 riffHeader[4] = (wavSize >> 0) & 0xff;
66 riffHeader[5] = (wavSize >> 8) & 0xff;
67 riffHeader[6] = (wavSize >> 16) & 0xff;
68 riffHeader[7] = (wavSize >> 24) & 0xff;
69
70 riffHeader[40] = (byteCount >> 0) & 0xff;
71 riffHeader[41] = (byteCount >> 8) & 0xff;
72 riffHeader[42] = (byteCount >> 16) & 0xff;
73 riffHeader[43] = (byteCount >> 24) & 0xff;
74
75 QByteArray output;
76 output = QByteArray::fromRawData((char *)riffHeader, 44);
77 ioWorker->data(output);
78 output.clear();
79 return 44;
80 }