[poppler] poppler/poppler: Sound.cc,1.2,1.3 Sound.h,1.1,1.2
Albert Astals Cid
aacid at kemper.freedesktop.org
Wed Jan 17 12:06:32 PST 2007
Update of /cvs/poppler/poppler/poppler
In directory kemper:/tmp/cvs-serv20800/poppler
Modified Files:
Sound.cc Sound.h
Log Message:
* poppler/Sound.h:
* poppler/Sound.cc:
* qt4/src/poppler-sound.cc: Move most of the sound reading code
into the Sound class, so frontends can use it easily.
Patch by Pino Toscano <pino at kde.org>.
Index: Sound.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Sound.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Sound.cc 6 Jan 2007 21:53:08 -0000 1.2
+++ Sound.cc 17 Jan 2007 20:06:30 -0000 1.3
@@ -1,5 +1,5 @@
/* Sound.cc - an object that holds the sound structure
- * Copyright (C) 2006, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2006-2007, Pino Toscano <pino at kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <string.h>
#include "GooString.h"
#include "Object.h"
#include "Sound.h"
#include "Stream.h"
+#include "Link.h"
Sound *Sound::parseSound(Object *obj)
{
@@ -47,15 +47,73 @@
}
}
-Sound::Sound(Object *obj)
+Sound::Sound(Object *obj, bool readAttrs)
{
streamObj = new Object();
streamObj->initNull();
obj->copy(streamObj);
+
+ fileName = NULL;
+ samplingRate = 0.0;
+ channels = 1;
+ bitsPerSample = 8;
+ encoding = soundRaw;
+
+ if (readAttrs)
+ {
+ Object tmp;
+ Dict *dict = streamObj->getStream()->getDict();
+ dict->lookup("F", &tmp);
+ if (!tmp.isNull()) {
+ // valid 'F' key -> external file
+ kind = soundExternal;
+ fileName = LinkAction::getFileSpecName(&tmp);
+ } else {
+ // no file specification, then the sound data have to be
+ // extracted from the stream
+ kind = soundEmbedded;
+ }
+ tmp.free();
+ // sampling rate
+ dict->lookup("R", &tmp);
+ if (tmp.isNum()) {
+ samplingRate = tmp.getNum();
+ }
+ tmp.free();
+ // sound channels
+ dict->lookup("C", &tmp);
+ if (tmp.isInt()) {
+ channels = tmp.getInt();
+ }
+ tmp.free();
+ // bits per sample
+ dict->lookup("B", &tmp);
+ if (tmp.isInt()) {
+ bitsPerSample = tmp.getInt();
+ }
+ tmp.free();
+ // encoding format
+ dict->lookup("E", &tmp);
+ if (tmp.isName())
+ {
+ const char *enc = tmp.getName();
+ if (strcmp("Raw", enc) == 0) {
+ encoding = soundRaw;
+ } else if (strcmp("Signed", enc) == 0) {
+ encoding = soundSigned;
+ } else if (strcmp("muLaw", enc) == 0) {
+ encoding = soundMuLaw;
+ } else if (strcmp("ALaw", enc) == 0) {
+ encoding = soundALaw;
+ }
+ }
+ tmp.free();
+ }
}
Sound::~Sound()
{
+ delete fileName;
streamObj->free();
delete streamObj;
}
@@ -64,3 +122,19 @@
{
return streamObj->getStream();
}
+
+Sound *Sound::copy()
+{
+ Sound *newsound = new Sound(streamObj, false);
+
+ newsound->kind = kind;
+ if (fileName) {
+ newsound->fileName = fileName->copy();
+ }
+ newsound->samplingRate = samplingRate;
+ newsound->channels = channels;
+ newsound->bitsPerSample = bitsPerSample;
+ newsound->encoding = encoding;
+
+ return newsound;
+}
Index: Sound.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/Sound.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Sound.h 8 Oct 2006 20:38:47 -0000 1.1
+++ Sound.h 17 Jan 2007 20:06:30 -0000 1.2
@@ -1,5 +1,5 @@
/* Sound.h - an object that holds the sound structure
- * Copyright (C) 2006, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2006-2007, Pino Toscano <pino at kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,11 +19,24 @@
#ifndef Sound_H
#define Sound_H
+class GooString;
class Object;
class Stream;
//------------------------------------------------------------------------
+enum SoundKind {
+ soundEmbedded, // embedded sound
+ soundExternal // external sound
+};
+
+enum SoundEncoding {
+ soundRaw, // raw encoding
+ soundSigned, // twos-complement values
+ soundMuLaw, // mu-law-encoded samples
+ soundALaw // A-law-encoded samples
+};
+
class Sound
{
public:
@@ -36,11 +49,26 @@
Object *getObject() { return streamObj; }
Stream *getStream();
+ SoundKind getSoundKind() { return kind; }
+ GooString *getFileName() { return fileName; }
+ double getSamplingRate() { return samplingRate; }
+ int getChannels() { return channels; }
+ int getBitsPerSample() { return bitsPerSample; }
+ SoundEncoding getEncoding() { return encoding; }
+
+ Sound *copy();
+
private:
// Create a sound. The Object obj is ensured to be a Stream with a Dict
- Sound(Object *obj);
+ Sound(Object *obj, bool readAttrs = true);
Object *streamObj;
+ SoundKind kind;
+ GooString *fileName;
+ double samplingRate;
+ int channels;
+ int bitsPerSample;
+ SoundEncoding encoding;
};
#endif
More information about the poppler
mailing list