1 /* Sound.cc - an object that holds the sound structure
2 * Copyright (C) 2006-2007, Pino Toscano <pino@kde.org>
3 * Copyright (C) 2009, Albert Astals Cid <aacid@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "GooString.h"
26 Sound
*Sound::parseSound(Object
*obj
)
28 // let's try to see if this Object is a Sound, according to the PDF specs
31 // the Object must be a Stream
32 if (obj
->isStream()) {
33 str
= obj
->getStream();
37 // the Stream must have a Dict
38 Dict
*dict
= str
->getDict();
42 // the Dict must have the 'R' key of type num
43 dict
->lookup("R", &tmp
);
45 return new Sound(obj
);
51 Sound::Sound(Object
*obj
, bool readAttrs
)
53 streamObj
= new Object();
54 streamObj
->initNull();
66 Dict
*dict
= streamObj
->getStream()->getDict();
67 dict
->lookup("F", &tmp
);
70 // valid 'F' key -> external file
72 if (getFileSpecNameForPlatform (&tmp
, &obj1
)) {
73 fileName
= obj1
.getString()->copy();
77 // no file specification, then the sound data have to be
78 // extracted from the stream
83 dict
->lookup("R", &tmp
);
85 samplingRate
= tmp
.getNum();
89 dict
->lookup("C", &tmp
);
91 channels
= tmp
.getInt();
95 dict
->lookup("B", &tmp
);
97 bitsPerSample
= tmp
.getInt();
101 dict
->lookup("E", &tmp
);
104 const char *enc
= tmp
.getName();
105 if (strcmp("Raw", enc
) == 0) {
107 } else if (strcmp("Signed", enc
) == 0) {
108 encoding
= soundSigned
;
109 } else if (strcmp("muLaw", enc
) == 0) {
110 encoding
= soundMuLaw
;
111 } else if (strcmp("ALaw", enc
) == 0) {
112 encoding
= soundALaw
;
126 Stream
*Sound::getStream()
128 return streamObj
->getStream();
133 Sound
*newsound
= new Sound(streamObj
, false);
135 newsound
->kind
= kind
;
137 newsound
->fileName
= fileName
->copy();
139 newsound
->samplingRate
= samplingRate
;
140 newsound
->channels
= channels
;
141 newsound
->bitsPerSample
= bitsPerSample
;
142 newsound
->encoding
= encoding
;