summaryrefslogtreecommitdiffstats
path: root/kttsd/players
diff options
context:
space:
mode:
Diffstat (limited to 'kttsd/players')
-rw-r--r--kttsd/players/Makefile.am27
-rw-r--r--kttsd/players/akodeplayer/Makefile.am28
-rw-r--r--kttsd/players/akodeplayer/README19
-rw-r--r--kttsd/players/akodeplayer/akodeplayer.cpp179
-rw-r--r--kttsd/players/akodeplayer/akodeplayer.h67
-rw-r--r--kttsd/players/akodeplayer/akodeplugin.cpp29
-rw-r--r--kttsd/players/akodeplayer/kttsd_akodeplugin.desktop89
-rw-r--r--kttsd/players/alsaplayer/Makefile.am30
-rw-r--r--kttsd/players/alsaplayer/alsaplayer.cpp1729
-rw-r--r--kttsd/players/alsaplayer/alsaplayer.h187
-rw-r--r--kttsd/players/alsaplayer/alsaplugin.cpp29
-rw-r--r--kttsd/players/alsaplayer/formats.h110
-rw-r--r--kttsd/players/alsaplayer/kttsd_alsaplugin.desktop89
-rw-r--r--kttsd/players/artsplayer/Makefile.am30
-rw-r--r--kttsd/players/artsplayer/artsplayer.cpp296
-rw-r--r--kttsd/players/artsplayer/artsplayer.h95
-rw-r--r--kttsd/players/artsplayer/artsplugin.cpp29
-rw-r--r--kttsd/players/artsplayer/kttsd_artsplugin.desktop91
-rw-r--r--kttsd/players/gstplayer/Makefile.am30
-rw-r--r--kttsd/players/gstplayer/gstplugin.cpp29
-rw-r--r--kttsd/players/gstplayer/gstreamerplayer.cpp258
-rw-r--r--kttsd/players/gstplayer/gstreamerplayer.h76
-rw-r--r--kttsd/players/gstplayer/kttsd_gstplugin.desktop92
-rw-r--r--kttsd/players/kttsd_audioplugin.desktop47
24 files changed, 3685 insertions, 0 deletions
diff --git a/kttsd/players/Makefile.am b/kttsd/players/Makefile.am
new file mode 100644
index 0000000..f400d82
--- /dev/null
+++ b/kttsd/players/Makefile.am
@@ -0,0 +1,27 @@
+#kdevelop: artsplayer_DIR = artsplayer
+if include_kttsd_artsplayer
+ artsplayer_DIR = artsplayer
+endif
+
+#kdevelop: gstplayer_DIR = gstplayer
+if include_kttsd_gstplayer
+ gstplayer_DIR = gstplayer
+endif
+
+#kdevelop: alsaplayer_DIR = alsaplayer
+if include_kttsd_alsaplayer
+ alsaplayer_DIR = alsaplayer
+endif
+
+#kdevelop: akodeplayer_DIR = akodeplayer
+if include_kttsd_akodeplayer
+ akodeplayer_DIR = akodeplayer
+endif
+
+SUBDIRS = \
+ $(artsplayer_DIR) \
+ $(alsaplayer_DIR) \
+ $(gstplayer_DIR) \
+ $(akodeplayer_DIR)
+
+kde_servicetypes_DATA = kttsd_audioplugin.desktop
diff --git a/kttsd/players/akodeplayer/Makefile.am b/kttsd/players/akodeplayer/Makefile.am
new file mode 100644
index 0000000..f5039f6
--- /dev/null
+++ b/kttsd/players/akodeplayer/Makefile.am
@@ -0,0 +1,28 @@
+INCLUDES = \
+ -I$(top_srcdir)/kttsd/libkttsd -I$(top_builddir)/kttsd/libkttsd \
+ $(akode_includes) \
+ $(all_includes)
+
+# Let automoc handle all of the metsource files (moc).
+METASOURCES = AUTO
+
+#########################################################################
+# LIBRARY SECTION
+#########################################################################
+# This is the library that gets installed. It's name is used for all
+# of the other Makefile.am variables.
+kde_module_LTLIBRARIES = libkttsd_akodeplugin.la
+
+libkttsd_akodeplugin_la_SOURCES = \
+ akodeplugin.cpp \
+ akodeplayer.cpp
+libkttsd_akodeplugin_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) -no-undefined
+libkttsd_akodeplugin_la_LIBADD = $(top_builddir)/kttsd/libkttsd/libkttsd.la $(akode_libs)
+
+# Header files that should not be installed.
+noinst_HEADERS = \
+ akodeplayer.h
+
+# This library is installed as a plugin.
+services_DATA = kttsd_akodeplugin.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kttsd/players/akodeplayer/README b/kttsd/players/akodeplayer/README
new file mode 100644
index 0000000..a45864f
--- /dev/null
+++ b/kttsd/players/akodeplayer/README
@@ -0,0 +1,19 @@
+This is an aKode audio plugin for KTTS.
+
+There are two problems right now (19 Jun 2005) that prevent this from being usable
+for KTTS:
+
+1. There was a bug in aKode that prevents it from playing .wav files. Carewolf
+ applied a patch on 13 Jun 2005 to decoderpluginhandler.cpp for this,
+ so you may need to update your kdemultimedia modules.
+
+2. aKode doesn't instantly stop when calling pause() or stop().
+ See bug:107135.
+
+If you want to try this plugin, add --enable-kttsd-akode to ./configure command.
+
+If the problems above aren't addressed, this plugin should probably be removed
+from KTTS.
+
+-- Gary Cramblitt (PhantomsDad)
+
diff --git a/kttsd/players/akodeplayer/akodeplayer.cpp b/kttsd/players/akodeplayer/akodeplayer.cpp
new file mode 100644
index 0000000..de88773
--- /dev/null
+++ b/kttsd/players/akodeplayer/akodeplayer.cpp
@@ -0,0 +1,179 @@
+/***************************************************************************
+ copyright : (C) 2004 by Allan Sandfeld Jensen
+ email : kde@carewolf.com
+***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <config.h>
+
+#include <kdebug.h>
+
+#include <qfile.h>
+
+#include "akode/player.h"
+#include "akode/decoder.h"
+
+#include "akodeplayer.h"
+
+using namespace aKode;
+
+////////////////////////////////////////////////////////////////////////////////
+// public methods
+////////////////////////////////////////////////////////////////////////////////
+
+aKodePlayer::aKodePlayer(QObject* parent, const char* name, const QStringList& args) :
+ Player(parent, name, args),
+ m_player(0)
+{}
+
+aKodePlayer::~aKodePlayer()
+{
+ delete m_player;
+}
+
+//void aKodePlayer::play(const FileHandle &file)
+void aKodePlayer::startPlay(const QString &file)
+{
+ kdDebug() << k_funcinfo << endl;
+
+ if (file.isNull()) { // null FileHandle file means unpause
+ if (paused())
+ // m_player->resume();
+ m_player->play();
+ else
+ stop();
+ return;
+ }
+
+ // QString filename = file.absFilePath();
+
+ kdDebug() << "Opening: " << file << endl;
+
+ if (m_player)
+ m_player->stop();
+ else {
+ m_player = new aKode::Player();
+ if (!m_player->open(m_sinkName.ascii())) {
+ kdDebug() << k_funcinfo << "Unable to open aKode " << m_sinkName << " sink. "
+ << "Falling back to auto." << endl;
+ m_player->open("auto");
+ }
+ }
+
+ if (m_player->load(QFile::encodeName(file)))
+ m_player->play();
+
+}
+
+void aKodePlayer::pause()
+{
+ if (m_player)
+ m_player->pause();
+}
+
+void aKodePlayer::stop()
+{
+ if (m_player) {
+ m_player->stop();
+ m_player->unload();
+ }
+}
+
+void aKodePlayer::setVolume(float volume)
+{
+ if (m_player)
+ m_player->setVolume(volume);
+}
+
+float aKodePlayer::volume() const
+{
+ if (m_player)
+ return m_player->volume();
+ // 1.0 is full volume
+ return 1.0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// m_player status functions
+/////////////////////////////////////////////////////////////////////////////////
+
+bool aKodePlayer::playing() const
+{
+ if (m_player && m_player->decoder())
+ return !m_player->decoder()->eof();
+ else
+ return false;
+}
+
+bool aKodePlayer::paused() const
+{
+ return m_player && (m_player->state() == aKode::Player::Paused);
+}
+
+int aKodePlayer::totalTime() const
+{
+ if (m_player) {
+ Decoder *d = m_player->decoder();
+ if (d)
+ return d->length() / 1000;
+ }
+ return -1;
+}
+
+int aKodePlayer::currentTime() const
+{
+ if (m_player) {
+ Decoder *d = m_player->decoder();
+ if (d)
+ return d->position() / 1000;
+ }
+ return -1;
+}
+
+int aKodePlayer::position() const
+{
+ if (m_player) {
+ Decoder *d = m_player->decoder();
+ if (d && d->length())
+ return (d->position()*1000)/(d->length());
+ else
+ return -1;
+ }
+ else
+ return -1;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// m_player seek functions
+/////////////////////////////////////////////////////////////////////////////////
+
+void aKodePlayer::seek(int seekTime)
+{
+ // seek time in seconds?
+ if (m_player)
+ m_player->decoder()->seek(seekTime*1000);
+}
+
+void aKodePlayer::seekPosition(int position)
+{
+ // position unit is 1/1000th
+ if (m_player)
+ m_player->decoder()->seek((position * m_player->decoder()->length())/1000);
+}
+
+QStringList aKodePlayer::getPluginList( const QCString& /*classname*/ )
+{
+ return QStringList::split("|", "auto|polyp|alsa|jack|oss");
+}
+
+void aKodePlayer::setSinkName(const QString& sinkName) { m_sinkName = sinkName; }
+
+#include "akodeplayer.moc"
diff --git a/kttsd/players/akodeplayer/akodeplayer.h b/kttsd/players/akodeplayer/akodeplayer.h
new file mode 100644
index 0000000..bbfb3ea
--- /dev/null
+++ b/kttsd/players/akodeplayer/akodeplayer.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+ copyright : (C) 2004 by Allan Sandfeld Jensen
+ email : kde@carewolf.com
+***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef AKODEPLAYER_H
+#define AKODEPLAYER_H
+
+#include <config.h>
+#include "kdeexportfix.h"
+
+#include <qstring.h>
+
+#include "player.h"
+#include <kdemacros.h>
+namespace aKode {
+ class File;
+ class Player;
+}
+
+class KDE_EXPORT aKodePlayer : public Player
+{
+ Q_OBJECT
+
+public:
+ aKodePlayer(QObject* parent = 0, const char* name = 0, const QStringList& args=QStringList());
+ virtual ~aKodePlayer();
+
+ // virtual void play(const FileHandle &file = FileHandle::null());
+ virtual void startPlay(const QString &file);
+
+ virtual void setVolume(float volume = 1.0);
+ virtual float volume() const;
+
+ virtual bool playing() const;
+ virtual bool paused() const;
+
+ virtual int totalTime() const;
+ virtual int currentTime() const;
+ virtual int position() const;
+
+ virtual void seek(int seekTime);
+ virtual void seekPosition(int position);
+
+ virtual QStringList getPluginList( const QCString& classname );
+ virtual void setSinkName(const QString &sinkName);
+
+public slots:
+ void pause();
+ void stop();
+
+private:
+ aKode::Player *m_player;
+ QString m_sinkName;
+};
+
+#endif
diff --git a/kttsd/players/akodeplayer/akodeplugin.cpp b/kttsd/players/akodeplayer/akodeplugin.cpp
new file mode 100644
index 0000000..9ef0deb
--- /dev/null
+++ b/kttsd/players/akodeplayer/akodeplugin.cpp
@@ -0,0 +1,29 @@
+/***************************************************** vim:set ts=4 sw=4 sts=4:
+ Generating the factories so aKode can be used as an audio plug in.
+ -------------------
+ Copyright:
+ (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
+ -------------------
+ Original author: Gary Cramblitt <garycramblitt@comcast.net>
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ******************************************************************************/
+
+#include <kgenericfactory.h>
+
+#include "akodeplayer.h"
+
+K_EXPORT_COMPONENT_FACTORY( libkttsd_akodeplugin, KGenericFactory<aKodePlayer>("kttsd_akode") );
+
diff --git a/kttsd/players/akodeplayer/kttsd_akodeplugin.desktop b/kttsd/players/akodeplayer/kttsd_akodeplugin.desktop
new file mode 100644
index 0000000..cc2c4bf
--- /dev/null
+++ b/kttsd/players/akodeplayer/kttsd_akodeplugin.desktop
@@ -0,0 +1,89 @@
+[Desktop Entry]
+Name=KTTSD aKode Plugin
+Name[br]=Lugent aKode evit KTTSD
+Name[bs]=KTTSD aKode dodatak
+Name[ca]=Connector aKode pel KTTSD
+Name[cs]=KTTSD aKode modul
+Name[da]=KTTSD aKode-plugin
+Name[de]=KTTSD aKode-Modul
+Name[el]=KTTSD πρόσθετο aKode
+Name[es]=Complemento aKode de KTTSD
+Name[et]=KTTSD aKode plugin
+Name[eu]=KTTSD-ren aKode plugina
+Name[fa]=وصلۀ KTTSD aKode
+Name[fi]=KTTSD aKode -liitännäinen
+Name[fr]=Module aKode pour KTTSD
+Name[ga]=Breiseán KTTSD aKode
+Name[gl]=Plugin aKode de KTTSD
+Name[he]=תוסף aKode עבור KTTSD
+Name[hu]=KTTSD aKode hangmodul
+Name[is]=KTTSD aKode íforrit
+Name[it]=Plugin per aKode di KTTSD
+Name[ja]=KTTSD aKode プラグイン
+Name[ka]=KTTSD aKode მოდული
+Name[km]= កម្មវិធី​ជំនួយ​ aKode សម្រាប់ KTTSD
+Name[mk]=aKode-приклучок за KTTSD
+Name[nb]=Programtillegg for KTTSD aKode
+Name[nds]=aKode-Moduul för KTTSD
+Name[ne]=KTTSD aKode प्लगइन
+Name[nl]=KTTSD aKode-plugin
+Name[pa]=KTTSD aKode ਪਲੱਗਿੰਨ
+Name[pl]=Wtyczka aKode KTTSD
+Name[pt]='Plugin' aKode do KTTSD
+Name[pt_BR]=Plug-in aKode para o KTTSD
+Name[ru]=Модуль aKode для KTTSD
+Name[sk]=Modul KTTSD aKode
+Name[sl]=Vstavek KTTSD za aKode
+Name[sr]=aKode прикључак за KTTSD
+Name[sr@Latn]=aKode priključak za KTTSD
+Name[sv]=KTTSD-insticksprogram för aKode
+Name[tg]=Модули KTTSD aKode
+Name[tr]=KTTSD aKode Eklentisi
+Name[uk]=Втулок aKode для KTTSD
+Name[vi]=Trình bổ sung KTTSD aKode
+Name[zh_TW]=KTTSD aKode 外掛程式
+Comment=KTTSD aKode audio plugin
+Comment[bg]=Аудио приставка на KTTSD за aKode
+Comment[br]=Lugent klevet aKode evit KTTSD
+Comment[ca]=Connector d'àudio aKode pel KTTSD
+Comment[cs]=KTTSD aKode zvukový modul
+Comment[da]=KTTSD aKode lyd-plugin
+Comment[de]=KTTSD aKode-Audio-Modul
+Comment[el]=KTTSD πρόσθετο ήχου aKode
+Comment[es]=Complemento de audio aKode de KTTSD
+Comment[et]=KTTSD aKode audioplugin
+Comment[eu]=KTTSD-ren aKode audio-plugina
+Comment[fa]=وصلۀ صوتی KTTSD aKode
+Comment[fi]=KTTSD aKode ääniliitännäinen
+Comment[fr]=Module audio aKode pour KTTSD
+Comment[ga]=Breiseán fuaime KTTSD aKode
+Comment[gl]=Plugin de áudio aKode para KTTSD
+Comment[hu]=KTTSD aKode hangmodul
+Comment[is]=KTTSD aKode hljóð íforrit
+Comment[it]=Plugin audio per aKode di KTTSD
+Comment[ja]=KTTSD aKode オーディオプラグイン
+Comment[ka]=KTTSD aKode აუდიო მოდული
+Comment[km]=កម្មវិធី​ជំនួយ​អូឌីយ៉ូ aKode សម្រាប់ KTTSD
+Comment[mk]=aKode-аудиоприклучок за KTTSD
+Comment[nb]=aKodes lyd-programtillegg for KTTSD
+Comment[nds]=aKode-Audiomoduul för KTTSD
+Comment[ne]=KTTSD aKode अडियो प्लगइन
+Comment[nl]=KTTSD aKode geluidsplugin
+Comment[pa]=KTTSD aKode ਆਡੀਓ ਪਲੱਗਿੰਨ
+Comment[pl]=Wtyczka dźwięku aKode dla KTTSD
+Comment[pt]='Plugin' de áudio aKode do KTTSD
+Comment[pt_BR]=Plug-in de áudio KTTSD aKode
+Comment[ru]=Модуль вывода звука KTTSD через aKode
+Comment[sk]=Modul KTTSD aKode audio
+Comment[sl]=Vstavek KTTSD za zvok v aKode
+Comment[sr]=aKode аудио прикључак за KTTSD
+Comment[sr@Latn]=aKode audio priključak za KTTSD
+Comment[sv]=KTTSD-ljudinsticksprogram för aKode
+Comment[tg]=Модули KTTSD aKode барои аудио
+Comment[tr]=KTTSD aRts ses eklentisi
+Comment[uk]=Втулок аудіо aKode для KTTSD
+Comment[vi]=Trình bổ sung âm thanh KTTSD aKode
+Comment[zh_TW]=KTTSd aKode 語音外掛程式
+Type=Service
+ServiceTypes=KTTSD/AudioPlugin
+X-KDE-Library=libkttsd_akodeplugin
diff --git a/kttsd/players/alsaplayer/Makefile.am b/kttsd/players/alsaplayer/Makefile.am
new file mode 100644
index 0000000..9653629
--- /dev/null
+++ b/kttsd/players/alsaplayer/Makefile.am
@@ -0,0 +1,30 @@
+# Include paths.
+INCLUDES = \
+ -I$(top_srcdir)/kttsd/libkttsd -I$(top_builddir)/kttsd/libkttsd \
+ $(all_includes)
+KDE_CXXFLAGS = -D_LARGEFILE64_SOURCE -D_GNU_SOURCE
+
+# Let automoc handle all of the metsource files (moc).
+METASOURCES = AUTO
+
+#########################################################################
+# LIBRARY SECTION
+#########################################################################
+# This is the library that gets installed. It's name is used for all
+# of the other Makefile.am variables.
+kde_module_LTLIBRARIES = libkttsd_alsaplugin.la
+
+libkttsd_alsaplugin_la_SOURCES = \
+ alsaplugin.cpp \
+ alsaplayer.cpp
+libkttsd_alsaplugin_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) $(LIBASOUND) -no-undefined
+libkttsd_alsaplugin_la_LIBADD = $(top_builddir)/kttsd/libkttsd/libkttsd.la
+
+# Header files that should not be installed.
+noinst_HEADERS = \
+ alsaplayer.h \
+ formats.h
+
+# This library is installed as a plugin.
+services_DATA = kttsd_alsaplugin.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kttsd/players/alsaplayer/alsaplayer.cpp b/kttsd/players/alsaplayer/alsaplayer.cpp
new file mode 100644
index 0000000..d3eabe8
--- /dev/null
+++ b/kttsd/players/alsaplayer/alsaplayer.cpp
@@ -0,0 +1,1729 @@
+/***************************************************** vim:set ts=4 sw=4 sts=4:
+ ALSA player.
+ -------------------
+ Copyright:
+ (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
+ Portions based on aplay.c in alsa-utils
+ Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ Based on vplay program by Michael Beck
+ -------------------
+ Original author: Gary Cramblitt <garycramblitt@comcast.net>
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ******************************************************************************/
+
+// #include <sys/wait.h>
+// System includes.
+#include <config.h>
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+// Qt includes.
+#include <qdir.h>
+#include <qapplication.h>
+#include <qcstring.h>
+
+// KDE includes.
+#include <kdebug.h>
+#include <kconfig.h>
+#include <kstandarddirs.h>
+#include <kmessagebox.h>
+#include <klocale.h>
+
+// AlsaPlayer includes.
+#include "alsaplayer.h"
+
+#if !defined(__GNUC__) || __GNUC__ >= 3
+#define ERR(...) do {\
+ QString dbgStr;\
+ QString s = dbgStr.sprintf( "%s:%d: ERROR ", __FUNCTION__, __LINE__); \
+ s += dbgStr.sprintf( __VA_ARGS__); \
+ kdDebug() << timestamp() << "AlsaPlayer::" << s << endl; \
+} while (0)
+#else
+#define ERR(args...) do {\
+ QString dbgStr;\
+ QString s = dbgStr.sprintf( "%s:%d: ERROR ", __FUNCTION__, __LINE__); \
+ s += dbgStr.sprintf( ##args ); \
+ kdDebug() << timestamp() << "AlsaPlayer::" << s << endl; \
+} while (0)
+#endif
+
+#if !defined(__GNUC__) || __GNUC__ >= 3
+#define MSG(...) do {\
+ if (m_debugLevel >= 1) {\
+ QString dbgStr; \
+ QString s = dbgStr.sprintf( "%s:%d: ", __FUNCTION__, __LINE__); \
+ s += dbgStr.sprintf( __VA_ARGS__); \
+ kdDebug() << timestamp() << "AlsaPlayer::" << s << endl; \
+ }; \
+} while (0)
+#else
+#define MSG(args...) do {\
+ if (m_debugLevel >= 1) {\
+ QString dbgStr; \
+ QString s = dbgStr.sprintf( "%s:%d: ", __FUNCTION__, __LINE__); \
+ s += dbgStr.sprintf( ##args ); \
+ kdDebug() << timestamp() << "AlsaPlayer::" << s << endl; \
+ }; \
+} while (0)
+#endif
+
+#if !defined(__GNUC__) || __GNUC__ >= 3
+#define DBG(...) do {\
+ if (m_debugLevel >= 2) {\
+ QString dbgStr; \
+ QString s = dbgStr.sprintf( "%s:%d: ", __FUNCTION__, __LINE__); \
+ s += dbgStr.sprintf( __VA_ARGS__); \
+ kdDebug() << timestamp() << "AlsaPlayer::" << s << endl; \
+ }; \
+} while (0)
+#else
+#define DBG(args...) do {\
+ if (m_debugLevel >= 2) {\
+ QString dbgStr; \
+ QString s = dbgStr.sprintf( "%s:%d: ", __FUNCTION__, __LINE__); \
+ s += dbgStr.sprintf( ##args ); \
+ kdDebug() << timestamp() << "AlsaPlayer::" << s << endl; \
+ }; \
+} while (0)
+#endif
+
+QString AlsaPlayer::timestamp() const
+{
+ time_t t;
+ struct timeval tv;
+ char *tstr;
+ t = time(NULL);
+ tstr = strdup(ctime(&t));
+ tstr[strlen(tstr)-1] = 0;
+ gettimeofday(&tv,NULL);
+ QString ts;
+ ts.sprintf(" %s [%d] ",tstr, (int) tv.tv_usec);
+ free(tstr);
+ return ts;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// public methods
+////////////////////////////////////////////////////////////////////////////////
+
+AlsaPlayer::AlsaPlayer(QObject* parent, const char* name, const QStringList& args) :
+ Player(parent, name, args),
+ m_currentVolume(1.0),
+ m_pcmName("default"),
+ m_defPeriodSize(128),
+ m_defPeriods(8),
+ m_debugLevel(1),
+ m_simulatedPause(false)
+{
+ init();
+}
+
+AlsaPlayer::~AlsaPlayer()
+{
+ if (running()) {
+ stop();
+ wait();
+ }
+}
+
+//void AlsaPlayer::play(const FileHandle &file)
+void AlsaPlayer::startPlay(const QString &file)
+{
+ if (running()) {
+ if (paused()) {
+ if (canPause)
+ snd_pcm_pause(handle, false);
+ else
+ m_simulatedPause = false;
+ }
+ return;
+ }
+ audiofile.setName(file);
+ audiofile.open(IO_ReadOnly);
+ fd = audiofile.handle();
+ // Start thread running.
+ start();
+}
+
+/*virtual*/ void AlsaPlayer::run()
+{
+ QString pName = m_pcmName.section(" ", 0, 0);
+ DBG("pName = %s", pName.ascii());
+ pcm_name = qstrdup(pName.ascii());
+ int err;
+ snd_pcm_info_t *info;
+
+ m_simulatedPause = false;
+
+ snd_pcm_info_alloca(&info);
+
+ err = snd_output_stdio_attach(&log, stderr, 0);
+ assert(err >= 0);
+
+ rhwdata.format = DEFAULT_FORMAT;
+ rhwdata.rate = DEFAULT_SPEED;
+ rhwdata.channels = 1;
+
+ err = snd_pcm_open(&handle, pcm_name, stream, open_mode);
+ if (err < 0) {
+ ERR("audio open error on pcm device %s: %s", pcm_name, snd_strerror(err));
+ return;
+ }
+
+ if ((err = snd_pcm_info(handle, info)) < 0) {
+ ERR("info error: %s", snd_strerror(err));
+ return;
+ }
+
+ chunk_size = 1024;
+ hwdata = rhwdata;
+
+ audioBuffer.resize(1024);
+ // audiobuf = (char *)malloc(1024);
+ audiobuf = audioBuffer.data();
+ if (audiobuf == NULL) {
+ ERR("not enough memory");
+ return;
+ }
+
+ if (mmap_flag) {
+ writei_func = snd_pcm_mmap_writei;
+ readi_func = snd_pcm_mmap_readi;
+ writen_func = snd_pcm_mmap_writen;
+ readn_func = snd_pcm_mmap_readn;
+ } else {
+ writei_func = snd_pcm_writei;
+ readi_func = snd_pcm_readi;
+ writen_func = snd_pcm_writen;
+ readn_func = snd_pcm_readn;
+ }
+
+ playback(fd);
+ cleanup();
+ return;
+}
+
+void AlsaPlayer::pause()
+{
+ if (running()) {
+ DBG("Pause requested");
+ m_mutex.lock();
+ if (handle) {
+ // Some hardware can pause; some can't. canPause is set in set_params.
+ if (canPause) {
+ m_simulatedPause = false;
+ snd_pcm_pause(handle, true);
+ m_mutex.unlock();
+ } else {
+ // Set a flag and cause wait_for_poll to sleep. When resumed, will get
+ // an underrun.
+ m_simulatedPause = true;
+ m_mutex.unlock();
+ }
+ }
+ }
+}
+
+void AlsaPlayer::stop()
+{
+ if (running()) {
+ DBG("STOP! Locking mutex");
+ m_mutex.lock();
+ m_simulatedPause = false;
+ if (handle) {
+ /* This constant is arbitrary */
+ char buf = 42;
+ DBG("Request for stop, device state is %s",
+ snd_pcm_state_name(snd_pcm_state(handle)));
+ write(alsa_stop_pipe[1], &buf, 1);
+ }
+ DBG("unlocking mutex");
+ m_mutex.unlock();
+ /* Wait for thread to exit */
+ DBG("waiting for thread to exit");
+ wait();
+ DBG("cleaning up");
+ }
+ cleanup();
+}
+
+/*
+ * Stop playback, cleanup and exit thread.
+ */
+void AlsaPlayer::stopAndExit()
+{
+ // if (handle) snd_pcm_drop(handle);
+ cleanup();
+ exit();
+}
+
+void AlsaPlayer::setVolume(float volume)
+{
+ m_currentVolume = volume;
+}
+
+float AlsaPlayer::volume() const
+{
+ return m_currentVolume;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// player status functions
+/////////////////////////////////////////////////////////////////////////////////
+
+bool AlsaPlayer::playing() const
+{
+ bool result = false;
+ if (running()) {
+ m_mutex.lock();
+ if (handle) {
+ if (canPause) {
+ snd_pcm_status_t *status;
+ snd_pcm_status_alloca(&status);
+ int res;
+ if ((res = snd_pcm_status(handle, status)) < 0)
+ ERR("status error: %s", snd_strerror(res));
+ else {
+ result = (SND_PCM_STATE_RUNNING == snd_pcm_status_get_state(status))
+ || (SND_PCM_STATE_DRAINING == snd_pcm_status_get_state(status));
+ DBG("state = %s", snd_pcm_state_name(snd_pcm_status_get_state(status)));
+ }
+ } else
+ result = !m_simulatedPause;
+ }
+ m_mutex.unlock();
+ }
+ return result;
+}
+
+bool AlsaPlayer::paused() const
+{
+ bool result = false;
+ if (running()) {
+ m_mutex.lock();
+ if (handle) {
+ if (canPause) {
+ snd_pcm_status_t *status;
+ snd_pcm_status_alloca(&status);
+ int res;
+ if ((res = snd_pcm_status(handle, status)) < 0)
+ ERR("status error: %s", snd_strerror(res));
+ else {
+ result = (SND_PCM_STATE_PAUSED == snd_pcm_status_get_state(status));
+ DBG("state = %s", snd_pcm_state_name(snd_pcm_status_get_state(status)));
+ }
+ } else
+ result = m_simulatedPause;
+ }
+ m_mutex.unlock();
+ }
+ return result;
+}
+
+int AlsaPlayer::totalTime() const
+{
+ int total = 0;
+ int rate = hwdata.rate;
+ int channels = hwdata.channels;
+ if (rate > 0 && channels > 0) {
+ total = int((double(pbrec_count) / rate) / channels);
+ // DBG("pbrec_count = %i rate =%i channels = %i", pbrec_count, rate, channels);
+ // DBG("totalTime = %i", total);
+ }
+ return total;
+}
+
+int AlsaPlayer::currentTime() const
+{
+ int current = 0;
+ int rate = hwdata.rate;
+ int channels = hwdata.channels;
+ if (rate > 0 && channels > 0) {
+ current = int((double(fdcount) / rate) / channels);
+ // DBG("fdcount = %i rate = %i channels = %i", fdcount, rate, channels);
+ // DBG("currentTime = %i", current);
+ }
+ return current;
+}
+
+int AlsaPlayer::position() const
+{
+ // TODO: Make this more accurate by adding frames that have been so-far
+ // played within the Alsa ring buffer.
+ return pbrec_count > 0 ? int(double(fdcount) * 1000 / pbrec_count + .5) : 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// player seek functions
+/////////////////////////////////////////////////////////////////////////////////
+
+void AlsaPlayer::seek(int /*seekTime*/)
+{
+ // TODO:
+}
+
+void AlsaPlayer::seekPosition(int /*position*/)
+{
+ // TODO:
+}
+
+/*
+ * Returns a list of PCM devices.
+ * This function fills the specified list with ALSA hardware soundcards found on the system.
+ * It uses plughw:xx instead of hw:xx for specifiers, because hw:xx are not practical to
+ * use (e.g. they require a resampler/channel mixer in the application).
+ */
+QStringList AlsaPlayer::getPluginList( const QCString& /*classname*/ )
+{
+ int err = 0;
+ int card = -1, device = -1;
+ snd_ctl_t *handle;
+ snd_ctl_card_info_t *info;
+ snd_pcm_info_t *pcminfo;
+ snd_ctl_card_info_alloca(&info);
+ snd_pcm_info_alloca(&pcminfo);
+ QStringList result;
+
+ result.append("default");
+ for (;;) {
+ err = snd_card_next(&card);
+ if (err < 0 || card < 0) break;
+ if (card >= 0) {
+ char name[32];
+ sprintf(name, "hw:%i", card);
+ if ((err = snd_ctl_open(&handle, name, 0)) < 0) continue;
+ if ((err = snd_ctl_card_info(handle, info)) < 0) {
+ snd_ctl_close(handle);
+ continue;
+ }
+ for (int devCnt=0;;++devCnt) {
+ err = snd_ctl_pcm_next_device(handle, &device);
+ if (err < 0 || device < 0) break;
+
+ snd_pcm_info_set_device(pcminfo, device);
+ snd_pcm_info_set_subdevice(pcminfo, 0);
+ snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK);
+ if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) continue;
+ QString infoName = " ";
+ infoName += snd_ctl_card_info_get_name(info);
+ infoName += " (";
+ infoName += snd_pcm_info_get_name(pcminfo);
+ infoName += ")";
+ if (0 == devCnt) {
+ QString pcmName = QString("default:%1").arg(card);
+ result.append(pcmName + infoName);
+ }
+ QString pcmName = QString("plughw:%1,%2").arg(card).arg(device);
+ result.append(pcmName + infoName);
+ }
+ snd_ctl_close(handle);
+ }
+ }
+ return result;
+}
+
+// QStringList AlsaPlayer::getPluginList( const QCString& /*classname*/ )
+// {
+// QStringList assumed("default");
+// snd_config_t *conf;
+// int err = snd_config_update();
+// if (err < 0) {
+// ERR("snd_config_update: %s", snd_strerror(err));
+// return assumed;
+// }
+// err = snd_config_search(snd_config, "pcm", &conf);
+// if (err < 0) return QStringList();
+// snd_config_iterator_t it = snd_config_iterator_first(conf);
+// snd_config_iterator_t itEnd = snd_config_iterator_end(conf);
+// const char* id;
+// snd_config_t *entry;
+// QStringList result;
+// snd_ctl_card_info_t *info;
+// snd_ctl_card_info_alloca(&info);
+// snd_pcm_info_t *pcminfo;
+// snd_pcm_info_alloca(&pcminfo);
+// while (it != itEnd) {
+// entry = snd_config_iterator_entry(it);
+// err = snd_config_get_id(entry, &id);
+// if (err >= 0) {
+// if (QString(id) != "default")
+// {
+// int card = -1;
+// while (snd_card_next(&card) >= 0 && card >= 0) {
+// char name[32];
+// sprintf(name, "%s:%d", id, card);
+// DBG("Checking %s", name);
+// snd_ctl_t *handle;
+// if ((err = snd_ctl_open(&handle, name, SND_CTL_NONBLOCK)) >= 0) {
+// if ((err = snd_ctl_card_info(handle, info)) >= 0) {
+// int dev = -1;
+// snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
+// while (snd_ctl_pcm_next_device(handle, &dev) >= 0 && dev >= 0) {
+// snd_pcm_info_set_device(pcminfo, dev);
+// snd_pcm_info_set_subdevice(pcminfo, 0);
+// snd_pcm_info_set_stream(pcminfo, stream);
+// if ((err = snd_ctl_pcm_info(handle, pcminfo)) >= 0) {
+// QString pluginName = name;
+// pluginName += ",";
+// pluginName += QString::number(dev);
+// pluginName += " ";
+// pluginName += snd_ctl_card_info_get_name(info);
+// pluginName += ",";
+// pluginName += snd_pcm_info_get_name(pcminfo);
+// result.append(pluginName);
+// // DBG(pluginName);
+// }
+// }
+// }
+// snd_ctl_close(handle);
+// }
+// }
+// if (card == -1) result.append(id);
+// } else result.append(id);
+// }
+// it = snd_config_iterator_next(it);
+// }
+// snd_config_update_free_global();
+// return result;
+// }
+
+void AlsaPlayer::setSinkName(const QString& sinkName) { m_pcmName = sinkName; }
+
+/////////////////////////////////////////////////////////////////////////////////
+// private
+/////////////////////////////////////////////////////////////////////////////////
+
+void AlsaPlayer::init()
+{
+ pcm_name = 0;
+ handle = 0;
+ canPause = false;
+ timelimit = 0;
+ file_type = FORMAT_DEFAULT;
+ sleep_min = 0;
+ // open_mode = 0;
+ open_mode = SND_PCM_NONBLOCK;
+ stream = SND_PCM_STREAM_PLAYBACK;
+ mmap_flag = 0;
+ interleaved = 1;
+ audiobuf = NULL;
+ chunk_size = 0;
+ period_time = 0;
+ buffer_time = 0;
+ avail_min = -1;
+ start_delay = 0;
+ stop_delay = 0;
+ buffer_pos = 0;
+ log = 0;
+ fd = -1;
+ pbrec_count = LLONG_MAX;
+ alsa_stop_pipe[0] = 0;
+ alsa_stop_pipe[1] = 0;
+ alsa_poll_fds = 0;
+ m_simulatedPause = false;
+}
+
+void AlsaPlayer::cleanup()
+{
+ DBG("cleaning up");
+ m_mutex.lock();
+ if (pcm_name) free(pcm_name);
+ if (fd >= 0) audiofile.close();
+ if (handle) {
+ snd_pcm_drop(handle);
+ snd_pcm_close(handle);
+ }
+ if (alsa_stop_pipe[0]) close(alsa_stop_pipe[0]);
+ if (alsa_stop_pipe[1]) close(alsa_stop_pipe[1]);
+ if (audiobuf) audioBuffer.resize(0);
+ if (alsa_poll_fds) alsa_poll_fds_barray.resize(0);
+ if (log) snd_output_close(log);
+ snd_config_update_free_global();
+ init();
+ m_mutex.unlock();
+}
+
+/*
+ * Safe read (for pipes)
+ */
+
+ssize_t AlsaPlayer::safe_read(int fd, void *buf, size_t count)
+{
+ ssize_t result = 0;
+ ssize_t res;
+
+ while (count > 0) {
+ if ((res = read(fd, buf, count)) == 0)
+ break;
+ if (res < 0)
+ return result > 0 ? result : res;
+ count -= res;
+ result += res;
+ buf = (char *)buf + res;
+ }
+ return result;
+}
+
+/*
+ * Test, if it is a .VOC file and return >=0 if ok (this is the length of rest)
+ * < 0 if not
+ */
+int AlsaPlayer::test_vocfile(void *buffer)
+{
+ VocHeader *vp = (VocHeader*)buffer;
+
+ if (!memcmp(vp->magic, VOC_MAGIC_STRING, 20)) {
+ vocminor = LE_SHORT(vp->version) & 0xFF;
+ vocmajor = LE_SHORT(vp->version) / 256;
+ if (LE_SHORT(vp->version) != (0x1233 - LE_SHORT(vp->coded_ver)))
+ return -2; /* coded version mismatch */
+ return LE_SHORT(vp->headerlen) - sizeof(VocHeader); /* 0 mostly */
+ }
+ return -1; /* magic string fail */
+}
+
+/*
+ * helper for test_wavefile
+ */
+
+size_t AlsaPlayer::test_wavefile_read(int fd, char *buffer, size_t *size, size_t reqsize, int line)
+{
+ if (*size >= reqsize)
+ return *size;
+ if ((size_t)safe_read(fd, buffer + *size, reqsize - *size) != reqsize - *size) {
+ ERR("read error (called from line %i)", line);
+ stopAndExit();
+ }
+ return *size = reqsize;
+}
+
+#define check_wavefile_space(buffer, len, blimit) \
+ if (len > blimit) { \
+ blimit = len; \
+ if ((buffer = (char*)realloc(buffer, blimit)) == NULL) { \
+ ERR("not enough memory"); \
+ stopAndExit(); \
+ } \
+ }
+
+/*
+ * test, if it's a .WAV file, > 0 if ok (and set the speed, stereo etc.)
+ * == 0 if not
+ * Value returned is bytes to be discarded.
+ */
+ssize_t AlsaPlayer::test_wavefile(int fd, char *_buffer, size_t size)
+{
+ WaveHeader *h = (WaveHeader *)_buffer;
+ char *buffer = NULL;
+ size_t blimit = 0;
+ WaveFmtBody *f;
+ WaveChunkHeader *c;
+ u_int type;
+ u_int len;
+
+ if (size < sizeof(WaveHeader))
+ return -1;
+ if (h->magic != WAV_RIFF || h->type != WAV_WAVE)
+ return -1;
+ if (size > sizeof(WaveHeader)) {
+ check_wavefile_space(buffer, size - sizeof(WaveHeader), blimit);
+ memcpy(buffer, _buffer + sizeof(WaveHeader), size - sizeof(WaveHeader));
+ }
+ size -= sizeof(WaveHeader);
+ while (1) {
+ check_wavefile_space(buffer, sizeof(WaveChunkHeader), blimit);
+ test_wavefile_read(fd, buffer, &size, sizeof(WaveChunkHeader), __LINE__);
+ c = (WaveChunkHeader*)buffer;
+ type = c->type;
+ len = LE_INT(c->length);
+ len += len % 2;
+ if (size > sizeof(WaveChunkHeader))
+ memmove(buffer, buffer + sizeof(WaveChunkHeader), size - sizeof(WaveChunkHeader));
+ size -= sizeof(WaveChunkHeader);
+ if (type == WAV_FMT)
+ break;
+ check_wavefile_space(buffer, len, blimit);
+ test_wavefile_read(fd, buffer, &size, len, __LINE__);
+ if (size > len)
+ memmove(buffer, buffer + len, size - len);
+ size -= len;
+ }
+
+ if (len < sizeof(WaveFmtBody)) {
+ ERR("unknown length of 'fmt ' chunk (read %u, should be %u at least)", len, (u_int)sizeof(WaveFmtBody));
+ stopAndExit();
+ }
+ check_wavefile_space(buffer, len, blimit);
+ test_wavefile_read(fd, buffer, &size, len, __LINE__);
+ f = (WaveFmtBody*) buffer;
+ if (LE_SHORT(f->format) != WAV_PCM_CODE) {
+ ERR("can't play not PCM-coded WAVE-files");
+ stopAndExit();
+ }
+ if (LE_SHORT(f->modus) < 1) {
+ ERR("can't play WAVE-files with %d tracks", LE_SHORT(f->modus));
+ stopAndExit();
+ }
+ hwdata.channels = LE_SHORT(f->modus);
+ switch (LE_SHORT(f->bit_p_spl)) {
+ case 8:
+ if (hwdata.format != DEFAULT_FORMAT &&
+ hwdata.format != SND_PCM_FORMAT_U8)
+ MSG("Warning: format is changed to U8");
+ hwdata.format = SND_PCM_FORMAT_U8;
+ break;
+ case 16:
+ if (hwdata.format != DEFAULT_FORMAT &&
+ hwdata.format != SND_PCM_FORMAT_S16_LE)
+ MSG("Warning: format is changed to S16_LE");
+ hwdata.format = SND_PCM_FORMAT_S16_LE;
+ break;
+ case 24:
+ switch (LE_SHORT(f->byte_p_spl) / hwdata.channels) {
+ case 3:
+ if (hwdata.format != DEFAULT_FORMAT &&
+ hwdata.format != SND_PCM_FORMAT_S24_3LE)
+ MSG("Warning: format is changed to S24_3LE");
+ hwdata.format = SND_PCM_FORMAT_S24_3LE;
+ break;
+ case 4:
+ if (hwdata.format != DEFAULT_FORMAT &&
+ hwdata.format != SND_PCM_FORMAT_S24_LE)
+ MSG("Warning: format is changed to S24_LE");
+ hwdata.format = SND_PCM_FORMAT_S24_LE;
+ break;
+ default:
+ ERR("can't play WAVE-files with sample %d bits in %d bytes wide (%d channels)", LE_SHORT(f->bit_p_spl), LE_SHORT(f->byte_p_spl), hwdata.channels);
+ stopAndExit();
+ }
+ break;
+ case 32:
+ hwdata.format = SND_PCM_FORMAT_S32_LE;
+ break;
+ default:
+ ERR("can't play WAVE-files with sample %d bits wide", LE_SHORT(f->bit_p_spl));
+ stopAndExit();
+ }
+ hwdata.rate = LE_INT(f->sample_fq);
+
+ if (size > len)
+ memmove(buffer, buffer + len, size - len);
+ size -= len;
+
+ while (1) {
+ u_int type, len;
+
+ check_wavefile_space(buffer, sizeof(WaveChunkHeader), blimit);
+ test_wavefile_read(fd, buffer, &size, sizeof(WaveChunkHeader), __LINE__);
+ c = (WaveChunkHeader*)buffer;
+ type = c->type;
+ len = LE_INT(c->length);
+ if (size > sizeof(WaveChunkHeader))
+ memmove(buffer, buffer + sizeof(WaveChunkHeader), size - sizeof(WaveChunkHeader));
+ size -= sizeof(WaveChunkHeader);
+ if (type == WAV_DATA) {
+ if (len < pbrec_count && len < 0x7ffffffe)
+ pbrec_count = len;
+ if (size > 0)
+ memcpy(_buffer, buffer, size);
+ free(buffer);
+ return size;
+ }
+ len += len % 2;
+ check_wavefile_space(buffer, len, blimit);
+ test_wavefile_read(fd, buffer, &size, len, __LINE__);
+ if (size > len)
+ memmove(buffer, buffer + len, size - len);
+ size -= len;
+ }
+
+ /* shouldn't be reached */
+ return -1;
+}
+
+/*
+ * Test for AU file.
+ */
+
+int AlsaPlayer::test_au(int fd, char *buffer)
+{
+ AuHeader *ap = (AuHeader*)buffer;
+
+ if (ap->magic != AU_MAGIC)
+ return -1;
+ if (BE_INT(ap->hdr_size) > 128 || BE_INT(ap->hdr_size) < 24)
+ return -1;
+ pbrec_count = BE_INT(ap->data_size);
+ switch (BE_INT(ap->encoding)) {
+ case AU_FMT_ULAW:
+ if (hwdata.format != DEFAULT_FORMAT &&
+ hwdata.format != SND_PCM_FORMAT_MU_LAW)
+ MSG("Warning: format is changed to MU_LAW");
+ hwdata.format = SND_PCM_FORMAT_MU_LAW;
+ break;
+ case AU_FMT_LIN8:
+ if (hwdata.format != DEFAULT_FORMAT &&
+ hwdata.format != SND_PCM_FORMAT_U8)
+ MSG("Warning: format is changed to U8");
+ hwdata.format = SND_PCM_FORMAT_U8;
+ break;
+ case AU_FMT_LIN16:
+ if (hwdata.format != DEFAULT_FORMAT &&
+ hwdata.format != SND_PCM_FORMAT_S16_BE)
+ MSG("Warning: format is changed to S16_BE");
+ hwdata.format = SND_PCM_FORMAT_S16_BE;
+ break;
+ default:
+ return -1;
+ }
+ hwdata.rate = BE_INT(ap->sample_rate);
+ if (hwdata.rate < 2000 || hwdata.rate > 256000)
+ return -1;
+ hwdata.channels = BE_INT(ap->channels);
+ if (hwdata.channels < 1 || hwdata.channels > 128)
+ return -1;
+ if ((size_t)safe_read(fd, buffer + sizeof(AuHeader), BE_INT(ap->hdr_size) - sizeof(AuHeader)) != BE_INT(ap->hdr_size) - sizeof(AuHeader)) {
+ ERR("read error");
+ stopAndExit();
+ }
+ return 0;
+}
+
+void AlsaPlayer::set_params(void)
+{
+ snd_pcm_hw_params_t *hwparams;
+ snd_pcm_uframes_t period_size;
+ int err;
+ int dir;
+ unsigned int rate;
+ unsigned int periods;
+
+ snd_pcm_hw_params_alloca(&hwparams);
+ err = snd_pcm_hw_params_any(handle, hwparams);
+ if (err < 0) {
+ ERR("Broken configuration for this PCM: no configurations available");
+ stopAndExit();
+ }
+
+ /* Create the pipe for communication about stop requests. */
+ if (pipe(alsa_stop_pipe)) {
+ ERR("Stop pipe creation failed (%s)", strerror(errno));
+ stopAndExit();
+ }
+
+ /* Find how many descriptors we will get for poll(). */
+ alsa_fd_count = snd_pcm_poll_descriptors_count(handle);
+ if (alsa_fd_count <= 0){
+ ERR("Invalid poll descriptors count returned from ALSA.");
+ stopAndExit();
+ }
+
+ /* Create and fill in struct pollfd *alsa_poll_fds with ALSA descriptors. */
+ // alsa_poll_fds = (pollfd *)malloc ((alsa_fd_count + 1) * sizeof(struct pollfd));
+ alsa_poll_fds_barray.resize((alsa_fd_count + 1) * sizeof(struct pollfd));
+ alsa_poll_fds = (pollfd *)alsa_poll_fds_barray.data();
+ assert(alsa_poll_fds);
+ if ((err = snd_pcm_poll_descriptors(handle, alsa_poll_fds, alsa_fd_count)) < 0) {
+ ERR("Unable to obtain poll descriptors for playback: %s", snd_strerror(err));
+ stopAndExit();
+ }
+
+ /* Create a new pollfd structure for requests by alsa_stop(). */
+ struct pollfd alsa_stop_pipe_pfd;
+ alsa_stop_pipe_pfd.fd = alsa_stop_pipe[0];
+ alsa_stop_pipe_pfd.events = POLLIN;
+ alsa_stop_pipe_pfd.revents = 0;
+
+ /* Join this our own pollfd to the ALSAs ones. */
+ alsa_poll_fds[alsa_fd_count] = alsa_stop_pipe_pfd;
+ ++alsa_fd_count;
+
+ if (mmap_flag) {
+ snd_pcm_access_mask_t *mask = (snd_pcm_access_mask_t *)alloca(snd_pcm_access_mask_sizeof());
+ snd_pcm_access_mask_none(mask);
+ snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_INTERLEAVED);
+ snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
+ snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_COMPLEX);
+ err = snd_pcm_hw_params_set_access_mask(handle, hwparams, mask);
+ } else if (interleaved)
+ err = snd_pcm_hw_params_set_access(handle, hwparams,
+ SND_PCM_ACCESS_RW_INTERLEAVED);
+ else
+ err = snd_pcm_hw_params_set_access(handle, hwparams,
+ SND_PCM_ACCESS_RW_NONINTERLEAVED);
+ if (err < 0) {
+ ERR("Error setting access type: %s", snd_strerror(err));
+ stopAndExit();
+ }
+ err = snd_pcm_hw_params_set_format(handle, hwparams, hwdata.format);
+ if (err < 0) {
+ ERR("Error setting sample format to %i: %s", hwdata.format, snd_strerror(err));
+ stopAndExit();
+ }
+ err = snd_pcm_hw_params_set_channels(handle, hwparams, hwdata.channels);
+ if (err < 0) {
+ ERR("Error setting channel count to %i: %s", hwdata.channels, snd_strerror(err));
+ stopAndExit();
+ }
+
+#if 0
+ err = snd_pcm_hw_params_set_periods_min(handle, hwparams, 2);
+ assert(err >= 0);
+#endif
+ rate = hwdata.rate;
+#if SND_LIB_MAJOR >= 1
+ err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &hwdata.rate, 0);
+#else
+ err = snd_pcm_hw_params_set_rate_near(handle, hwparams, hwdata.rate, 0);
+#endif
+ assert(err >= 0);
+ if ((float)rate * 1.05 < hwdata.rate || (float)rate * 0.95 > hwdata.rate) {
+ MSG("Warning: rate is not accurate (requested = %iHz, got = %iHz)", rate, hwdata.rate);
+ MSG(" please, try the plug plugin (-Dplug:%s)", snd_pcm_name(handle));
+ }
+
+ period_size = m_defPeriodSize;
+ dir = 1;
+#if SND_LIB_MAJOR >= 1
+ err = snd_pcm_hw_params_set_period_size_near(handle, hwparams, &period_size, &dir);
+#else
+ err = snd_pcm_hw_params_set_period_size_near(handle, hwparams, period_size, &dir);
+#endif
+ if (err < 0) {
+ MSG("Setting period_size to %lu failed, but continuing: %s", period_size, snd_strerror(err));
+ }
+
+ periods = m_defPeriods;
+ dir = 1;
+#if SND_LIB_MAJOR >= 1
+ err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &periods, &dir);
+#else
+ err = snd_pcm_hw_params_set_periods_near(handle, hwparams, periods, &dir);
+#endif
+ if (err < 0)
+ MSG("Unable to set number of periods to %i, but continuing: %s", periods, snd_strerror(err));
+
+ /* Install hw parameters. */
+ err = snd_pcm_hw_params(handle, hwparams);
+ if (err < 0) {
+ MSG("Unable to install hw params: %s", snd_strerror(err));
+ snd_pcm_hw_params_dump(hwparams, log);
+ stopAndExit();
+ }
+
+ /* Determine if device can pause. */
+ canPause = (1 == snd_pcm_hw_params_can_pause(hwparams));
+
+ /* Get final buffer size and calculate the chunk size we will pass to device. */
+#if SND_LIB_MAJOR >= 1
+ snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size);
+#else
+ buffer_size = snd_pcm_hw_params_get_buffer_size(hwparams);
+#endif
+ chunk_size = periods * period_size;
+
+ if (0 == chunk_size) {
+ ERR("Invalid periods or period_size. Cannot continue.");
+ stopAndExit();
+ }
+
+ if (chunk_size == buffer_size)
+ MSG("WARNING: Shouldn't use chunk_size equal to buffer_size (%lu). Continuing anyway.", chunk_size);
+
+ DBG("Final buffer_size = %lu, chunk_size = %lu, periods = %i, period_size = %lu, canPause = %i",
+ buffer_size, chunk_size, periods, period_size, canPause);
+
+ if (m_debugLevel >= 2)
+ snd_pcm_dump(handle, log);
+
+ bits_per_sample = snd_pcm_format_physical_width(hwdata.format);
+ bits_per_frame = bits_per_sample * hwdata.channels;
+ chunk_bytes = chunk_size * bits_per_frame / 8;
+ audioBuffer.resize(chunk_bytes);
+ audiobuf = audioBuffer.data();
+ if (audiobuf == NULL) {
+ ERR("not enough memory");
+ stopAndExit();
+ }
+}
+
+#ifndef timersub
+#define timersub(a, b, result) \
+do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
+ if ((result)->tv_usec < 0) { \
+ --(result)->tv_sec; \
+ (result)->tv_usec += 1000000; \
+ } \
+} while (0)
+#endif
+
+/* I/O error handler */
+void AlsaPlayer::xrun()
+{
+ snd_pcm_status_t *status;
+ int res;
+
+ snd_pcm_status_alloca(&status);
+ if ((res = snd_pcm_status(handle, status))<0) {
+ ERR("status error: %s", snd_strerror(res));
+ stopAndExit();
+ }
+ if (SND_PCM_STATE_XRUN == snd_pcm_status_get_state(status)) {
+ struct timeval now, diff, tstamp;
+ gettimeofday(&now, 0);
+ snd_pcm_status_get_trigger_tstamp(status, &tstamp);
+ timersub(&now, &tstamp, &diff);
+ MSG("%s!!! (at least %.3f ms long)",
+ stream == SND_PCM_STREAM_PLAYBACK ? "underrun" : "overrun",
+ diff.tv_sec * 1000 + diff.tv_usec / 1000.0);
+ if (m_debugLevel >= 2) {
+ DBG("Status:");
+ snd_pcm_status_dump(status, log);
+ }
+ if ((res = snd_pcm_prepare(handle))<0) {
+ ERR("xrun: prepare error: %s", snd_strerror(res));
+ stopAndExit();
+ }
+ return; /* ok, data should be accepted again */
+ } if (SND_PCM_STATE_DRAINING == snd_pcm_status_get_state(status)) {
+ if (m_debugLevel >= 2) {
+ DBG("Status(DRAINING):");
+ snd_pcm_status_dump(status, log);
+ }
+ if (stream == SND_PCM_STREAM_CAPTURE) {
+ MSG("capture stream format change? attempting recover...");
+ if ((res = snd_pcm_prepare(handle))<0) {
+ ERR("xrun(DRAINING): prepare error: %s", snd_strerror(res));
+ stopAndExit();
+ }
+ return;
+ }
+ }
+ if (m_debugLevel >= 2) {
+ DBG("Status(R/W):");
+ snd_pcm_status_dump(status, log);
+ }
+ ERR("read/write error, state = %s", snd_pcm_state_name(snd_pcm_status_get_state(status)));
+ stopAndExit();
+}
+
+/* I/O suspend handler */
+void AlsaPlayer::suspend(void)
+{
+ int res;
+
+ MSG("Suspended. Trying resume. ");
+ while ((res = snd_pcm_resume(handle)) == -EAGAIN)
+ sleep(1); /* wait until suspend flag is released */
+ if (res < 0) {
+ MSG("Failed. Restarting stream. ");
+ if ((res = snd_pcm_prepare(handle)) < 0) {
+ ERR("suspend: prepare error: %s", snd_strerror(res));
+ stopAndExit();
+ }
+ }
+ MSG("Suspend done.");
+}
+
+/* peak handler */
+void AlsaPlayer::compute_max_peak(char *data, size_t count)
+{
+ signed int val, max, max_peak = 0, perc;
+ size_t ocount = count;
+
+ switch (bits_per_sample) {
+ case 8: {
+ signed char *valp = (signed char *)data;
+ signed char mask = snd_pcm_format_silence(hwdata.format);
+ while (count-- > 0) {
+ val = *valp++ ^ mask;
+ val = abs(val);
+ if (max_peak < val)
+ max_peak = val;
+ }
+ break;
+ }
+ case 16: {
+ signed short *valp = (signed short *)data;
+ signed short mask = snd_pcm_format_silence_16(hwdata.format);
+ count /= 2;
+ while (count-- > 0) {
+ val = *valp++ ^ mask;
+ val = abs(val);
+ if (max_peak < val)
+ max_peak = val;
+ }
+ break;
+ }
+ case 32: {
+ signed int *valp = (signed int *)data;
+ signed int mask = snd_pcm_format_silence_32(hwdata.format);
+ count /= 4;
+ while (count-- > 0) {
+ val = *valp++ ^ mask;
+ val = abs(val);
+ if (max_peak < val)
+ max_peak = val;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ max = 1 << (bits_per_sample-1);
+ if (max <= 0)
+ max = 0x7fffffff;
+ DBG("Max peak (%li samples): %05i (0x%04x) ", (long)ocount, max_peak, max_peak);
+ if (bits_per_sample > 16)
+ perc = max_peak / (max / 100);
+ else
+ perc = max_peak * 100 / max;
+ for (val = 0; val < 20; val++)
+ if (val <= perc / 5)
+ kdDebug() << '#';
+ else
+ kdDebug() << ' ';
+ DBG(" %i%%", perc);
+}
+
+/*
+ * Write to the ALSA pcm.
+ */
+
+ssize_t AlsaPlayer::pcm_write(char *data, size_t count)
+{
+ ssize_t r;
+ ssize_t result = 0;
+
+ if (sleep_min == 0 && count < chunk_size) {
+ DBG("calling snd_pcm_format_set_silence");
+ snd_pcm_format_set_silence(hwdata.format, data + count * bits_per_frame / 8, (chunk_size - count) * hwdata.channels);
+ count = chunk_size;
+ }
+ while (count > 0) {
+ DBG("calling writei_func, count = %i", count);
+ r = writei_func(handle, data, count);
+ DBG("writei_func returned %i", r);
+ if (-EAGAIN == r || (r >= 0 && (size_t)r < count)) {
+ DBG("r = %i calling snd_pcm_wait", r);
+ snd_pcm_wait(handle, 100);
+ } else if (-EPIPE == r) {
+ xrun();
+ } else if (-ESTRPIPE == r) {
+ suspend();
+ } else if (-EBUSY == r){
+ MSG("WARNING: sleeping while PCM BUSY");
+ usleep(1000);
+ continue;
+ } else if (r < 0) {
+ ERR("write error: %s", snd_strerror(r));
+ stopAndExit();
+ }
+ if (r > 0) {
+ if (m_debugLevel >= 1)
+ compute_max_peak(data, r * hwdata.channels);
+ result += r;
+ count -= r;
+ data += r * bits_per_frame / 8;
+ }
+ /* Report current state */
+ DBG("PCM state before polling: %s",
+ snd_pcm_state_name(snd_pcm_state(handle)));
+
+ int err = wait_for_poll(0);
+ if (err < 0) {
+ ERR("Wait for poll() failed");
+ return -1;
+ }
+ else if (err == 1){
+ MSG("Playback stopped");
+ /* Drop the playback on the sound device (probably
+ still in progress up till now) */
+ err = snd_pcm_drop(handle);
+ if (err < 0) {
+ ERR("snd_pcm_drop() failed: %s", snd_strerror(err));
+ return -1;
+ }
+ return -1;
+ }
+ }
+ return result;
+}
+
+/*
+ * ok, let's play a .voc file
+ */
+
+ssize_t AlsaPlayer::voc_pcm_write(u_char *data, size_t count)
+{
+ ssize_t result = count, r;
+ size_t size;
+
+ while (count > 0) {
+ size = count;
+ if (size > chunk_bytes - buffer_pos)
+ size = chunk_bytes - buffer_pos;
+ memcpy(audiobuf + buffer_pos, data, size);
+ data += size;
+ count -= size;
+ buffer_pos += size;
+ if ((size_t)buffer_pos == chunk_bytes) {
+ if ((size_t)(r = pcm_write(audiobuf, chunk_size)) != chunk_size)
+ return r;
+ buffer_pos = 0;
+ }
+ }
+ return result;
+}
+
+void AlsaPlayer::voc_write_silence(unsigned x)
+{
+ unsigned l;
+ char *buf;
+
+ QByteArray buffer(chunk_bytes);
+ // buf = (char *) malloc(chunk_bytes);
+ buf = buffer.data();
+ if (buf == NULL) {
+ ERR("can't allocate buffer for silence");
+ return; /* not fatal error */
+ }
+ snd_pcm_format_set_silence(hwdata.format, buf, chunk_size * hwdata.channels);
+ while (x > 0) {
+ l = x;
+ if (l > chunk_size)
+ l = chunk_size;
+ if (voc_pcm_write((u_char*)buf, l) != (ssize_t)l) {
+ ERR("write error");
+ stopAndExit();
+ }
+ x -= l;
+ }
+ // free(buf);
+}
+
+void AlsaPlayer::voc_pcm_flush(void)
+{
+ if (buffer_pos > 0) {
+ size_t b;
+ if (sleep_min == 0) {
+ if (snd_pcm_format_set_silence(hwdata.format, audiobuf + buffer_pos, chunk_bytes - buffer_pos * 8 / bits_per_sample) < 0)
+ MSG("voc_pcm_flush - silence error");
+ b = chunk_size;
+ } else {
+ b = buffer_pos * 8 / bits_per_frame;
+ }
+ if (pcm_write(audiobuf, b) != (ssize_t)b)
+ ERR("voc_pcm_flush error");
+ }
+ snd_pcm_drain(handle);
+}
+
+void AlsaPlayer::voc_play(int fd, int ofs, const char* name)
+{
+ int l;
+ VocBlockType *bp;
+ VocVoiceData *vd;
+ VocExtBlock *eb;
+ size_t nextblock, in_buffer;
+ u_char *data, *buf;
+ char was_extended = 0, output = 0;
+ u_short *sp, repeat = 0;
+ size_t silence;
+ off64_t filepos = 0;
+
+#define COUNT(x) nextblock -= x; in_buffer -= x; data += x
+#define COUNT1(x) in_buffer -= x; data += x
+
+ QByteArray buffer(64 * 1024);
+ // data = buf = (u_char *)malloc(64 * 1024);
+ data = buf = (u_char*)buffer.data();
+ buffer_pos = 0;
+ if (data == NULL) {
+ ERR("malloc error");
+ stopAndExit();
+ }
+ MSG("Playing Creative Labs Channel file '%s'...", name);
+ /* first we waste the rest of header, ugly but we don't need seek */
+ while (ofs > (ssize_t)chunk_bytes) {
+ if ((size_t)safe_read(fd, buf, chunk_bytes) != chunk_bytes) {
+ ERR("read error");
+ stopAndExit();
+ }
+ ofs -= chunk_bytes;
+ }
+ if (ofs) {
+ if (safe_read(fd, buf, ofs) != ofs) {
+ ERR("read error");
+ stopAndExit();
+ }
+ }
+ hwdata.format = DEFAULT_FORMAT;
+ hwdata.channels = 1;
+ hwdata.rate = DEFAULT_SPEED;
+ set_params();
+
+ in_buffer = nextblock = 0;
+ while (1) {
+ Fill_the_buffer: /* need this for repeat */
+ if (in_buffer < 32) {
+ /* move the rest of buffer to pos 0 and fill the buf up */
+ if (in_buffer)
+ memcpy(buf, data, in_buffer);
+ data = buf;
+ if ((l = safe_read(fd, buf + in_buffer, chunk_bytes - in_buffer)) > 0)
+ in_buffer += l;
+ else if (!in_buffer) {
+ /* the file is truncated, so simulate 'Terminator'
+ and reduce the datablock for safe landing */
+ nextblock = buf[0] = 0;
+ if (l == -1) {
+// perror(name);
+ stopAndExit();
+ }
+ }
+ }
+ while (!nextblock) { /* this is a new block */
+ if (in_buffer < sizeof(VocBlockType))
+ goto __end;
+ bp = (VocBlockType *) data;
+ COUNT1(sizeof(VocBlockType));
+ nextblock = VOC_DATALEN(bp);
+ if (output)
+ MSG(" "); /* write /n after ASCII-out */
+ output = 0;
+ switch (bp->type) {
+ case 0:
+#if 0
+ MSG("Terminator");
+#endif
+ return; /* VOC-file stop */
+ case 1:
+ vd = (VocVoiceData *) data;
+ COUNT1(sizeof(VocVoiceData));
+ /* we need a SYNC, before we can set new SPEED, STEREO ... */
+
+ if (!was_extended) {
+ hwdata.rate = (int) (vd->tc);
+ hwdata.rate = 1000000 / (256 - hwdata.rate);
+#if 0
+ MSG("Channel data %d Hz", dsp_speed);
+#endif
+ if (vd->pack) { /* /dev/dsp can't it */
+ ERR("can't play packed .voc files");
+ return;
+ }
+ if (hwdata.channels == 2) /* if we are in Stereo-Mode, switch back */
+ hwdata.channels = 1;
+ } else { /* there was extended block */
+ hwdata.channels = 2;
+ was_extended = 0;
+ }
+ set_params();
+ break;
+ case 2: /* nothing to do, pure data */
+#if 0
+ MSG("Channel continuation");
+#endif
+ break;
+ case 3: /* a silence block, no data, only a count */
+ sp = (u_short *) data;
+ COUNT1(sizeof(u_short));
+ hwdata.rate = (int) (*data);
+ COUNT1(1);
+ hwdata.rate = 1000000 / (256 - hwdata.rate);
+ set_params();
+ silence = (((size_t) * sp) * 1000) / hwdata.rate;
+#if 0
+ MSG("Silence for %d ms", (int) silence);
+#endif
+ voc_write_silence(*sp);
+ break;
+ case 4: /* a marker for syncronisation, no effect */
+ sp = (u_short *) data;
+ COUNT1(sizeof(u_short));
+#if 0
+ MSG("Marker %d", *sp);
+#endif
+ break;
+ case 5: /* ASCII text, we copy to stderr */
+ output = 1;
+#if 0
+ MSG("ASCII - text :");
+#endif
+ break;
+ case 6: /* repeat marker, says repeatcount */
+ /* my specs don't say it: maybe this can be recursive, but
+ I don't think somebody use it */
+ repeat = *(u_short *) data;
+ COUNT1(sizeof(u_short));
+#if 0
+ MSG("Repeat loop %d times", repeat);
+#endif
+ if (filepos >= 0) { /* if < 0, one seek fails, why test another */
+ if ((filepos = lseek64(fd, 0, 1)) < 0) {
+ ERR("can't play loops; %s isn't seekable", name);
+ repeat = 0;
+ } else {
+ filepos -= in_buffer; /* set filepos after repeat */
+ }
+ } else {
+ repeat = 0;
+ }
+ break;
+ case 7: /* ok, lets repeat that be rewinding tape */
+ if (repeat) {
+ if (repeat != 0xFFFF) {
+#if 0
+ MSG("Repeat loop %d", repeat);
+#endif
+ --repeat;
+ }
+#if 0
+ else
+ MSG("Neverending loop");
+#endif
+ lseek64(fd, filepos, 0);
+ in_buffer = 0; /* clear the buffer */
+ goto Fill_the_buffer;
+ }
+#if 0
+ else
+ MSG("End repeat loop");
+#endif
+ break;
+ case 8: /* the extension to play Stereo, I have SB 1.0 :-( */
+ was_extended = 1;
+ eb = (VocExtBlock *) data;
+ COUNT1(sizeof(VocExtBlock));
+ hwdata.rate = (int) (eb->tc);
+ hwdata.rate = 256000000L / (65536 - hwdata.rate);
+ hwdata.channels = eb->mode == VOC_MODE_STEREO ? 2 : 1;
+ if (hwdata.channels == 2)
+ hwdata.rate = hwdata.rate >> 1;
+ if (eb->pack) { /* /dev/dsp can't it */
+ ERR("can't play packed .voc files");
+ return;
+ }
+#if 0
+ MSG("Extended block %s %d Hz",
+ (eb->mode ? "Stereo" : "Mono"), dsp_speed);
+#endif
+ break;
+ default:
+ ERR("unknown blocktype %d. terminate.", bp->type);
+ return;
+ } /* switch (bp->type) */
+ } /* while (! nextblock) */
+ /* put nextblock data bytes to dsp */
+ l = in_buffer;
+ if (nextblock < (size_t)l)
+ l = nextblock;
+ if (l) {
+ if (output) {
+ if (write(2, data, l) != l) { /* to stderr */
+ ERR("write error");
+ stopAndExit();
+ }
+ } else {
+ if (voc_pcm_write(data, l) != l) {
+ ERR("write error");
+ stopAndExit();
+ }
+ }
+ COUNT(l);
+ }
+ } /* while(1) */
+ __end:
+ voc_pcm_flush();
+ // free(buf);
+}
+/* that was a big one, perhaps somebody split it :-) */
+
+/* setting the globals for playing raw data */
+void AlsaPlayer::init_raw_data(void)
+{
+ hwdata = rhwdata;
+}
+
+/* calculate the data count to read from/to dsp */
+off64_t AlsaPlayer::calc_count(void)
+{
+ off64_t count;
+
+ if (timelimit == 0) {
+ count = pbrec_count;
+ } else {
+ count = snd_pcm_format_size(hwdata.format, hwdata.rate * hwdata.channels);
+ count *= (off64_t)timelimit;
+ }
+ return count < pbrec_count ? count : pbrec_count;
+}
+
+void AlsaPlayer::header(int /*rtype*/, const char* /*name*/)
+{
+// fprintf(stderr, "%s %s '%s' : ",
+// (stream == SND_PCM_STREAM_PLAYBACK) ? "Playing" : "Recording",
+// fmt_rec_table[rtype].what,
+// name);
+ QString channels;
+ if (hwdata.channels == 1)
+ channels = "Mono";
+ else if (hwdata.channels == 2)
+ channels = "Stereo";
+ else
+ channels = QString("Channels %1").arg(hwdata.channels);
+ DBG("Format: %s, Rate %d Hz, %s",
+ snd_pcm_format_description(hwdata.format),
+ hwdata.rate,
+ channels.ascii());
+}
+
+/* playing raw data */
+
+void AlsaPlayer::playback_go(int fd, size_t loaded, off64_t count, int rtype, const char *name)
+{
+ int l, r;
+ off64_t written = 0;
+ off64_t c;
+
+ if (m_debugLevel >= 1) header(rtype, name);
+ set_params();
+
+ while (loaded > chunk_bytes && written < count) {
+ if (pcm_write(audiobuf + written, chunk_size) <= 0)
+ return;
+ written += chunk_bytes;
+ loaded -= chunk_bytes;
+ }
+ if (written > 0 && loaded > 0)
+ memmove(audiobuf, audiobuf + written, loaded);
+
+ l = loaded;
+ while (written < count) {
+ do {
+ c = count - written;
+ if (c > chunk_bytes)
+ c = chunk_bytes;
+ c -= l;
+
+ if (c == 0)
+ break;
+ r = safe_read(fd, audiobuf + l, c);
+ if (r < 0) {
+// perror(name);
+ stopAndExit();
+ }
+ fdcount += r;
+ if (r == 0)
+ break;
+ l += r;
+ } while (sleep_min == 0 && (size_t)l < chunk_bytes);
+ l = l * 8 / bits_per_frame;
+ DBG("calling pcm_write with %i frames.", l);
+ r = pcm_write(audiobuf, l);
+ DBG("pcm_write returned r = %i", r);
+ if (r < 0) return;
+ if (r != l)
+ break;
+ r = r * bits_per_frame / 8;
+ written += r;
+ l = 0;
+ }
+
+ DBG("Draining...");
+
+ /* We want the next "device ready" notification only when the buffer is completely empty. */
+ /* Do this by setting the avail_min to the buffer size. */
+ int err;
+ DBG("Getting swparams");
+ snd_pcm_sw_params_t *swparams;
+ snd_pcm_sw_params_alloca(&swparams);
+ err = snd_pcm_sw_params_current(handle, swparams);
+ if (err < 0) {
+ ERR("Unable to get current swparams: %s", snd_strerror(err));
+ return;
+ }
+ DBG("Setting avail min to %lu", buffer_size);
+ err = snd_pcm_sw_params_set_avail_min(handle, swparams, buffer_size);
+ if (err < 0) {
+ ERR("Unable to set avail min for playback: %s", snd_strerror(err));
+ return;
+ }
+ /* write the parameters to the playback device */
+ DBG("Writing swparams");
+ err = snd_pcm_sw_params(handle, swparams);
+ if (err < 0) {
+ ERR("Unable to set sw params for playback: %s", snd_strerror(err));
+ return;
+ }
+
+ DBG("Waiting for poll");
+ err = wait_for_poll(1);
+ if (err < 0) {
+ ERR("Wait for poll() failed");
+ return;
+ } else if (err == 1){
+ MSG("Playback stopped while draining");
+
+ /* Drop the playback on the sound device (probably
+ still in progress up till now) */
+ err = snd_pcm_drop(handle);
+ if (err < 0) {
+ ERR("snd_pcm_drop() failed: %s", snd_strerror(err));
+ return;
+ }
+ }
+ DBG("Draining completed");
+}
+
+/*
+ * let's play or capture it (capture_type says VOC/WAVE/raw)
+ */
+
+void AlsaPlayer::playback(int fd)
+{
+ int ofs;
+ size_t dta;
+ ssize_t dtawave;
+
+ pbrec_count = LLONG_MAX;
+ fdcount = 0;
+
+ /* read the file header */
+ dta = sizeof(AuHeader);
+ if ((size_t)safe_read(fd, audiobuf, dta) != dta) {
+ ERR("read error");
+ stopAndExit();
+ }
+ if (test_au(fd, audiobuf) >= 0) {
+ rhwdata.format = hwdata.format;
+ pbrec_count = calc_count();
+ playback_go(fd, 0, pbrec_count, FORMAT_AU, name.ascii());
+ goto __end;
+ }
+ dta = sizeof(VocHeader);
+ if ((size_t)safe_read(fd, audiobuf + sizeof(AuHeader),
+ dta - sizeof(AuHeader)) != dta - sizeof(AuHeader)) {
+ ERR("read error");
+ stopAndExit();
+ }
+ if ((ofs = test_vocfile(audiobuf)) >= 0) {
+ pbrec_count = calc_count();
+ voc_play(fd, ofs, name.ascii());
+ goto __end;
+ }
+ /* read bytes for WAVE-header */
+ if ((dtawave = test_wavefile(fd, audiobuf, dta)) >= 0) {
+ pbrec_count = calc_count();
+ playback_go(fd, dtawave, pbrec_count, FORMAT_WAVE, name.ascii());
+ } else {
+ /* should be raw data */
+ init_raw_data();
+ pbrec_count = calc_count();
+ playback_go(fd, dta, pbrec_count, FORMAT_RAW, name.ascii());
+ }
+__end:
+ return;
+}
+
+/* Wait until ALSA is ready for more samples or stop() was called.
+ @return 0 if ALSA is ready for more input, +1 if a request to stop
+ the sound output was received and a negative value on error. */
+int AlsaPlayer::wait_for_poll(int draining)
+{
+ unsigned short revents;
+ snd_pcm_state_t state;
+ int ret;
+
+ DBG("Waiting for poll");
+
+ /* Wait for certain events */
+ while (1) {
+ /* Simulated pause by not writing to alsa device, which will lead to an XRUN
+ when resumed. */
+ if (m_simulatedPause)
+ msleep(500);
+ else {
+
+ ret = poll(alsa_poll_fds, alsa_fd_count, -1);
+ DBG("activity on %d descriptors", ret);
+
+ /* Check for stop request from alsa_stop on the last file descriptors. */
+ if ((revents = alsa_poll_fds[alsa_fd_count-1].revents)) {
+ if (revents & POLLIN){
+ DBG("stop requested");
+ return 1;
+ }
+ }
+
+ /* Check the first count-1 descriptors for ALSA events */
+ snd_pcm_poll_descriptors_revents(handle, alsa_poll_fds, alsa_fd_count-1, &revents);
+
+ /* Ensure we are in the right state */
+ state = snd_pcm_state(handle);
+ DBG("State after poll returned is %s", snd_pcm_state_name(state));
+
+ if (SND_PCM_STATE_XRUN == state){
+ if (!draining){
+ MSG("WARNING: Buffer underrun detected!");
+ xrun();
+ return 0;
+ }else{
+ DBG("Playback terminated");
+ return 0;
+ }
+ }
+
+ if (SND_PCM_STATE_SUSPENDED == state){
+ DBG("WARNING: Suspend detected!");
+ suspend();
+ return 0;
+ }
+
+ /* Check for errors */
+ if (revents & POLLERR) {
+ DBG("poll revents says POLLERR");
+ return -EIO;
+ }
+
+ /* Is ALSA ready for more input? */
+ if ((revents & POLLOUT)){
+ DBG("Ready for more input");
+ return 0;
+ }
+ }
+ }
+}
+
+#include "alsaplayer.moc"
+
+#undef DBG
+#undef MSG
+#undef ERR
+
+// vim: sw=4 ts=8 et
diff --git a/kttsd/players/alsaplayer/alsaplayer.h b/kttsd/players/alsaplayer/alsaplayer.h
new file mode 100644
index 0000000..acd465c
--- /dev/null
+++ b/kttsd/players/alsaplayer/alsaplayer.h
@@ -0,0 +1,187 @@
+/***************************************************** vim:set ts=4 sw=4 sts=4:
+ ALSA player.
+ -------------------
+ Copyright:
+ (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
+ -------------------
+ Original author: Gary Cramblitt <garycramblitt@comcast.net>
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ******************************************************************************/
+
+#ifndef ALSAPLAYER_H
+#define ALSAPLAYER_H
+
+// System includes.
+#include <alsa/asoundlib.h>
+#include <sys/poll.h>
+
+// Qt includes.
+#include <qstring.h>
+#include <qobject.h>
+#include <qthread.h>
+#include <qfile.h>
+#include <qmutex.h>
+
+// KDE includes.
+#include <config.h>
+#include <kdemacros.h>
+#include "kdeexportfix.h"
+#include <kurl.h>
+
+// AlsaPlayer includes.
+#include "formats.h"
+#include "player.h"
+
+#ifndef LLONG_MAX
+#define LLONG_MAX 9223372036854775807LL
+#endif
+
+#define DEFAULT_FORMAT SND_PCM_FORMAT_U8
+#define DEFAULT_SPEED 8000
+
+#define FORMAT_DEFAULT -1
+#define FORMAT_RAW 0
+#define FORMAT_VOC 1
+#define FORMAT_WAVE 2
+#define FORMAT_AU 3
+
+static snd_pcm_sframes_t (*readi_func)(snd_pcm_t *handle, void *buffer, snd_pcm_uframes_t size);
+static snd_pcm_sframes_t (*writei_func)(snd_pcm_t *handle, const void *buffer, snd_pcm_uframes_t size);
+static snd_pcm_sframes_t (*readn_func)(snd_pcm_t *handle, void **bufs, snd_pcm_uframes_t size);
+static snd_pcm_sframes_t (*writen_func)(snd_pcm_t *handle, void **bufs, snd_pcm_uframes_t size);
+
+class KDE_EXPORT AlsaPlayer : public Player, QThread
+{
+ Q_OBJECT
+
+public:
+ AlsaPlayer(QObject* parent = 0, const char* name = 0, const QStringList& args=QStringList());
+ ~AlsaPlayer();
+
+ virtual void startPlay(const QString& file);
+ virtual void pause();
+ virtual void stop();
+
+ virtual void setVolume(float volume = 1.0);
+ virtual float volume() const;
+
+ virtual bool playing() const;
+ virtual bool paused() const;
+
+ virtual int totalTime() const;
+ virtual int currentTime() const;
+ virtual int position() const; // in this case not really the percent
+
+ virtual void seek(int seekTime);
+ virtual void seekPosition(int position);
+
+ virtual QStringList getPluginList( const QCString& classname );
+ virtual void setSinkName(const QString &sinkName);
+
+ virtual void setDebugLevel(uint level) { m_debugLevel = level; }
+ virtual void setPeriodSize(uint periodSize) { m_defPeriodSize = periodSize; }
+ virtual void setPeriods(uint periods) { m_defPeriods = periods; }
+
+protected:
+ virtual void run();
+
+private slots:
+
+private:
+ void init();
+ void cleanup();
+ void stopAndExit();
+ int wait_for_poll(int draining);
+
+ QString timestamp() const;
+
+ ssize_t safe_read(int fd, void *buf, size_t count);
+ int test_vocfile(void *buffer);
+ size_t test_wavefile_read(int fd, char *buffer, size_t *size, size_t reqsize, int line);
+ ssize_t test_wavefile(int fd, char *_buffer, size_t size);
+ int test_au(int fd, char *buffer);
+ void set_params(void);
+ void xrun();
+ void suspend(void);
+ void compute_max_peak(char *data, size_t count);
+ ssize_t pcm_write(char *data, size_t count);
+ ssize_t voc_pcm_write(u_char *data, size_t count);
+ void voc_write_silence(unsigned x);
+ void voc_pcm_flush(void);
+ void voc_play(int fd, int ofs, const char *name);
+ void init_raw_data(void);
+ off64_t calc_count(void);
+ void header(int rtype, const char *name);
+ void playback_go(int fd, size_t loaded, off64_t count, int rtype, const char *name);
+ void playback(int fd);
+
+ KURL m_currentURL;
+ float m_currentVolume;
+ QString m_pcmName;
+ char* pcm_name;
+ mutable QMutex m_mutex;
+
+ QFile audiofile;
+ QString name;
+ bool canPause;
+
+ snd_pcm_t *handle;
+ struct {
+ snd_pcm_format_t format;
+ unsigned int channels;
+ unsigned int rate;
+ } hwdata, rhwdata;
+ int timelimit;
+ int file_type;
+ unsigned int sleep_min;
+ int open_mode;
+ snd_pcm_stream_t stream;
+ int mmap_flag;
+ int interleaved;
+ QByteArray audioBuffer;
+ char *audiobuf;
+ snd_pcm_uframes_t chunk_size;
+ snd_pcm_uframes_t period_frames;
+ unsigned period_time;
+ unsigned buffer_time;
+ snd_pcm_uframes_t buffer_size;
+ int avail_min;
+ int start_delay;
+ int stop_delay;
+ int buffer_pos;
+ size_t bits_per_sample;
+ size_t bits_per_frame;
+ size_t chunk_bytes;
+ snd_output_t *log;
+ int fd;
+ off64_t pbrec_count;
+ off64_t fdcount;
+ int vocmajor;
+ int vocminor;
+
+ int alsa_stop_pipe[2]; /* Pipe for communication about stop requests*/
+ int alsa_fd_count; /* Counter of descriptors to poll */
+ QByteArray alsa_poll_fds_barray;
+ struct pollfd *alsa_poll_fds; /* Descriptors to poll */
+ unsigned int m_defPeriodSize;
+ unsigned int m_defPeriods;
+ unsigned int m_debugLevel;
+ bool m_simulatedPause;
+};
+
+#endif // ALSAPLAYER_H
+
+// vim: sw=4 ts=8 et
diff --git a/kttsd/players/alsaplayer/alsaplugin.cpp b/kttsd/players/alsaplayer/alsaplugin.cpp
new file mode 100644
index 0000000..4bd700d
--- /dev/null
+++ b/kttsd/players/alsaplayer/alsaplugin.cpp
@@ -0,0 +1,29 @@
+/***************************************************** vim:set ts=4 sw=4 sts=4:
+ Generating the factories so ALSA can be used as an audio plug in.
+ -------------------
+ Copyright:
+ (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
+ -------------------
+ Original author: Gary Cramblitt <garycramblitt@comcast.net>
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ******************************************************************************/
+
+#include <kgenericfactory.h>
+
+#include "alsaplayer.h"
+
+K_EXPORT_COMPONENT_FACTORY( libkttsd_alsaplugin, KGenericFactory<AlsaPlayer>("kttsd_alsa") )
+
diff --git a/kttsd/players/alsaplayer/formats.h b/kttsd/players/alsaplayer/formats.h
new file mode 100644
index 0000000..2c4f724
--- /dev/null
+++ b/kttsd/players/alsaplayer/formats.h
@@ -0,0 +1,110 @@
+#ifndef FORMATS_H
+#define FORMATS_H 1
+
+#include <endian.h>
+#include <byteswap.h>
+
+/* Definitions for .VOC files */
+
+#define VOC_MAGIC_STRING "Creative Voice File\x1A"
+#define VOC_ACTUAL_VERSION 0x010A
+#define VOC_SAMPLESIZE 8
+
+#define VOC_MODE_MONO 0
+#define VOC_MODE_STEREO 1
+
+#define VOC_DATALEN(bp) ((u_long)(bp->datalen) | \
+ ((u_long)(bp->datalen_m) << 8) | \
+ ((u_long)(bp->datalen_h) << 16) )
+
+typedef struct voc_header {
+ u_char magic[20]; /* must be MAGIC_STRING */
+ u_short headerlen; /* Headerlength, should be 0x1A */
+ u_short version; /* VOC-file version */
+ u_short coded_ver; /* 0x1233-version */
+} VocHeader;
+
+typedef struct voc_blocktype {
+ u_char type;
+ u_char datalen; /* low-byte */
+ u_char datalen_m; /* medium-byte */
+ u_char datalen_h; /* high-byte */
+} VocBlockType;
+
+typedef struct voc_voice_data {
+ u_char tc;
+ u_char pack;
+} VocVoiceData;
+
+typedef struct voc_ext_block {
+ u_short tc;
+ u_char pack;
+ u_char mode;
+} VocExtBlock;
+
+/* Definitions for Microsoft WAVE format */
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define COMPOSE_ID(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
+#define LE_SHORT(v) (v)
+#define LE_INT(v) (v)
+#define BE_SHORT(v) bswap_16(v)
+#define BE_INT(v) bswap_32(v)
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define COMPOSE_ID(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
+#define LE_SHORT(v) bswap_16(v)
+#define LE_INT(v) bswap_32(v)
+#define BE_SHORT(v) (v)
+#define BE_INT(v) (v)
+#else
+#error "Wrong endian"
+#endif
+
+#define WAV_RIFF COMPOSE_ID('R','I','F','F')
+#define WAV_WAVE COMPOSE_ID('W','A','V','E')
+#define WAV_FMT COMPOSE_ID('f','m','t',' ')
+#define WAV_DATA COMPOSE_ID('d','a','t','a')
+#define WAV_PCM_CODE 1
+
+/* it's in chunks like .voc and AMIGA iff, but my source say there
+ are in only in this combination, so I combined them in one header;
+ it works on all WAVE-file I have
+ */
+typedef struct {
+ u_int magic; /* 'RIFF' */
+ u_int length; /* filelen */
+ u_int type; /* 'WAVE' */
+} WaveHeader;
+
+typedef struct {
+ u_short format; /* should be 1 for PCM-code */
+ u_short modus; /* 1 Mono, 2 Stereo */
+ u_int sample_fq; /* frequence of sample */
+ u_int byte_p_sec;
+ u_short byte_p_spl; /* samplesize; 1 or 2 bytes */
+ u_short bit_p_spl; /* 8, 12 or 16 bit */
+} WaveFmtBody;
+
+typedef struct {
+ u_int type; /* 'data' */
+ u_int length; /* samplecount */
+} WaveChunkHeader;
+
+/* Definitions for Sparc .au header */
+
+#define AU_MAGIC COMPOSE_ID('.','s','n','d')
+
+#define AU_FMT_ULAW 1
+#define AU_FMT_LIN8 2
+#define AU_FMT_LIN16 3
+
+typedef struct au_header {
+ u_int magic; /* '.snd' */
+ u_int hdr_size; /* size of header (min 24) */
+ u_int data_size; /* size of data */
+ u_int encoding; /* see to AU_FMT_XXXX */
+ u_int sample_rate; /* sample rate */
+ u_int channels; /* number of channels (voices) */
+} AuHeader;
+
+#endif /* FORMATS */
diff --git a/kttsd/players/alsaplayer/kttsd_alsaplugin.desktop b/kttsd/players/alsaplayer/kttsd_alsaplugin.desktop
new file mode 100644
index 0000000..36eec0b
--- /dev/null
+++ b/kttsd/players/alsaplayer/kttsd_alsaplugin.desktop
@@ -0,0 +1,89 @@
+[Desktop Entry]
+Name=KTTSD ALSA Plugin
+Name[br]=Lugent ALSA evit KTTSD
+Name[bs]=KTTSD ALSA dodatak
+Name[ca]=Connector ALSA pel KTTSD
+Name[cs]=KTTSD ALSA modul
+Name[da]=KTTSD ALSA plugin
+Name[de]=KTTSD ALSA-Modul
+Name[el]=KTTSD πρόσθετο ALSA
+Name[es]=Complemento ALSA de KTTSD
+Name[et]=KTTSD ALSA plugin
+Name[eu]=KTTSD-ren ALSA plugina
+Name[fa]=وصلۀ KTTSD ALSA
+Name[fi]=KTTSD ALSA -liitännäinen
+Name[fr]=Module ALSA pour KTTSD
+Name[ga]=Breiseán KTTSD ALSA
+Name[gl]=Plugin ALSA de KTTSD
+Name[hu]=KTTSD ALSA hangmodul
+Name[is]=KTTSD ALSA íforrit
+Name[it]=Plugin per ALSA di KTTSD
+Name[ja]=KTTSD ALSA プラグイン
+Name[ka]=KTTSD ALSA მოდული
+Name[km]= កម្មវិធី​ជំនួយ​ ALSA សម្រាប់ KTTSD
+Name[mk]=ALSA-приклучок за KTTSD
+Name[nb]=Alsas programtillegg for KTTSD
+Name[nds]=ALSA-Moduul för KTTSD
+Name[ne]=KTTSD ALSA प्लगइन
+Name[nl]=KTTSD ALSA-plugin
+Name[pa]=KTTSD ALSA ਪਲੱਗਿੰਨ
+Name[pl]=Wtyczka ALSA dla KTTSD
+Name[pt]='Plugin' ALSA do KTTSD
+Name[pt_BR]=Plug-in ALSA para o KTTSD
+Name[ru]=Модуль alsa для KTTSD
+Name[sk]=Modul KTTSD ALSA
+Name[sl]=Vstavek KTTSD za ALSA
+Name[sr]=ALSA прикључак за KTTSD
+Name[sr@Latn]=ALSA priključak za KTTSD
+Name[sv]=KTTSD-insticksprogram för ALSA
+Name[tg]=Модули KTTSD ALSA
+Name[tr]=KTTSD ALSA Eklentisi
+Name[uk]=Втулок ALSA для KTTSD
+Name[vi]=Trình bổ sung KTTSD ALSA
+Name[zh_TW]=KTTSd ALSA 外掛程式
+Comment=KTTSD ALSA audio plugin
+Comment[bg]=Аудио приставка на KTTSD за ALSA
+Comment[br]=Lugent klevet ALSA evit KTTSD
+Comment[bs]=KTTSD ALSA audio dodatak
+Comment[ca]=Connector d'àudio ALSA pel KTTSD
+Comment[cs]=KTTSD ALSA zvukový modul
+Comment[da]=KTTSD ALSA lyd-plugin
+Comment[de]=KTTSD ALSA-Audio-Modul
+Comment[el]=KTTSD πρόσθετο ήχου ALSA
+Comment[es]=Complemento de audio ALSA de KTTSD
+Comment[et]=KTTSD ALSA audioplugin
+Comment[eu]=KTTSD-ren ALSA audio-plugina
+Comment[fa]=وصلۀ صوتی KTTSD ALSA
+Comment[fi]=KTTSD ALSA ääniliitännäinen
+Comment[fr]=Module audio ALSA pour KTTSD
+Comment[ga]=Breiseán fuaime KTTSD ALSA
+Comment[gl]=Plugin de áudio ALSA para KTTSD
+Comment[hu]=KTTSD ALSA hangmodul
+Comment[is]=KTTSD ALSA hljóð íforrit
+Comment[it]=Plugin audio per ALSA di KTTSD
+Comment[ja]=KTTSD ALSA オーディオプラグイン
+Comment[ka]=KTTSD ALSA აუდიო მოდული
+Comment[km]= កម្មវិធី​ជំនួយអូឌីយ៉ូ​ ALSA សម្រាប់ KTTSD
+Comment[mk]=ALSA-аудиоприклучок за KTTSD
+Comment[nb]=Alsas lyd-programtillegg for KTTSD
+Comment[nds]=ALSA-Audiomoduul för KTTSD
+Comment[ne]=KTTSD ALSA अडियो प्लगइन
+Comment[nl]=KTTSD ALSA geluidsplugin
+Comment[pa]=KTTSD ALSA ਆਡੀਓ ਪਲੱਗਿੰਨ
+Comment[pl]=Wtyczka dźwięku ALSA dla KTTSD
+Comment[pt]='Plugin' de áudio ALSA do KTTSD
+Comment[pt_BR]=Plug-in de áudio ALSA para o KTTSD
+Comment[ru]=Модуль вывода звука KTTSD через alsa
+Comment[sk]=Modul KTTSD ALSA audio
+Comment[sl]=Vstavek KTTSD za zvok v ALSA
+Comment[sr]=ALSA аудио прикључак за KTTSD
+Comment[sr@Latn]=ALSA audio priključak za KTTSD
+Comment[sv]=KTTSD-ljudinsticksprogram för ALSA
+Comment[tg]=Модули KTTSD ALSA барои аудио
+Comment[tr]=KTTSD ALSA ses eklentisi
+Comment[uk]=Втулок аудіо ALSA для KTTSD
+Comment[vi]=Trình bổ sung âm thanh KTTSD ALSA
+Comment[zh_TW]=KTTSd ALSA 語音外掛程式
+Type=Service
+ServiceTypes=KTTSD/AudioPlugin
+X-KDE-Library=libkttsd_alsaplugin
diff --git a/kttsd/players/artsplayer/Makefile.am b/kttsd/players/artsplayer/Makefile.am
new file mode 100644
index 0000000..d5c6012
--- /dev/null
+++ b/kttsd/players/artsplayer/Makefile.am
@@ -0,0 +1,30 @@
+# Include paths. INCLUDES is maintained by KDevelop, AM_CPPFLAGS is the preferred variable,
+# so keep them synchronized.
+INCLUDES = \
+ -I$(kde_includes)/arts \
+ -I$(top_srcdir)/kttsd/libkttsd -I$(top_builddir)/kttsd/libkttsd \
+ $(all_includes)
+
+# Let automoc handle all of the metsource files (moc).
+METASOURCES = AUTO
+
+#########################################################################
+# LIBRARY SECTION
+#########################################################################
+# This is the library that gets installed. It's name is used for all
+# of the other Makefile.am variables.
+kde_module_LTLIBRARIES = libkttsd_artsplugin.la
+
+libkttsd_artsplugin_la_SOURCES = \
+ artsplugin.cpp \
+ artsplayer.cpp
+libkttsd_artsplugin_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) -no-undefined
+libkttsd_artsplugin_la_LIBADD = $(top_builddir)/kttsd/libkttsd/libkttsd.la -lartskde
+
+# Header files that should not be installed.
+noinst_HEADERS = \
+ artsplayer.h
+
+# This library is installed as a plugin.
+services_DATA = kttsd_artsplugin.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kttsd/players/artsplayer/artsplayer.cpp b/kttsd/players/artsplayer/artsplayer.cpp
new file mode 100644
index 0000000..512765a
--- /dev/null
+++ b/kttsd/players/artsplayer/artsplayer.cpp
@@ -0,0 +1,296 @@
+/***************************************************************************
+ begin : Sun Feb 17 2002
+ copyright : (C) 2002 - 2004 by Scott Wheeler
+ email : wheeler@kde.org
+
+ copyright : (C) 2003 by Matthias Kretz
+ email : kretz@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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "artsplayer.h"
+
+#include <kdebug.h>
+#include <kconfig.h>
+#include <kstandarddirs.h>
+
+#include <qdir.h>
+#include <qapplication.h>
+
+#include <kartsserver.h>
+#include <kartsdispatcher.h>
+#include <kplayobject.h>
+#include <kplayobjectfactory.h>
+
+#include <sys/wait.h>
+
+#include <kmessagebox.h>
+#include <kaudiomanagerplay.h>
+#include <klocale.h>
+
+////////////////////////////////////////////////////////////////////////////////
+// public methods
+////////////////////////////////////////////////////////////////////////////////
+
+ArtsPlayer::ArtsPlayer(QObject* parent, const char* name, const QStringList& args) :
+ Player(parent, name, args),
+ m_dispatcher(0),
+ m_server(0),
+ m_factory(0),
+ m_playobject(0),
+ m_amanPlay(0),
+ m_volumeControl(Arts::StereoVolumeControl::null()),
+ m_currentVolume(1.0)
+{
+}
+
+ArtsPlayer::~ArtsPlayer()
+{
+ delete m_playobject;
+ delete m_factory;
+ delete m_amanPlay;
+ delete m_server;
+ delete m_dispatcher;
+}
+
+//void ArtsPlayer::play(const FileHandle &file)
+void ArtsPlayer::startPlay(const QString &file)
+{
+ if (!m_dispatcher)
+ setupPlayer();
+
+ // kdDebug(65432) << k_funcinfo << endl;
+ // Make sure that the server still exists, if it doesn't a new one should
+ // be started automatically and the factory and amanPlay are created again.
+
+ if(!file.isNull())
+// m_currentURL.setPath(file.absFilePath());
+ m_currentURL.setPath(file);
+
+ if(m_server->server().isNull()) {
+ KMessageBox::error(0, i18n("Cannot find the aRts soundserver."));
+ return;
+ }
+
+ if(!m_playobject || !file.isNull()) {
+ stop();
+
+ delete m_playobject;
+ m_playobject = m_factory->createPlayObject(m_currentURL, false);
+
+ if(m_playobject->object().isNull())
+ connect(m_playobject, SIGNAL(playObjectCreated()), SLOT(playObjectCreated()));
+ else
+ playObjectCreated();
+ }
+
+ m_playobject->play();
+}
+
+void ArtsPlayer::pause()
+{
+ // kdDebug(65432) << k_funcinfo << endl;
+ if(m_playobject)
+ m_playobject->pause();
+}
+
+void ArtsPlayer::stop()
+{
+ // kdDebug(65432) << k_funcinfo << endl;
+ if(m_playobject) {
+ m_playobject->halt();
+ delete m_playobject;
+ m_playobject = 0;
+ }
+ if(!m_volumeControl.isNull()) {
+ m_volumeControl.stop();
+ m_volumeControl = Arts::StereoVolumeControl::null();
+ }
+}
+
+void ArtsPlayer::setVolume(float volume)
+{
+ // kdDebug( 65432 ) << k_funcinfo << endl;
+
+ m_currentVolume = volume;
+
+ if(serverRunning() && m_playobject && !m_playobject->isNull()) {
+ if(m_volumeControl.isNull())
+ setupVolumeControl();
+ if(!m_volumeControl.isNull()) {
+ m_volumeControl.scaleFactor(volume);
+ // kdDebug( 65432 ) << "set volume to " << volume << endl;
+ }
+ }
+}
+
+float ArtsPlayer::volume() const
+{
+ return m_currentVolume;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// player status functions
+/////////////////////////////////////////////////////////////////////////////////
+
+bool ArtsPlayer::playing() const
+{
+ if(serverRunning() && m_playobject && m_playobject->state() == Arts::posPlaying)
+ return true;
+ else
+ return false;
+}
+
+bool ArtsPlayer::paused() const
+{
+ if(serverRunning() && m_playobject && m_playobject->state() == Arts::posPaused)
+ return true;
+ else
+ return false;
+}
+
+int ArtsPlayer::totalTime() const
+{
+ if(serverRunning() && m_playobject)
+ return m_playobject->overallTime().seconds;
+ else
+ return -1;
+}
+
+int ArtsPlayer::currentTime() const
+{
+ if(serverRunning() && m_playobject &&
+ (m_playobject->state() == Arts::posPlaying ||
+ m_playobject->state() == Arts::posPaused))
+ {
+ return m_playobject->currentTime().seconds;
+ }
+ else
+ return -1;
+}
+
+int ArtsPlayer::position() const
+{
+ if(serverRunning() && m_playobject && m_playobject->state() == Arts::posPlaying) {
+ long total = m_playobject->overallTime().seconds * 1000 + m_playobject->overallTime().ms;
+ long current = m_playobject->currentTime().seconds * 1000 + m_playobject->currentTime().ms;
+
+ // add .5 to make rounding happen properly
+
+ return int(double(current) * 1000 / total + .5);
+ }
+ else
+ return -1;
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// player seek functions
+/////////////////////////////////////////////////////////////////////////////////
+
+void ArtsPlayer::seek(int seekTime)
+{
+ if(serverRunning() && m_playobject) {
+ Arts::poTime poSeekTime;
+ poSeekTime.custom = 0;
+ poSeekTime.ms = 0;
+ poSeekTime.seconds = seekTime;
+ m_playobject->object().seek(poSeekTime);
+ }
+}
+
+void ArtsPlayer::seekPosition(int position)
+{
+ if(serverRunning() && m_playobject) {
+ Arts::poTime poSeekTime;
+ long total = m_playobject->overallTime().seconds;
+ poSeekTime.custom = 0;
+ poSeekTime.ms = 0;
+ poSeekTime.seconds = long(double(total) * position / 1000 + .5);
+ m_playobject->object().seek(poSeekTime);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////
+// private
+/////////////////////////////////////////////////////////////////////////////////
+
+void ArtsPlayer::setupArtsObjects()
+{
+ // kdDebug( 65432 ) << k_funcinfo << endl;
+ delete m_factory;
+ delete m_amanPlay;
+ m_volumeControl = Arts::StereoVolumeControl::null();
+ m_factory = new KDE::PlayObjectFactory(m_server);
+ m_amanPlay = new KAudioManagerPlay(m_server);
+
+ if(m_amanPlay->isNull() || !m_factory) {
+ KMessageBox::error(0, i18n("Connecting/starting aRts soundserver failed. "
+ "Make sure that artsd is configured properly."));
+ qApp->exit(1);
+ }
+
+ m_amanPlay->setTitle(i18n("kttsd"));
+ m_amanPlay->setAutoRestoreID("kttsdAmanPlay");
+
+ m_factory->setAudioManagerPlay(m_amanPlay);
+}
+
+void ArtsPlayer::playObjectCreated()
+{
+ // kdDebug(65432) << k_funcinfo << endl;
+ setVolume(m_currentVolume);
+}
+
+void ArtsPlayer::setupPlayer()
+{
+ m_dispatcher = new KArtsDispatcher;
+ m_server = new KArtsServer;
+ setupArtsObjects();
+ connect(m_server, SIGNAL(restartedServer()), SLOT(setupArtsObjects()));
+}
+
+void ArtsPlayer::setupVolumeControl()
+{
+ // kdDebug( 65432 ) << k_funcinfo << endl;
+ m_volumeControl = Arts::DynamicCast(m_server->server().createObject("Arts::StereoVolumeControl"));
+ if(!m_volumeControl.isNull() && !m_playobject->isNull() && !m_playobject->object().isNull()) {
+ Arts::Synth_AMAN_PLAY ap = m_amanPlay->amanPlay();
+ Arts::PlayObject po = m_playobject->object();
+ ap.stop();
+ Arts::disconnect(po, "left" , ap, "left" );
+ Arts::disconnect(po, "right", ap, "right");
+
+ m_volumeControl.start();
+ ap.start();
+
+ Arts::connect(po, "left" , m_volumeControl, "inleft" );
+ Arts::connect(po, "right", m_volumeControl, "inright");
+ Arts::connect(m_volumeControl, "outleft" , ap, "left" );
+ Arts::connect(m_volumeControl, "outright", ap, "right");
+ // kdDebug( 65432 ) << "connected volume control" << endl;
+ }
+ else {
+ m_volumeControl = Arts::StereoVolumeControl::null();
+ kdDebug(65432) << "Could not initialize volume control!" << endl;
+ }
+}
+
+bool ArtsPlayer::serverRunning() const
+{
+ if(m_server)
+ return !(m_server->server().isNull());
+ else
+ return false;
+}
+
+#include "artsplayer.moc"
+
+// vim: sw=4 ts=8 et
diff --git a/kttsd/players/artsplayer/artsplayer.h b/kttsd/players/artsplayer/artsplayer.h
new file mode 100644
index 0000000..96d62f6
--- /dev/null
+++ b/kttsd/players/artsplayer/artsplayer.h
@@ -0,0 +1,95 @@
+/***************************************************************************
+ begin : Sun Feb 17 2002
+ copyright : (C) 2002 - 2004 by Scott Wheeler
+ email : wheeler@kde.org
+
+ copyright : (C) 2003 by Matthias Kretz
+ email : kretz@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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef ARTSPLAYER_H
+#define ARTSPLAYER_H
+
+#include <config.h>
+#include <kdemacros.h>
+#include "kdeexportfix.h"
+
+#include "player.h"
+
+#include <kurl.h>
+
+#include <qstring.h>
+#include <qobject.h>
+#include <artsflow.h>
+
+class KArtsDispatcher;
+class KArtsServer;
+class KAudioManagerPlay;
+
+namespace KDE {
+ class PlayObjectFactory;
+ class PlayObject;
+}
+
+class KDE_EXPORT ArtsPlayer : public Player
+{
+ Q_OBJECT
+
+public:
+ ArtsPlayer(QObject* parent = 0, const char* name = 0, const QStringList& args=QStringList());
+ ~ArtsPlayer();
+
+// virtual void play(const FileHandle &file = FileHandle::null());
+ virtual void startPlay(const QString& file);
+ virtual void pause();
+ virtual void stop();
+
+ virtual void setVolume(float volume = 1.0);
+ virtual float volume() const;
+
+ virtual bool playing() const;
+ virtual bool paused() const;
+
+ virtual int totalTime() const;
+ virtual int currentTime() const;
+ virtual int position() const; // in this case not really the percent
+
+ virtual void seek(int seekTime);
+ virtual void seekPosition(int position);
+
+private slots:
+ void setupArtsObjects();
+ void playObjectCreated();
+
+private:
+ void setupPlayer();
+ void setupVolumeControl();
+ bool serverRunning() const;
+
+ KArtsDispatcher *m_dispatcher;
+ KArtsServer *m_server;
+ KDE::PlayObjectFactory *m_factory;
+ KDE::PlayObject *m_playobject;
+ KAudioManagerPlay *m_amanPlay;
+
+ // This is a pretty heavy module for the needs that JuK has, it would probably
+ // be good to use two Synth_MUL instead or the one from Noatun.
+
+ Arts::StereoVolumeControl m_volumeControl;
+
+ KURL m_currentURL;
+ float m_currentVolume;
+};
+
+#endif
+
+// vim: sw=4 ts=8 et
diff --git a/kttsd/players/artsplayer/artsplugin.cpp b/kttsd/players/artsplayer/artsplugin.cpp
new file mode 100644
index 0000000..36f4517
--- /dev/null
+++ b/kttsd/players/artsplayer/artsplugin.cpp
@@ -0,0 +1,29 @@
+/***************************************************** vim:set ts=4 sw=4 sts=4:
+ Generating the factories so aRts can be used as an audio plug in.
+ -------------------
+ Copyright:
+ (C) 2004 by Gary Cramblitt <garycramblitt@comcast.net>
+ -------------------
+ Original author: Gary Cramblitt <garycramblitt@comcast.net>
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ******************************************************************************/
+
+#include <kgenericfactory.h>
+
+#include "artsplayer.h"
+
+K_EXPORT_COMPONENT_FACTORY( libkttsd_artsplugin, KGenericFactory<ArtsPlayer>("kttsd_arts") )
+
diff --git a/kttsd/players/artsplayer/kttsd_artsplugin.desktop b/kttsd/players/artsplayer/kttsd_artsplugin.desktop
new file mode 100644
index 0000000..9eef151
--- /dev/null
+++ b/kttsd/players/artsplayer/kttsd_artsplugin.desktop
@@ -0,0 +1,91 @@
+[Desktop Entry]
+Name=KTTSD Arts Plugin
+Name[br]=Lugent Arts evit KTTSD
+Name[bs]=KTTSD Arts dodatak
+Name[ca]=Connector Arts pel KTTSD
+Name[cs]=KTTSD Arts modul
+Name[da]=KTTSD aRts-plugin
+Name[de]=KTTSD Arts-Modul
+Name[el]=KTTSD πρόσθετο Arts
+Name[es]=Complemento KTTSD Arts
+Name[et]=KTTSD Artsi plugin
+Name[eu]=KTTSD-ren Arts-plugina
+Name[fa]=وصلۀ KTTSD Arts
+Name[fi]=KTTSD Arts -liitännäinen
+Name[fr]=Module Arts pour KTTSD
+Name[ga]=Breiseán KTTSD Arts
+Name[gl]=Plugin Arts de KTTSD
+Name[hu]=KTTSD aRts hangmodul
+Name[is]=KTTSD Arts íforrit
+Name[it]=Plugin per Arts di KTTSD
+Name[ja]=KTTSD aRts プラグイン
+Name[ka]=KTTSD Arts მოდული
+Name[km]=កម្មវិធី​ជំនួយ Arts សម្រាប់ KTTSD
+Name[mk]=aRts-приклучок за KTTSD
+Name[nb]=Arts programtillegg for KTTSD
+Name[nds]=aRts-Moduul för KTTSD
+Name[ne]=KTTSD कला प्लगइन
+Name[nl]=KTTSD Arts-plugin
+Name[pa]=KTTSD Arts ਪਲੱਗਿੰਨ
+Name[pl]=Wtyczka aRts KTTSD
+Name[pt]='Plugin' Arts do KTTSD
+Name[pt_BR]=Plug-in do Arts para o KTTSD
+Name[ru]=Модуль Arts для KTTSD
+Name[sk]=Modul KTTSD Arts
+Name[sl]=Vstavek KTTSD za aRts
+Name[sr]=Arts као прикључак за KTTSD
+Name[sr@Latn]=Arts kao priključak za KTTSD
+Name[sv]=KTTSD-insticksprogram för aRts
+Name[ta]=KTTSD ஆர்ட்ஸ் சொருகுப்பொருள்
+Name[tg]=Модули Arts барои KTTSD
+Name[tr]=KTTSD Arts Eklentisi
+Name[uk]=Втулок Arts для KTTSD
+Name[vi]=Trình bổ sung KTTSD Arts
+Name[zh_TW]=KTTSd Arts 外掛程式
+Comment=KTTSD aRts audio plugin
+Comment[bg]=Аудио приставка на KTTSD за aRts
+Comment[br]=Lugent klevet Arts evit KTTSD
+Comment[ca]=Connector d'àudio aRts pel KTTSD
+Comment[cs]=KTTSD aRts zvukový modul
+Comment[da]=KTTSD aRts lyd-plugin
+Comment[de]=KTTSD aRts Audio-Modul
+Comment[el]=KTTSD πρόσθετο ήχου aRts
+Comment[es]=Complemento de audio KTTSD aRts
+Comment[et]=KTTSD aRts'i audioplugin
+Comment[eu]=KTTSD-ren aRts audio-plugina
+Comment[fa]=وصلۀ صوتی KTTSD aRts
+Comment[fi]=KTTSD aRts ääniliitännäinen
+Comment[fr]=Module audio Arts pour KTTSD
+Comment[ga]=Breiseán fuaime KTTSD aRts
+Comment[gl]=Plugin de áudio aRts para KTTSD
+Comment[hu]=KTTSD hangmodul az aRts hangrendszerhez
+Comment[is]=KTTSD aRts hljóð íforrit
+Comment[it]=Plugin audio per aRts di KTTSD
+Comment[ja]=KTTSD aRts オーディオプラグイン
+Comment[ka]=KTTSD aRts აუდიო მოდული
+Comment[km]=កម្មវិធី​ជំនួយ​អូឌីយ៉ូ aRts សម្រាប់ KTTSD
+Comment[mk]=aRts-аудиоприклучок за KTTSD
+Comment[ms]=Plugin audio aRts KTTSD
+Comment[nb]=aRts lyd-programtillegg for KTTSD
+Comment[nds]=aRts-Audiomoduul för KTTSD
+Comment[ne]=KTTSD कला अडियो प्लगइन
+Comment[nl]=KTTSD aRts-audioplugin
+Comment[pa]=KTTSD aRts ਆਡੀਓ ਪਲੱਗਿੰਨ
+Comment[pl]=Wtyczka dźwięku aRts dla KTTSD
+Comment[pt]='Plugin' áudio aRts do KTTSD
+Comment[pt_BR]=Plug-in de áudio do Arts para o KTTSD
+Comment[ru]=Модуль вывода звука KTTSD через aRts
+Comment[sk]=Modul KTTSD aRts audio
+Comment[sl]=Vstavek KTTSD za zvok v aRts
+Comment[sr]=Arts као аудио прикључак за KTTSD
+Comment[sr@Latn]=Arts kao audio priključak za KTTSD
+Comment[sv]=KTTSD-ljudinsticksprogram för aRts
+Comment[ta]=KTTSD aRts கேட்பொலி சொருகுப்பொருள்
+Comment[tg]=Модули барориши овози KTTSD ба воситаи aRts
+Comment[tr]=KTTSD aRts ses eklentisi
+Comment[uk]=Звуковий втулок aRts для KTTSD
+Comment[vi]=Trình bổ sung âm thanh KTTSD aRts
+Comment[zh_TW]=KTTSd aRts 語音外掛程式
+Type=Service
+ServiceTypes=KTTSD/AudioPlugin
+X-KDE-Library=libkttsd_artsplugin
diff --git a/kttsd/players/gstplayer/Makefile.am b/kttsd/players/gstplayer/Makefile.am
new file mode 100644
index 0000000..df00c55
--- /dev/null
+++ b/kttsd/players/gstplayer/Makefile.am
@@ -0,0 +1,30 @@
+# Include paths. INCLUDES is maintained by KDevelop, AM_CPPFLAGS is the preferred variable,
+# so keep them synchronized.
+INCLUDES = \
+ $(GST_CFLAGS) \
+ -I$(top_srcdir)/kttsd/libkttsd -I$(top_builddir)/kttsd/libkttsd \
+ $(all_includes)
+
+# Let automoc handle all of the metsource files (moc).
+METASOURCES = AUTO
+
+#########################################################################
+# LIBRARY SECTION
+#########################################################################
+# This is the library that gets installed. It's name is used for all
+# of the other Makefile.am variables.
+kde_module_LTLIBRARIES = libkttsd_gstplugin.la
+
+libkttsd_gstplugin_la_SOURCES = \
+ gstplugin.cpp \
+ gstreamerplayer.cpp
+libkttsd_gstplugin_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) $(LDFLAGS_GST) -no-undefined
+libkttsd_gstplugin_la_LIBADD = $(top_builddir)/kttsd/libkttsd/libkttsd.la $(LDADD_GST)
+
+# Header files that should not be installed.
+noinst_HEADERS = \
+ gstreamerplayer.h
+
+# This library is installed as a plugin.
+services_DATA = kttsd_gstplugin.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kttsd/players/gstplayer/gstplugin.cpp b/kttsd/players/gstplayer/gstplugin.cpp
new file mode 100644
index 0000000..633bff9
--- /dev/null
+++ b/kttsd/players/gstplayer/gstplugin.cpp
@@ -0,0 +1,29 @@
+/***************************************************** vim:set ts=4 sw=4 sts=4:
+ Generating the factories so that GStreamer can be used as and audio plug in.
+ -------------------
+ Copyright:
+ (C) 2004 by Gary Cramblitt <garycramblitt@comcast.net>
+ -------------------
+ Original author: Gary Cramblitt <garycramblitt@comcast.net>
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ******************************************************************************/
+
+#include <kgenericfactory.h>
+
+#include "gstreamerplayer.h"
+
+K_EXPORT_COMPONENT_FACTORY( libkttsd_gstplugin, KGenericFactory<GStreamerPlayer>("kttsd_gst") );
+
diff --git a/kttsd/players/gstplayer/gstreamerplayer.cpp b/kttsd/players/gstplayer/gstreamerplayer.cpp
new file mode 100644
index 0000000..64aa1c4
--- /dev/null
+++ b/kttsd/players/gstplayer/gstreamerplayer.cpp
@@ -0,0 +1,258 @@
+/***************************************************************************
+ copyright : (C) 2004 Scott Wheeler
+ email : wheeler@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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+// Qt includes.
+#include <qfile.h>
+
+// KDE includes.
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kglobal.h>
+#include <kdebug.h>
+
+// GStreamerPlayer includes.
+#include "gstreamerplayer.h"
+#include "gstreamerplayer.moc"
+
+////////////////////////////////////////////////////////////////////////////////
+// public methods
+////////////////////////////////////////////////////////////////////////////////
+
+GStreamerPlayer::GStreamerPlayer(QObject* parent, const char* name, const QStringList& args) :
+ Player(parent, name, args),
+ m_initialized(false),
+ m_pipeline(0),
+ m_source(0),
+ m_decoder(0),
+ m_volume(0),
+ m_sink(0)
+{
+ // readConfig();
+ setupPipeline();
+}
+
+GStreamerPlayer::~GStreamerPlayer()
+{
+ stop();
+ gst_object_unref(GST_OBJECT(m_pipeline));
+}
+
+//void GStreamerPlayer::play(const FileHandle &file)
+void GStreamerPlayer::startPlay(const QString &file)
+{
+ if(!file.isNull()) {
+ stop();
+ // g_object_set(G_OBJECT(m_source), "location", file.absFilePath().local8Bit().data(), 0);
+ g_object_set(G_OBJECT(m_source),"location",file.local8Bit().data(),NULL);
+ }
+
+ gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
+}
+
+void GStreamerPlayer::pause()
+{
+ gst_element_set_state(m_pipeline, GST_STATE_PAUSED);
+}
+
+void GStreamerPlayer::stop()
+{
+ gst_element_set_state(m_pipeline, GST_STATE_NULL);
+}
+
+void GStreamerPlayer::setVolume(float volume)
+{
+ g_object_set(G_OBJECT(m_volume), "volume", volume, NULL);
+}
+
+float GStreamerPlayer::volume() const
+{
+ gfloat value;
+ g_object_get(G_OBJECT(m_volume), "volume", &value, NULL);
+ return value;
+}
+
+bool GStreamerPlayer::playing() const
+{
+ return gst_element_get_state(m_pipeline) == GST_STATE_PLAYING;
+}
+
+bool GStreamerPlayer::paused() const
+{
+ return gst_element_get_state(m_pipeline) == GST_STATE_PAUSED;
+}
+
+int GStreamerPlayer::totalTime() const
+{
+ return time(GST_QUERY_TOTAL) / GST_SECOND;
+}
+
+int GStreamerPlayer::currentTime() const
+{
+ return time(GST_QUERY_POSITION) / GST_SECOND;
+}
+
+int GStreamerPlayer::position() const
+{
+ long long total = time(GST_QUERY_TOTAL);
+ long long current = time(GST_QUERY_POSITION);
+ return total > 0 ? int((double(current) / double(total)) * double(1000) + 0.5) : 0;
+}
+
+void GStreamerPlayer::seek(int seekTime)
+{
+ int type = (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH);
+ gst_element_seek(m_sink, GstSeekType(type), seekTime * GST_SECOND);
+}
+
+void GStreamerPlayer::seekPosition(int position)
+{
+ long long total = time(GST_QUERY_TOTAL);
+ if(total > 0)
+ seek(int(double(position) / double(1000) * double(totalTime()) + 0.5));
+}
+
+/**
+ * Returns a list of GStreamer plugins of the specified class.
+ * @param classname Desired class. Use "Sink/Audio" for sinks.
+ * @return List of plugin names.
+ */
+QStringList GStreamerPlayer::getPluginList( const QCString& classname )
+{
+ GList * pool_registries = NULL;
+ GList* registries = NULL;
+ GList* plugins = NULL;
+ GList* features = NULL;
+ QString name;
+ QStringList results;
+
+ if(!m_initialized) {
+ int argc = kapp->argc();
+ char **argv = kapp->argv();
+ gst_init(&argc, &argv);
+ m_initialized = true;
+ }
+
+ pool_registries = gst_registry_pool_list ();
+ registries = pool_registries;
+
+ while ( registries ) {
+ GstRegistry * registry = GST_REGISTRY ( registries->data );
+ plugins = registry->plugins;
+
+ while ( plugins ) {
+ GstPlugin * plugin = GST_PLUGIN ( plugins->data );
+ features = gst_plugin_get_feature_list ( plugin );
+
+ while ( features ) {
+ GstPluginFeature * feature = GST_PLUGIN_FEATURE ( features->data );
+
+ if ( GST_IS_ELEMENT_FACTORY ( feature ) ) {
+ GstElementFactory * factory = GST_ELEMENT_FACTORY ( feature );
+
+ if ( g_strrstr ( factory->details.klass, classname ) ) {
+ name = g_strdup ( GST_OBJECT_NAME ( factory ) );
+ if ( name != "artsdsink" ) results << name;
+ }
+ }
+ features = g_list_next ( features );
+ }
+ plugins = g_list_next ( plugins );
+ }
+ registries = g_list_next ( registries );
+ }
+ g_list_free ( pool_registries );
+ pool_registries = NULL;
+
+ return results;
+}
+
+bool GStreamerPlayer::requireVersion(uint major, uint minor, uint micro)
+{
+ guint gmajor, gminor, gmicro;
+
+ if(!m_initialized) {
+ int argc = kapp->argc();
+ char **argv = kapp->argv();
+ gst_init(&argc, &argv);
+ m_initialized = true;
+ }
+
+ gst_version(&gmajor, &gminor, &gmicro);
+ // kdDebug() << QString("GStreamerPlayer::requireVersion: You have gstreamer %1.%2.%3 installed.").arg(gmajor).arg(gminor).arg(gmicro) << endl;
+ if (gmajor > major) return true;
+ if (gminor > minor) return true;
+ if (gmicro >= micro) return true;
+ kdDebug() << QString("GStreamerPlayer::requireVersion: You have gstreamer %1.%2.%3 installed.").arg(gmajor).arg(gminor).arg(gmicro) << endl;
+ kdDebug() << QString("GStreamerPlayer::requireVersion: This application requires %1.%2.%3 or greater.").arg(major).arg(minor).arg(micro) << endl;
+ return false;
+}
+
+void GStreamerPlayer::setSinkName(const QString &sinkName) { m_sinkName = sinkName; }
+
+////////////////////////////////////////////////////////////////////////////////
+// private methods
+////////////////////////////////////////////////////////////////////////////////
+
+void GStreamerPlayer::readConfig()
+{
+ KConfigGroup config(KGlobal::config(), "GStreamerPlayer");
+ m_sinkName = config.readEntry("SinkName", QString::null);
+}
+
+void GStreamerPlayer::setupPipeline()
+{
+ if(!m_initialized) {
+ int argc = kapp->argc();
+ char **argv = kapp->argv();
+ gst_init(&argc, &argv);
+ m_initialized = true;
+ }
+
+ m_pipeline = gst_thread_new("pipeline");
+ m_source = gst_element_factory_make("filesrc", "source");
+ m_decoder = gst_element_factory_make("spider", "decoder");
+ m_volume = gst_element_factory_make("volume", "volume");
+
+ if(!m_sinkName.isNull())
+ m_sink = gst_element_factory_make(m_sinkName.utf8().data(), "sink");
+ if (!m_sink)
+ {
+ // m_sink = gst_element_factory_make("alsasink", "sink");
+ // if(!m_sink)
+ // m_sink = gst_element_factory_make("osssink", "sink");
+
+ // Reversing order. OSS seems to work. Alsa sink produces ugly echo of last
+ // couple of words in each wav file. argh!
+ // kdDebug() << "GStreamerPlayer::setupPipeline: trying oss sink." << endl;
+ m_sink = gst_element_factory_make("osssink", "sink");
+ if(!m_sink)
+ {
+ // kdDebug() << "GStreamerPlayer::setupPipeline: reverting to alsa sink." << endl;
+ m_sink = gst_element_factory_make("alsasink", "sink");
+ }
+ }
+
+ gst_bin_add_many(GST_BIN(m_pipeline), m_source, m_decoder, m_volume, m_sink, 0);
+ gst_element_link_many(m_source, m_decoder, m_volume, m_sink, 0);
+}
+
+long long GStreamerPlayer::time(GstQueryType type) const
+{
+ gint64 ns = 0;
+ GstFormat format = GST_FORMAT_TIME;
+ gst_element_query(m_sink, type, &format, &ns);
+ return ns;
+}
+
+// vim: set et sw=4:
diff --git a/kttsd/players/gstplayer/gstreamerplayer.h b/kttsd/players/gstplayer/gstreamerplayer.h
new file mode 100644
index 0000000..6a7f1d6
--- /dev/null
+++ b/kttsd/players/gstplayer/gstreamerplayer.h
@@ -0,0 +1,76 @@
+/***************************************************************************
+ copyright : (C) 2004 Scott Wheeler
+ email : wheeler@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 *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef GSTREAMERPLAYER_H
+#define GSTREAMERPLAYER_H
+
+#include "config.h"
+
+#include <glib.h>
+extern "C" {
+#include <gst/gstversion.h>
+}
+#include <gst/gst.h>
+#include <qstring.h>
+#include "player.h"
+
+class GStreamerPlayer : public Player
+{
+ Q_OBJECT
+
+public:
+ GStreamerPlayer(QObject* parent = 0, const char* name = 0, const QStringList& args=QStringList());
+ virtual ~GStreamerPlayer();
+
+ // virtual void play(const FileHandle &file = FileHandle::null());
+ virtual void startPlay(const QString& file);
+
+ virtual void setVolume(float volume = 1.0);
+ virtual float volume() const;
+
+ virtual bool playing() const;
+ virtual bool paused() const;
+
+ virtual int totalTime() const;
+ virtual int currentTime() const;
+ virtual int position() const; // in this case not really the percent
+
+ virtual void seek(int seekTime);
+ virtual void seekPosition(int position);
+
+ virtual QStringList getPluginList( const QCString& classname );
+ virtual void setSinkName(const QString &sinkName);
+
+ virtual bool requireVersion(uint major, uint minor, uint micro);
+
+ void pause();
+ void stop();
+
+private:
+ void readConfig();
+ void setupPipeline();
+ long long time(GstQueryType type) const;
+
+ QString m_sinkName;
+ // True once gst_init() has been called.
+ bool m_initialized;
+
+ GstElement *m_pipeline;
+ GstElement *m_source;
+ GstElement *m_decoder;
+ GstElement *m_volume;
+ GstElement *m_sink;
+};
+
+#endif
diff --git a/kttsd/players/gstplayer/kttsd_gstplugin.desktop b/kttsd/players/gstplayer/kttsd_gstplugin.desktop
new file mode 100644
index 0000000..7646cee
--- /dev/null
+++ b/kttsd/players/gstplayer/kttsd_gstplugin.desktop
@@ -0,0 +1,92 @@
+[Desktop Entry]
+Name=KTTSD GStreamer Plugin
+Name[br]=Lugent KTTSD GStreamer
+Name[bs]=KTTSD GStreamer dodatak
+Name[ca]=Connector GStreamer pel KTTSD
+Name[cs]=KTTSD GStreamer modul
+Name[da]=KTTSD GStreamer-plugin
+Name[de]=KTTSD GStreamer-Modul
+Name[el]=KTTSD πρόσθετο GStreamer
+Name[es]=Complemento KTTSD GStreamer
+Name[et]=KTTSD GStreameri plugin
+Name[eu]=KTTSD-ren GStreamer plugina
+Name[fa]=وصلۀ KTTSD GStreamer
+Name[fi]=KTTSD GStreamer-liitännäinen
+Name[fr]=Module GStreamer pour KTTSD
+Name[ga]=Breiseán KTTSD GStreamer
+Name[gl]=Plugin GStreamer de KTTSD
+Name[hu]=KTTSD GStreamer-modul
+Name[is]=KTTSD GStreamer íforrit
+Name[it]=Plugin per GStreamer di KTTSD
+Name[ja]=KTTSD GStreamer プラグイン
+Name[ka]=KTTSD GStreamer მოდული
+Name[km]= កម្មវិធី​ជំនួយ GStreamer សម្រាប់ KTTSD
+Name[mk]=GStreamer-приклучок за KTTSD
+Name[ms]=Plugin KTTSD GStreamer
+Name[nb]=GStreamer programtillegg for KTTSD
+Name[nds]=GStreamer-Moduul för KTTSD
+Name[ne]=KTTSD जि स्ट्रिमर प्लगइन
+Name[nl]=KTTSD GStreamer-plugin
+Name[pa]=KTTSD ਜੀਸਟਰੀਮਰ ਪਲੱਗਿੰਨ
+Name[pl]=Wtyczka GStreamer KTTSD
+Name[pt]='Plugin' GStreamer do KTTSD
+Name[pt_BR]=Plug-in do GStreamer para o KTTSD
+Name[ru]=Модуль GStreamer для KTTSD
+Name[sk]=Modul KTTSD GStreamer
+Name[sl]=Vstavek KTTSD za GStreamer
+Name[sr]=GStreamer као прикључак за KTTSD
+Name[sr@Latn]=GStreamer kao priključak za KTTSD
+Name[sv]=KTTSD-insticksprogram för Gstreamer
+Name[ta]=KTTSD GStreamer சொருகுப்பொருள்
+Name[tg]=Модули GStreamer барои KTTSD
+Name[tr]=KTTSD GStreamer Eklentisi
+Name[uk]=Втулок GStreamer для KTTSD
+Name[vi]=Trình bổ sung KTTSD GStreamer
+Name[zh_TW]=KTTSd GStreamer 外掛程式
+Comment=KTTSD GStreamer audio plugin
+Comment[bg]=Аудио приставка на KTTSD за GStreamer
+Comment[br]=Lugent klevet GStreamer evit KTTSD
+Comment[ca]=Connector d'àudio GStreamer pel KTTSD
+Comment[cs]=KTTSD GStreamer zvukový modul
+Comment[da]=KTTSD GStreamer lyd-plugin
+Comment[de]=KTTSD GStreamer Audio-Modul
+Comment[el]=KTTSD πρόσθετο ήχου GStreamer
+Comment[es]=Complemento de audio KTTSD GStreamer
+Comment[et]=KTTSD GStreameri audioplugin
+Comment[eu]=KTTSD-ren GStreamer audio-plugina
+Comment[fa]=وصلۀ صوتی KTTSD GStreamer
+Comment[fi]=KTTSD GStreamer ääniliitännäinen
+Comment[fr]=Module audio GStreamer pour KTTSD
+Comment[ga]=Breiseán fuaime GStreamer KTTSD
+Comment[gl]=Plugin de áudio GStreamer para KTTSD
+Comment[hu]=KTTSD hangmodul a GStreamerhez
+Comment[is]=KTTSD GStreamer hljóð íforrit
+Comment[it]=Plugin audio per GStreamer di KTTSD
+Comment[ja]=KTTSD GStreamer オーディオプラグイン
+Comment[ka]=KTTSD GStreamer აუდიო მოდული
+Comment[km]=កម្មវិធី​ជំនួយអូឌីយ៉ូ​ GStreamer សម្រាប់ KTTSD
+Comment[mk]=GStreamer-аудиоприклучок за KTTSD
+Comment[ms]=Plugin audio KTTSD GStreamer
+Comment[nb]=GStreamer lyd-programtillegg for KTTSD
+Comment[nds]=GStreamer-Audiomoduul för KTTSD
+Comment[ne]=KTTSD जि स्ट्रिमर अडियो प्लगइन
+Comment[nl]=KTTSD GStreamer-audioplugin
+Comment[pa]=KTTSD ਜੀਸਟਰੀਮਰ ਆਡੀਓ ਪਲੱਗਿੰਨ
+Comment[pl]=Wtyczka dźwięku GStreamer dla KTTSD
+Comment[pt]='Plugin' áudio GStreamer do KTTSD
+Comment[pt_BR]=Plug-in de áudio do GStreamer para o KTTSD
+Comment[ru]=Модуль вывода звука KTTSD через GStreamer
+Comment[sk]=Modul KTTSD GStreamer audio
+Comment[sl]=Vstavek KTTSD za zvok v GStreamer
+Comment[sr]=GStreamer као аудио прикључак за KTTSD
+Comment[sr@Latn]=GStreamer kao audio priključak za KTTSD
+Comment[sv]=KTTSD-ljudinsticksprogram för Gstreamer
+Comment[ta]=KTTSD GStreamer கேட்பொலி சொருகுப்பொருள்
+Comment[tg]=Модули барориши овози KTTSD ба воситаи GStreamer
+Comment[tr]= KTTSD GStreamer ses eklentisi
+Comment[uk]=Звуковий втулок GStreamer для KTTSD
+Comment[vi]=Trình bổ sung âm thanh KTTSD GStreamer
+Comment[zh_TW]=KTTSd GStreamer 語音外掛程式
+Type=Service
+ServiceTypes=KTTSD/AudioPlugin
+X-KDE-Library=libkttsd_gstplugin
diff --git a/kttsd/players/kttsd_audioplugin.desktop b/kttsd/players/kttsd_audioplugin.desktop
new file mode 100644
index 0000000..ae39e7c
--- /dev/null
+++ b/kttsd/players/kttsd_audioplugin.desktop
@@ -0,0 +1,47 @@
+[Desktop Entry]
+Type=ServiceType
+X-KDE-ServiceType=KTTSD/AudioPlugin
+Comment=Audio Plugin for KTTSD
+Comment[bg]=Аудио приставка на KTTSD
+Comment[br]=Lugent klevet evit KTTSD
+Comment[ca]=Connector d'àudio pel KTTSD
+Comment[cs]=Zvukový modul KTTSD
+Comment[da]=Lyd-plugin for KTTSD
+Comment[de]=Audio-Modul für KTTSD
+Comment[el]=Πρόσθετο ήχου για το KTTSD
+Comment[es]=Complemento de audio para KTTSD
+Comment[et]=KTTSD audioplugin
+Comment[eu]=KTTSD-ren audio plugnka
+Comment[fa]=وصلۀ صوتی برای KTTSD
+Comment[fi]=Ääniliitännäinen KTTSD-ohjelmalle
+Comment[fr]=Module audio pour KTTSD
+Comment[ga]=Breiseán fuaime KTTSD
+Comment[gl]=Plugin de Áudio para KTTSD
+Comment[hu]=Hangmodul a KTTSD szolgáltatáshoz
+Comment[is]=Hljóð íforrit fyrir KTTSD
+Comment[it]=Plugin audio per KTTSD
+Comment[ja]=KTTSD 用オーディオプラグイン
+Comment[ka]=აუდიო მოდული KTTSD-თვის
+Comment[km]=​កម្មវិធី​ជំនួយ​អូឌីយ៉ូ​សម្រាប់​ KTTSD
+Comment[mk]=Аудиоприклучок за KTTSD
+Comment[ms]=Plugin Audio bagi KTTSD
+Comment[nb]=Lyd-programtillegg for KTTSD
+Comment[nds]=Audiomoduul för KTTSD
+Comment[ne]=KTTSD का लागि अडियो प्लगइन
+Comment[nl]=Audio-plugin voor KTTSD
+Comment[pa]=KTTSD ਲਈ ਆਡੀਓ ਪਲੱਗਿੰਨ
+Comment[pl]=Wtyczka dźwięku dla KTTSD
+Comment[pt]='Plugin' Áudio para o KTTSD
+Comment[pt_BR]=Plug-in de áudio para o KTTSD
+Comment[ru]=Модуль вывода звука KTTSD
+Comment[sk]=Audio modul pre KTTSD
+Comment[sl]=Vstavek KTTSD za zvok
+Comment[sr]=Аудио прикључак за KTTSD
+Comment[sr@Latn]=Audio priključak za KTTSD
+Comment[sv]=Ljudinsticksprogram för KTTSD
+Comment[ta]= KTTSDக்கான கேட்பொலி சொருகுப்பொருள்
+Comment[tg]=Модули барориши овози KTTSD
+Comment[tr]=KTTS için Ses Eklentisi
+Comment[uk]=Звуковий втулок для KTTSD
+Comment[vi]=Trình bổ sung Âm thanh cho KTTSD
+Comment[zh_TW]=KTTSd 語音外掛程式