~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/qt4/src/poppler-sound.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-qt4.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:
 
32
        SoundData()
 
33
          : m_soundObj( 0 )
 
34
        {
 
35
        }
 
36
 
 
37
        ~SoundData()
 
38
        {
 
39
                delete m_soundObj;
 
40
        }
 
41
 
 
42
        SoundObject::SoundType m_type;
 
43
        Sound *m_soundObj;
 
44
};
 
45
 
 
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
 
 
63
SoundObject::~SoundObject()
 
64
{
 
65
        delete m_soundData;
 
66
}
 
67
 
 
68
SoundObject::SoundType SoundObject::soundType() const
 
69
{
 
70
        return m_soundData->m_type;
 
71
}
 
72
 
 
73
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
 
 
82
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
 
 
101
double SoundObject::samplingRate() const
 
102
{
 
103
        return m_soundData->m_soundObj->getSamplingRate();
 
104
}
 
105
 
 
106
int SoundObject::channels() const
 
107
{
 
108
        return m_soundData->m_soundObj->getChannels();
 
109
}
 
110
 
 
111
int SoundObject::bitsPerSample() const
 
112
{
 
113
        return m_soundData->m_soundObj->getBitsPerSample();
 
114
}
 
115
 
 
116
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
}