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

source code of poppler/qt6/src/poppler-sound.cc