1 /* poppler-sound.cc: qt interface to poppler
2 * Copyright (C) 2006-2007, Pino Toscano <pino@kde.org>
3 * Copyright (C) 2008, Albert Astals Cid <aacid@kde.org>
4 *
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)
8 * any later version.
9 *
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.
14 *
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.
18 */
19
20 #include "poppler-qt5.h"
21
22 #include "Object.h"
23 #include "Stream.h"
24 #include "Sound.h"
25
26 namespace Poppler
27 {
28
29 class SoundData
30 {
31 public:
SoundData()32 SoundData()
33 : m_soundObj( 0 )
34 {
35 }
36
~SoundData()37 ~SoundData()
38 {
39 delete m_soundObj;
40 }
41
42 SoundObject::SoundType m_type;
43 Sound *m_soundObj;
44 };
45
SoundObject(Sound * popplersound)46 SoundObject::SoundObject(Sound *popplersound)
47 {
48 m_soundData = new SoundData();
49 switch ( popplersound->getSoundKind() )
50 {
51 case soundEmbedded:
52 m_soundData->m_type = SoundObject::Embedded;
53 break;
54 case soundExternal:
55 default:
56 m_soundData->m_type = SoundObject::External;
57 break;
58 }
59
60 m_soundData->m_soundObj = popplersound->copy();
61 }
62
~SoundObject()63 SoundObject::~SoundObject()
64 {
65 delete m_soundData;
66 }
67
soundType() const68 SoundObject::SoundType SoundObject::soundType() const
69 {
70 return m_soundData->m_type;
71 }
72
url() const73 QString SoundObject::url() const
74 {
75 if ( m_soundData->m_type != SoundObject::External )
76 return QString();
77
78 GooString * goo = m_soundData->m_soundObj->getFileName();
79 return goo ? QString( goo->getCString() ) : QString();
80 }
81
data() const82 QByteArray SoundObject::data() const
83 {
84 if ( m_soundData->m_type != SoundObject::Embedded )
85 return QByteArray();
86
87 Stream *stream = m_soundData->m_soundObj->getStream();
88 stream->reset();
89 int dataLen = 0;
90 QByteArray fileArray;
91 int i;
92 while ( (i = stream->getChar()) != EOF) {
93 fileArray[dataLen] = (char)i;
94 ++dataLen;
95 }
96 fileArray.resize(dataLen);
97
98 return fileArray;
99 }
100
samplingRate() const101 double SoundObject::samplingRate() const
102 {
103 return m_soundData->m_soundObj->getSamplingRate();
104 }
105
channels() const106 int SoundObject::channels() const
107 {
108 return m_soundData->m_soundObj->getChannels();
109 }
110
bitsPerSample() const111 int SoundObject::bitsPerSample() const
112 {
113 return m_soundData->m_soundObj->getBitsPerSample();
114 }
115
soundEncoding() const116 SoundObject::SoundEncoding SoundObject::soundEncoding() const
117 {
118 switch ( m_soundData->m_soundObj->getEncoding() )
119 {
120 case soundRaw:
121 return SoundObject::Raw;
122 case soundSigned:
123 return SoundObject::Signed;
124 case soundMuLaw:
125 return SoundObject::muLaw;
126 case soundALaw:
127 return SoundObject::ALaw;
128 }
129 return SoundObject::Raw;
130 }
131
132 }
133