[SCM] clalsadrv packaging branch, master, updated. upstream/2.0.0
quadrispro-guest at users.alioth.debian.org
quadrispro-guest at users.alioth.debian.org
Thu Mar 18 18:46:15 UTC 2010
The following commit has been merged in the master branch:
commit 9a8add5c4bbc47639fab74fef007bb8b734e3669
Author: Alessio Treglia <quadrispro at ubuntu.com>
Date: Thu Mar 18 19:26:06 2010 +0100
Imported Upstream version 2.0.0
diff --git a/AUTHORS b/AUTHORS
index e3a24a0..10a30ad 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1 +1 @@
-Fons Adriaensen <fons.adriaensen at skynet.be>
+Fons Adriaensen <fons at kokkinizita.net>
diff --git a/INSTALL b/INSTALL
index 7652a50..464ab07 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,6 +1,8 @@
-To make and install the library, cd to this directory, su root,
-and 'make install'. This will install the lib and header file in
-/usr/lib and /usr/include.
+To make and install the library, cd to the libs directory, make,
+sudo make install. This will install the lib and header file in
+/usr/local/lib and /usr/local/include.
-To install to other directories, see the Makefile.
+To make and install the loopback and latency test programs, cd to
+the apps directory, make, sudo make install. This will install the
+test applications in /usr/local/bin.
diff --git a/apps/Makefile b/apps/Makefile
new file mode 100644
index 0000000..530ee65
--- /dev/null
+++ b/apps/Makefile
@@ -0,0 +1,51 @@
+# Copyright (C) 2003-2010 Fons Adriaensen <fons at kokkinizita.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+PREFIX = /usr/local
+SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
+LIBDIR = lib$(SUFFIX)
+LDFLAGS += -L$(PREFIX)/$(LIBDIR)
+CPPFLAGS += -O2 -Wall -MMD -MP -DVERSION=\"$(VERSION)\"
+
+
+all: alsa-loopback alsa-latency
+
+
+LOOPBACK_O = loopback.o
+alsa-loopback: LDLIBS += -lclthreads -lclalsadrv -lpthread -lrt
+alsa-loopback: $(LOOPBACK_O)
+ g++ $(LDFLAGS) -o $@ $(LOOPBACK_O) $(LDLIBS)
+$(LOOPBACK_O):
+-include $(LOOPBACK_O:%.o=%.d)
+
+
+LATENCY_O = latency.o
+alsa-latency: LDLIBS += -lclthreads -lclalsadrv -lpthread -lrt
+alsa-latency: $(LATENCY_O)
+ g++ $(LDFLAGS) -o $@ $(LATENCY_O) $(LDLIBS)
+$(LATENCY_O):
+-include $(LATENCY_O:%.o=%.d)
+
+
+install: all
+ install -Dm 755 alsa-loopback $(DESTDIR)$(PREFIX)/bin/alsa-loopback
+ install -Dm 755 alsa-latency $(DESTDIR)$(PREFIX)/bin/alsa-latency
+
+
+clean:
+ /bin/rm -f *~ *.o *.a *.d *.so alsa-loopback alsa-latency
+
diff --git a/apps/latency.cc b/apps/latency.cc
new file mode 100644
index 0000000..45e34d8
--- /dev/null
+++ b/apps/latency.cc
@@ -0,0 +1,285 @@
+/*
+ Copyright (C) 2010 Fons Adriaensen <fons at kokkinizita.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <clthreads.h>
+#include <clalsadrv.h>
+
+
+// --------------------------------------------------------------------------------
+
+
+class Freq
+{
+public:
+
+ int p;
+ int f;
+ float a;
+ float xa;
+ float ya;
+ float xf;
+ float yf;
+};
+
+
+class MTDM
+{
+public:
+
+ MTDM (void);
+ int process (size_t len, float *inp, float *out);
+ int resolve (void);
+ void invert (void) { _inv ^= 1; }
+ int inv (void) { return _inv; }
+ double del (void) { return _del; }
+ double err (void) { return _err; }
+
+private:
+
+ double _del;
+ double _err;
+ int _cnt;
+ int _inv;
+ Freq _freq [5];
+};
+
+
+MTDM::MTDM (void) : _cnt (0), _inv (0)
+{
+ int i;
+ Freq *F;
+
+ _freq [0].f = 4096;
+ _freq [1].f = 512;
+ _freq [2].f = 1088;
+ _freq [3].f = 1544;
+ _freq [4].f = 2049;
+
+ _freq [0].a = 0.2f;
+ _freq [1].a = 0.1f;
+ _freq [2].a = 0.1f;
+ _freq [3].a = 0.1f;
+ _freq [4].a = 0.1f;
+
+ for (i = 0, F = _freq; i < 5; i++, F++)
+ {
+ F->p = 128;
+ F->xa = F->ya = 0.0f;
+ F->xf = F->yf = 0.0f;
+ }
+}
+
+
+int MTDM::process (size_t len, float *ip, float *op)
+{
+ int i;
+ float vip, vop, a, c, s;
+ Freq *F;
+
+ while (len--)
+ {
+ vop = 0.0f;
+ vip = *ip++;
+ for (i = 0, F = _freq; i < 5; i++, F++)
+ {
+ a = 2 * (float) M_PI * (F->p & 65535) / 65536.0;
+ F->p += F->f;
+ c = cosf (a);
+ s = -sinf (a);
+ vop += F->a * s;
+ F->xa += s * vip;
+ F->ya += c * vip;
+ }
+ *op++ = vop;
+ if (++_cnt == 16)
+ {
+ for (i = 0, F = _freq; i < 5; i++, F++)
+ {
+ F->xf += 1e-3f * (F->xa - F->xf + 1e-20);
+ F->yf += 1e-3f * (F->ya - F->yf + 1e-20);
+ F->xa = F->ya = 0.0f;
+ }
+ _cnt = 0;
+ }
+ }
+
+ return 0;
+}
+
+
+int MTDM::resolve (void)
+{
+ int i, k, m;
+ double d, e, f0, p;
+ Freq *F = _freq;
+
+ if (hypot (F->xf, F->yf) < 0.01) return -1;
+ d = atan2 (F->yf, F->xf) / (2 * M_PI);
+ if (_inv) d += 0.5f;
+ if (d > 0.5f) d -= 1.0f;
+ f0 = _freq [0].f;
+ m = 1;
+ _err = 0.0;
+ for (i = 0; i < 4; i++)
+ {
+ F++;
+ p = atan2 (F->yf, F->xf) / (2 * M_PI) - d * F->f / f0;
+ if (_inv) p += 0.5f;
+ p -= floor (p);
+ p *= 8;
+ k = (int)(floor (p + 0.5));
+ e = fabs (p - k);
+ if (e > _err) _err = e;
+ if (e > 0.4) return 1;
+ d += m * (k & 7);
+ m *= 8;
+ }
+ _del = 16 * d;
+
+ return 0;
+}
+
+
+// --------------------------------------------------------------------------------
+
+
+static char playdev [256];
+static char captdev [256];
+static unsigned long fsamp;
+static unsigned long frsize;
+static unsigned long nfrags;
+static MTDM mtdm;
+
+
+class Audiothr : public P_thread
+{
+public:
+
+ virtual void thr_main (void);
+
+private:
+
+ float *ipbuf;
+ float *opbuf;
+};
+
+
+void Audiothr::thr_main (void)
+{
+ Alsa_driver *D;
+ unsigned long k;
+
+ ipbuf = new float [frsize];
+ opbuf = new float [frsize];
+
+ D = new Alsa_driver (playdev, captdev, 0, fsamp, frsize, nfrags);
+ if (D->stat ())
+ {
+ fprintf (stderr, "Can't open ALSA device\n");
+ delete D;
+ return;
+ }
+ D->printinfo ();
+
+ D->pcm_start ();
+ while (1)
+ {
+ k = D->pcm_wait ();
+ while (k >= frsize)
+ {
+ D->capt_init (frsize);
+ D->capt_chan (0, ipbuf, frsize);
+ D->capt_done (frsize);
+
+ mtdm.process (frsize, ipbuf, opbuf);
+
+ D->play_init (frsize);
+ D->play_chan (0, opbuf, frsize);
+ D->play_done (frsize);
+
+ k -= frsize;
+ }
+ }
+ D->pcm_stop ();
+
+ delete D;
+}
+
+
+// --------------------------------------------------------------------------------
+
+
+int main (int ac, char *av [])
+{
+ Audiothr A;
+ float t;
+
+ if (ac < 6)
+ {
+ fprintf (stderr, "alsa-latency <playdev><captdev><fsamp><frsize><nfrags>\n");
+ return 1;
+ }
+
+ strcpy (playdev, av [1]);
+ strcpy (captdev, av [2]);
+ fsamp = atoi (av [3]);
+ frsize = atoi (av [4]);
+ nfrags = atoi (av [5]);
+
+ if (A.thr_start (SCHED_FIFO, -50, 0x20000))
+ {
+ fprintf (stderr, "Can't run in RT mode, trying normal scheduling.\n");
+ if (A.thr_start (SCHED_OTHER, 0, 0x20000))
+ {
+ fprintf (stderr, "Can't start audio thread.\n");
+ return 1;
+ }
+ }
+
+ t = 1000.0f / fsamp;
+ while (1)
+ {
+ usleep (250000);
+
+ if (mtdm.resolve () < 0) printf ("Signal below threshold...\n");
+ else
+ {
+ if (mtdm.err () > 0.3)
+ {
+ mtdm.invert ();
+ mtdm.resolve ();
+ }
+ printf ("%10.3lf frames %10.3lf ms", mtdm.del (), mtdm.del () * t);
+ if (mtdm.err () > 0.2) printf (" ??");
+ if (mtdm.inv ()) printf (" Inv");
+ printf ("\n");
+ }
+ }
+
+ return 0;
+}
+
+
+// --------------------------------------------------------------------------------
+
diff --git a/loopback.cc b/apps/loopback.cc
similarity index 64%
rename from loopback.cc
rename to apps/loopback.cc
index fda136f..c3a945f 100644
--- a/loopback.cc
+++ b/apps/loopback.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2003-2006 Fons Adriaensen <fons.adriaensen at skynet.be>
+ Copyright (C) 2003-2010 Fons Adriaensen <fons at kokkinizita.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
@@ -20,18 +20,21 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <sys/mman.h>
#include <clthreads.h>
#include <clalsadrv.h>
-char name [64];
+// --------------------------------------------------------------------------------
+
+
+char playdev [256];
+char captdev [256];
unsigned long fsamp;
unsigned long frsize;
unsigned long nfrags;
-class Testthr : public P_thread
+class Audiothr : public P_thread
{
public:
@@ -45,7 +48,7 @@ private:
};
-void Testthr::thr_main (void)
+void Audiothr::thr_main (void)
{
Alsa_driver *D;
unsigned long k;
@@ -53,7 +56,7 @@ void Testthr::thr_main (void)
buf0 = new float [frsize];
buf1 = new float [frsize];
- D = new Alsa_driver (name, fsamp, frsize, nfrags, true, true, false);
+ D = new Alsa_driver (playdev, captdev, 0, fsamp, frsize, nfrags);
if (D->stat ())
{
fprintf (stderr, "Can't open ALSA device\n");
@@ -87,23 +90,39 @@ void Testthr::thr_main (void)
}
+// --------------------------------------------------------------------------------
+
+
int main (int ac, char *av [])
{
- Testthr T;
+ Audiothr A;
- if (ac < 5)
+ if (ac < 6)
{
- fprintf (stderr, "loopback <device><fsamp><frsize><nfrags>\n");
+ fprintf (stderr, "alsa-loopback <playdev><captdev><fsamp><frsize><nfrags>\n");
return 1;
}
- strcpy (name, av [1]);
- fsamp = atoi (av [2]);
- frsize = atoi (av [3]);
- nfrags = atoi (av [4]);
+ strcpy (playdev, av [1]);
+ strcpy (captdev, av [2]);
+ fsamp = atoi (av [3]);
+ frsize = atoi (av [4]);
+ nfrags = atoi (av [5]);
+
+ if (A.thr_start (SCHED_FIFO, -50, 0x20000))
+ {
+ fprintf (stderr, "Can't run in RT mode, trying normal scheduling.\n");
+ if (A.thr_start (SCHED_OTHER, 0, 0x20000))
+ {
+ fprintf (stderr, "Can't start audio thread.\n");
+ return 1;
+ }
+ }
- T.thr_start (SCHED_OTHER, 0, 0);
sleep (1000000);
return 0;
}
+
+
+// --------------------------------------------------------------------------------
diff --git a/debian/README.source b/debian/README.source
deleted file mode 100644
index d0a7a50..0000000
--- a/debian/README.source
+++ /dev/null
@@ -1,13 +0,0 @@
-clalsadrv for Debian
----------------
-
- This package uses quilt to manage all modifications to the upstream
- source. Changes are stored in the source package as diffs in
- debian/patches and applied during the build.
-
- To read how to properly use quilt, please refer to the official
- documentation available at:
-
- /usr/share/doc/quilt/README.source
-
- -- Alessio Treglia <quadrispro at ubuntu.com> Wed, 17 Mar 2010 11:34:31 +0100
diff --git a/debian/changelog b/debian/changelog
deleted file mode 100644
index 83f0eec..0000000
--- a/debian/changelog
+++ /dev/null
@@ -1,72 +0,0 @@
-clalsadrv (1.2.2-2) unstable; urgency=low
-
- * Switch to debhelper 7.
- * Replace dpatch with quilt, convert all patches to the quilt format.
- * debian/control:
- - Set maintainer to Debian Multimedia Maintainers.
- - Add myself to the Uploaders list.
- - Set DM-Upload-Allowed to yes.
- - Bump Standards-Version.
- - Add missing macro to libclalsadrv-dev Depends field.
- - Add Homepage field.
- - Adjust Section fields properly.
- - Replace deprecated Source-Version substvar with binary:Version.
- - Improve long description.
- * debian/patches/01-makefile.patch:
- - Create /usr/include, otherwise doesn't install the headers.
- - Add comments as per DEP-3.
- * Remove unnecessary .dirs files, update .install files.
- * Update debian/copyright as per DEP-5 spec.
- * debian/README.source: Document how to patch the sources.
-
- -- Alessio Treglia <quadrispro at ubuntu.com> Wed, 17 Mar 2010 20:29:56 +0100
-
-clalsadrv (1.2.2-1) unstable; urgency=low
-
- * New upstream release
- * Updated watch file and home page in the copyright file
- * Updated makefile.dpatch
-
- -- Free Ekanayaka <freee at debian.org> Thu, 24 May 2007 11:48:58 +0200
-
-clalsadrv (1.1.0+1-1) unstable; urgency=low
-
- * New upstream release
- * Set Maintainer to debian-multimedia
- * Added myself to the uploaders
- * Fixed watch file
-
- -- Free Ekanayaka <freee at debian.org> Sun, 22 Apr 2007 22:15:41 +0200
-
-clalsadrv (1.0.1-3) unstable; urgency=low
-
- * Fixed broken Depends line for libclalsadrv-dev depending on the old
- shared library name
-
- -- Free Ekanayaka <free at agnula.org> Thu, 21 Jul 2005 12:30:21 +0200
-
-clalsadrv (1.0.1-2) unstable; urgency=low
-
- * Rebuilt against the GCC 4.0
- * Changed the library package name to libclalsadrv1, no
- need of the c2 suffix, as the so number (1) was not present
- in the previous package name (was simply libclalsadrv)
- * Conflicts with previous library package name
-
- -- Free Ekanayaka <free at agnula.org> Thu, 7 Jul 2005 10:13:26 +0200
-
-clalsadrv (1.0.1-1) unstable; urgency=low
-
- * New upstream release
- * Fixed watch file
-
- -- Free Ekanayaka <free at agnula.org> Fri, 8 Apr 2005 22:55:07 +0200
-
-clalsadrv (1.0.0-1) unstable; urgency=low
-
- * Initial Release.
- * First Debian upload (closes: #269394), sponsored by
- Cosimo Alfarano <kalfa at debian.org>
-
- -- Free Ekanayaka <free at agnula.org> Wed, 1 Sep 2004 11:55:33 +0200
-
diff --git a/debian/compat b/debian/compat
deleted file mode 100644
index 7f8f011..0000000
--- a/debian/compat
+++ /dev/null
@@ -1 +0,0 @@
-7
diff --git a/debian/control b/debian/control
deleted file mode 100644
index 9ce56e5..0000000
--- a/debian/control
+++ /dev/null
@@ -1,35 +0,0 @@
-Source: clalsadrv
-Section: libs
-Priority: optional
-Maintainer: Debian Multimedia Maintainers <pkg-multimedia-maintainers at lists.alioth.debian.org>
-Uploaders: Free Ekanayaka <freee at debian.org>,
- Alessio Treglia <quadrispro at ubuntu.com>
-DM-Upload-Allowed: yes
-Build-Depends: debhelper (>= 7.0.8~),
- libasound2-dev,
- quilt (>= 0.46-7~)
-Standards-Version: 3.8.4
-Vcs-Git: git://git.debian.org/pkg-multimedia/clalsadrv.git
-Vcs-Browser: http://git.debian.org/?p=pkg-multimedia/clalsadrv.git
-Homepage: http://www.kokkinizita.net/linuxaudio/
-
-Package: libclalsadrv-dev
-Section: libdevel
-Architecture: any
-Depends: libclalsadrv1 (= ${binary:Version}),
- ${misc:Depends}
-Description: ALSA driver C++ access library (development files)
- C++ wrapper around the ALSA API.
- .
- This package includes the development tools.
-
-Package: libclalsadrv1
-Conflicts: libclalsadrv
-Replaces: libclalsadrv
-Architecture: any
-Depends: ${shlibs:Depends},
- ${misc:Depends}
-Description: ALSA driver C++ access library
- C++ wrapper around the ALSA API.
- .
- This package includes the shared library object.
diff --git a/debian/copyright b/debian/copyright
deleted file mode 100644
index 8e8e403..0000000
--- a/debian/copyright
+++ /dev/null
@@ -1,30 +0,0 @@
-Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=142
-Name: clalsadrv
-Maintainer: Fons Adriaensen <fons.adriaensen at skynet.be>
-Source: http://www.kokkinizita.net/linuxaudio/downloads/index.html
-
-Copyright: 2003-2006 Fons Adriaensen <fons.adriaensen at skynet.be>
-License: GPL-2+
-
-Files: debian/*
-Copyright:
- 2010 Alessio Treglia <quadrispro at ubuntu.com>
- 2004-2007 Free Ekanayaka <freee at debian.org>
-License: GPL-2+
-
-License: GPL-2
- This package 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 package 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 package; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-X-Comment: On Debian systems, the complete text of the GNU General
- Public License can be found in `/usr/share/common-licenses/GPL-2'.
diff --git a/debian/dirs b/debian/dirs
deleted file mode 100644
index da07fdd..0000000
--- a/debian/dirs
+++ /dev/null
@@ -1,2 +0,0 @@
-usr/include
-usr/lib
diff --git a/debian/libclalsadrv-dev.install b/debian/libclalsadrv-dev.install
deleted file mode 100644
index e4eede3..0000000
--- a/debian/libclalsadrv-dev.install
+++ /dev/null
@@ -1,2 +0,0 @@
-usr/include/*.h
-usr/lib/lib*.so
diff --git a/debian/libclalsadrv1.install b/debian/libclalsadrv1.install
deleted file mode 100644
index d0dbfd1..0000000
--- a/debian/libclalsadrv1.install
+++ /dev/null
@@ -1 +0,0 @@
-usr/lib/lib*.so.*
diff --git a/debian/patches/01-makefile.patch b/debian/patches/01-makefile.patch
deleted file mode 100644
index d015617..0000000
--- a/debian/patches/01-makefile.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-Author: Free Ekanayaka <freee at debian.org>
-Description: Set PREFIX properly, add DESTDIR var, create /usr/include
- before installing the headers.
----
- Makefile | 6 ++++--
- 1 file changed, 4 insertions(+), 2 deletions(-)
-
---- clalsadrv.orig/Makefile
-+++ clalsadrv/Makefile
-@@ -14,11 +14,12 @@
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-+DESTDIR =
-
- # Modify as required.
- #
--PREFIX = /usr
--SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
-+PREFIX = $(DESTDIR)/usr
-+#SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
- LIBDIR = lib$(SUFFIX)
-
-
-@@ -47,6 +48,7 @@ $(CLALSADRV_MIN): $(CLALSADRV_O)
-
- install: $(CLALSADRV_MIN)
- /usr/bin/install -d $(PREFIX)/$(LIBDIR)
-+ /usr/bin/install -d $(PREFIX)/include
- /usr/bin/install -m 644 $(CLALSADRV_H) $(PREFIX)/include
- /usr/bin/install -m 755 $(CLALSADRV_MIN) $(PREFIX)/$(LIBDIR)
- /sbin/ldconfig -n $(PREFIX)/$(LIBDIR)
diff --git a/debian/patches/series b/debian/patches/series
deleted file mode 100644
index d3b72df..0000000
--- a/debian/patches/series
+++ /dev/null
@@ -1 +0,0 @@
-01-makefile.patch
diff --git a/debian/rules b/debian/rules
deleted file mode 100755
index 749e624..0000000
--- a/debian/rules
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/make -f
-
-%:
- dh --with quilt $@
diff --git a/debian/watch b/debian/watch
deleted file mode 100644
index d90b0f1..0000000
--- a/debian/watch
+++ /dev/null
@@ -1,3 +0,0 @@
-# Site Directory Pattern Version Script
-version=3
-http://www.kokkinizita.net/linuxaudio/downloads/index.html clalsadrv-(.*)\.tar\.bz2
diff --git a/Makefile b/libs/Makefile
similarity index 65%
rename from Makefile
rename to libs/Makefile
index 82cd85b..16f0272 100644
--- a/Makefile
+++ b/libs/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 2003-2006 Fons Adriaensen <fons.adriaensen at skynet.be>
+# Copyright (C) 2003-2010 Fons Adriaensen <fons at kokkinizita.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
@@ -17,18 +17,17 @@
# Modify as required.
#
-PREFIX = /usr
+PREFIX = /usr/local
SUFFIX := $(shell uname -m | sed -e 's/^unknown/$//' -e 's/^i.86/$//' -e 's/^x86_64/$/64/')
LIBDIR = lib$(SUFFIX)
-MAJVERS = 1
-MINVERS = 2.2
+MAJVERS = 2
+MINVERS = 0.0
VERSION = $(MAJVERS).$(MINVERS)
-DISTDIR = clalsadrv-$(VERSION)
-CPPFLAGS += -Wall -I. -fpic -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -O2
+CPPFLAGS += -Wall -I. -fPIC -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -O2
LDLFAGS +=
LDLIBS += -lclalsadrv -lclthreads -lrt
@@ -46,22 +45,11 @@ $(CLALSADRV_MIN): $(CLALSADRV_O)
install: $(CLALSADRV_MIN)
- /usr/bin/install -d $(PREFIX)/$(LIBDIR)
- /usr/bin/install -m 644 $(CLALSADRV_H) $(PREFIX)/include
- /usr/bin/install -m 755 $(CLALSADRV_MIN) $(PREFIX)/$(LIBDIR)
- /sbin/ldconfig -n $(PREFIX)/$(LIBDIR)
- ln -sf $(CLALSADRV_MIN) $(PREFIX)/$(LIBDIR)/$(CLALSADRV_SO)
-
+ install -Dm 644 $(CLALSADRV_H) $(DESTDIR)$(PREFIX)/include/$(CLALSADRV_H)
+ install -Dm 755 $(CLALSADRV_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(CLALSADRV_MIN)
+ /sbin/ldconfig $(PREFIX)/$(LIBDIR)
+ ln -sf $(CLALSADRV_MIN) $(DESTDIR)$(PREFIX)/$(LIBDIR)/$(CLALSADRV_SO)
clean:
- /bin/rm -f *~ *.o *.a *.d *.so.* loopback
-
-
-tarball:
- cd ..; \
- /bin/rm -f -r $(DISTDIR)*; \
- svn export clalsadrv $(DISTDIR); \
- tar cvf $(DISTDIR).tar $(DISTDIR); \
- bzip2 $(DISTDIR).tar; \
- /bin/rm -f -r $(DISTDIR);
+ /bin/rm -f *~ *.o *.a *.d *.so.*
diff --git a/clalsadrv.cc b/libs/clalsadrv.cc
similarity index 92%
rename from clalsadrv.cc
rename to libs/clalsadrv.cc
index c288645..23c3d72 100644
--- a/clalsadrv.cc
+++ b/libs/clalsadrv.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2003-2006 Fons Adriaensen <fons.adriaensen at skynet.be>
+ Copyright (C) 2003-2010 Fons Adriaensen <fons at kokkinizita.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
@@ -37,6 +37,33 @@ Alsa_driver::~Alsa_driver (void)
}
+Alsa_driver::Alsa_driver (const char *play_name,
+ const char *capt_name,
+ const char *ctrl_name,
+ unsigned int rate,
+ snd_pcm_uframes_t frsize,
+ unsigned int nfrags) :
+ _rate (rate),
+ _frsize (frsize),
+ _nfrags (nfrags),
+ _play_handle (0),
+ _capt_handle (0),
+ _ctrl_handle (0),
+ _play_hwpar (0),
+ _play_swpar (0),
+ _capt_hwpar (0),
+ _capt_swpar (0),
+ _play_nchan (0),
+ _capt_nchan (0),
+ _play_npfd (0),
+ _capt_npfd (0),
+ _synced (false),
+ _stat (-1)
+{
+ initialise (play_name, capt_name, ctrl_name, rate, frsize, nfrags);
+}
+
+
Alsa_driver::Alsa_driver (const char *name,
unsigned int rate,
snd_pcm_uframes_t frsize,
@@ -61,201 +88,8 @@ Alsa_driver::Alsa_driver (const char *name,
_synced (false),
_stat (-1)
{
- int err, dir;
- snd_ctl_card_info_t *card;
-
- if (play)
- {
- if (snd_pcm_open (&_play_handle, name, SND_PCM_STREAM_PLAYBACK, 0) < 0)
- {
- _play_handle = 0;
- fprintf (stderr, "Alsa_driver: Cannot open PCM device %s for playback.\n", name);
- }
- }
-
- if (capt)
- {
- if (snd_pcm_open (&_capt_handle, name, SND_PCM_STREAM_CAPTURE, 0) < 0)
- {
- _capt_handle = 0;
- fprintf (stderr, "Alsa_driver: Cannot open PCM device %s for capture.\n", name);
- }
- }
-
- if (! _play_handle && ! _capt_handle) return;
-
- if (ctrl)
- {
- snd_ctl_card_info_alloca (&card);
-
- if ((err = snd_ctl_open (&_ctrl_handle, name, 0)) < 0)
- {
- fprintf (stderr, "Alse_driver: ctl_open(): %s\n", snd_strerror (err));
- return;
- }
-
- if ((err = snd_ctl_card_info (_ctrl_handle, card)) < 0)
- {
- fprintf (stderr, "Alsa_driver: ctl_card_info(): %s\n", snd_strerror (err));
- return;
- }
- }
-
- // check capabilities here
-
- if (_play_handle)
- {
- if (snd_pcm_hw_params_malloc (&_play_hwpar) < 0)
- {
- fprintf (stderr, "Alsa_driver: can't allocate playback hw params\n");
- return;
- }
-
- if (snd_pcm_sw_params_malloc (&_play_swpar) < 0)
- {
- fprintf (stderr, "Alsa_driver: can't allocate playback sw params\n");
- return;
- }
-
- if (set_hwpar (_play_handle, _play_hwpar, "playback", &_play_nchan) < 0) return;
-
- if (_play_nchan > MAXPLAY)
- {
- fprintf (stderr, "Alsa_driver: detected %d playback channels, reset to %d.\n", _play_nchan, MAXPLAY);
- _play_nchan = MAXPLAY;
- }
-
- if (set_swpar (_play_handle, _play_swpar, "playback") < 0) return;
- }
-
- if (_capt_handle)
- {
- if (snd_pcm_hw_params_malloc (&_capt_hwpar) < 0)
- {
- fprintf (stderr, "Alsa_driver: can't allocate capture hw params\n");
- return;
- }
-
- if (snd_pcm_sw_params_malloc (&_capt_swpar) < 0)
- {
- fprintf (stderr, "Alsa_driver: can't allocate capture sw params\n");
- return;
- }
-
- if (set_hwpar (_capt_handle, _capt_hwpar, "capture", &_capt_nchan) < 0) return;
-
- if (_capt_nchan > MAXCAPT)
- {
- fprintf (stderr, "Alsa_driver: detected %d capture channels, reset to %d\n", _capt_nchan, MAXCAPT);
- _capt_nchan = MAXCAPT;
- }
-
- if (set_swpar (_capt_handle, _capt_swpar, "capture") < 0) return;
- }
-
- if (_play_handle)
- {
- if (snd_pcm_hw_params_get_rate (_play_hwpar, &rate, &dir) || (rate != rate) || dir)
- {
- fprintf (stderr, "Alsa_driver: can't get requested sample rate for playback.\n");
- return;
- }
-
- if (snd_pcm_hw_params_get_period_size (_play_hwpar, &frsize, &dir) || (frsize != _frsize) || dir)
- {
- fprintf (stderr, "Alsa_driver: can't get requested period size for playback.\n");
- return;
- }
-
- if (snd_pcm_hw_params_get_periods (_play_hwpar, &nfrags, &dir) || (nfrags != _nfrags) || dir)
- {
- fprintf (stderr, "Alsa_driver: can't get requested number of periods for playback.\n");
- return;
- }
-
- snd_pcm_hw_params_get_format (_play_hwpar, &_play_format);
- snd_pcm_hw_params_get_access (_play_hwpar, &_play_access);
-
- switch (_play_format)
- {
- case SND_PCM_FORMAT_S32_LE:
- _clear_func = clear_32le;
- _play_func = play_32le;
- break;
-
- case SND_PCM_FORMAT_S24_3LE:
- _clear_func = clear_24le;
- _play_func = play_24le;
- break;
-
- case SND_PCM_FORMAT_S16_LE:
- _clear_func = clear_16le;
- _play_func = play_16le;
- break;
-
- default:
- fprintf (stderr, "Alsa_driver: can't handle playback sample format.\n");
- return;
- }
-
- _play_npfd = snd_pcm_poll_descriptors_count (_play_handle);
- }
-
- if (_capt_handle)
- {
- if (snd_pcm_hw_params_get_rate (_capt_hwpar, &rate, &dir) || (rate != _rate) || dir)
- {
- fprintf (stderr, "Alsa_driver: can't get requested sample rate for capture.\n");
- return;
- }
-
- if (snd_pcm_hw_params_get_period_size (_capt_hwpar, &frsize, &dir) || (frsize != _frsize) || dir)
- {
- fprintf (stderr, "Alsa_driver: can't get requested period size for capture.\n");
- return;
- }
-
- if (snd_pcm_hw_params_get_periods (_capt_hwpar, &nfrags, &dir) || (nfrags != _nfrags) || dir)
- {
- fprintf (stderr, "Alsa_driver: can't get requested number of periods for capture.\n");
- return;
- }
-
- if (_play_handle) _synced = ! snd_pcm_link (_play_handle, _capt_handle);
-
- snd_pcm_hw_params_get_format (_capt_hwpar, &_capt_format);
- snd_pcm_hw_params_get_access (_capt_hwpar, &_capt_access);
-
- switch (_capt_format)
- {
- case SND_PCM_FORMAT_S32_LE:
- _capt_func = capt_32le;
- break;
-
- case SND_PCM_FORMAT_S24_3LE:
- _capt_func = capt_24le;
- break;
-
- case SND_PCM_FORMAT_S16_LE:
- _capt_func = capt_16le;
- break;
-
- default:
- fprintf (stderr, "Alsa_driver: can't handle capture sample format.\n");
- return;
- }
-
- _capt_npfd = snd_pcm_poll_descriptors_count (_capt_handle);
- }
-
- if (_play_npfd + _capt_npfd > MAXPFD)
- {
- fprintf (stderr, "Alsa_driver: interface requires more than %d pollfd\n", MAXPFD);
- return;
- }
-
- _stat = 0;
-}
+ initialise (play ? name : 0, capt ? name : 0, ctrl ? name : 0, rate, frsize, nfrags);
+}
int Alsa_driver::pcm_start (void)
@@ -516,6 +350,210 @@ void Alsa_driver::printinfo (void)
// Private members ---------------------------------------------------------------------
+void Alsa_driver::initialise (const char *play_name,
+ const char *capt_name,
+ const char *ctrl_name,
+ unsigned int rate,
+ snd_pcm_uframes_t frsize,
+ unsigned int nfrags)
+{
+ int err, dir;
+ snd_ctl_card_info_t *card;
+
+ if (play_name)
+ {
+ if (snd_pcm_open (&_play_handle, play_name, SND_PCM_STREAM_PLAYBACK, 0) < 0)
+ {
+ _play_handle = 0;
+ fprintf (stderr, "Alsa_driver: Cannot open PCM device %s for playback.\n", play_name);
+ }
+ }
+
+ if (capt_name)
+ {
+ if (snd_pcm_open (&_capt_handle, capt_name, SND_PCM_STREAM_CAPTURE, 0) < 0)
+ {
+ _capt_handle = 0;
+ fprintf (stderr, "Alsa_driver: Cannot open PCM device %s for capture.\n", capt_name);
+ }
+ }
+
+ if (! _play_handle && ! _capt_handle) return;
+
+ if (ctrl_name)
+ {
+ snd_ctl_card_info_alloca (&card);
+
+ if ((err = snd_ctl_open (&_ctrl_handle, ctrl_name, 0)) < 0)
+ {
+ fprintf (stderr, "Alse_driver: ctl_open(): %s\n", snd_strerror (err));
+ return;
+ }
+
+ if ((err = snd_ctl_card_info (_ctrl_handle, card)) < 0)
+ {
+ fprintf (stderr, "Alsa_driver: ctl_card_info(): %s\n", snd_strerror (err));
+ return;
+ }
+ }
+
+ // check capabilities here
+
+ if (_play_handle)
+ {
+ if (snd_pcm_hw_params_malloc (&_play_hwpar) < 0)
+ {
+ fprintf (stderr, "Alsa_driver: can't allocate playback hw params\n");
+ return;
+ }
+
+ if (snd_pcm_sw_params_malloc (&_play_swpar) < 0)
+ {
+ fprintf (stderr, "Alsa_driver: can't allocate playback sw params\n");
+ return;
+ }
+
+ if (set_hwpar (_play_handle, _play_hwpar, "playback", &_play_nchan) < 0) return;
+
+ if (_play_nchan > MAXPLAY)
+ {
+ fprintf (stderr, "Alsa_driver: detected %d playback channels, reset to %d.\n", _play_nchan, MAXPLAY);
+ _play_nchan = MAXPLAY;
+ }
+
+ if (set_swpar (_play_handle, _play_swpar, "playback") < 0) return;
+ }
+
+ if (_capt_handle)
+ {
+ if (snd_pcm_hw_params_malloc (&_capt_hwpar) < 0)
+ {
+ fprintf (stderr, "Alsa_driver: can't allocate capture hw params\n");
+ return;
+ }
+
+ if (snd_pcm_sw_params_malloc (&_capt_swpar) < 0)
+ {
+ fprintf (stderr, "Alsa_driver: can't allocate capture sw params\n");
+ return;
+ }
+
+ if (set_hwpar (_capt_handle, _capt_hwpar, "capture", &_capt_nchan) < 0) return;
+
+ if (_capt_nchan > MAXCAPT)
+ {
+ fprintf (stderr, "Alsa_driver: detected %d capture channels, reset to %d\n", _capt_nchan, MAXCAPT);
+ _capt_nchan = MAXCAPT;
+ }
+
+ if (set_swpar (_capt_handle, _capt_swpar, "capture") < 0) return;
+ }
+
+ if (_play_handle)
+ {
+ if (snd_pcm_hw_params_get_rate (_play_hwpar, &rate, &dir) || (rate != _rate) || dir)
+ {
+ fprintf (stderr, "Alsa_driver: can't get requested sample rate for playback.\n");
+ return;
+ }
+
+ if (snd_pcm_hw_params_get_period_size (_play_hwpar, &frsize, &dir) || (frsize != _frsize) || dir)
+ {
+ fprintf (stderr, "Alsa_driver: can't get requested period size for playback.\n");
+ return;
+ }
+
+ if (snd_pcm_hw_params_get_periods (_play_hwpar, &nfrags, &dir) || (nfrags != _nfrags) || dir)
+ {
+ fprintf (stderr, "Alsa_driver: can't get requested number of periods for playback.\n");
+ return;
+ }
+
+ snd_pcm_hw_params_get_format (_play_hwpar, &_play_format);
+ snd_pcm_hw_params_get_access (_play_hwpar, &_play_access);
+
+ switch (_play_format)
+ {
+ case SND_PCM_FORMAT_S32_LE:
+ _clear_func = clear_32le;
+ _play_func = play_32le;
+ break;
+
+ case SND_PCM_FORMAT_S24_3LE:
+ _clear_func = clear_24le;
+ _play_func = play_24le;
+ break;
+
+ case SND_PCM_FORMAT_S16_LE:
+ _clear_func = clear_16le;
+ _play_func = play_16le;
+ break;
+
+ default:
+ fprintf (stderr, "Alsa_driver: can't handle playback sample format.\n");
+ return;
+ }
+
+ _play_npfd = snd_pcm_poll_descriptors_count (_play_handle);
+ }
+
+ if (_capt_handle)
+ {
+ if (snd_pcm_hw_params_get_rate (_capt_hwpar, &rate, &dir) || (rate != _rate) || dir)
+ {
+ fprintf (stderr, "Alsa_driver: can't get requested sample rate for capture.\n");
+ return;
+ }
+
+ if (snd_pcm_hw_params_get_period_size (_capt_hwpar, &frsize, &dir) || (frsize != _frsize) || dir)
+ {
+ fprintf (stderr, "Alsa_driver: can't get requested period size for capture.\n");
+ return;
+ }
+
+ if (snd_pcm_hw_params_get_periods (_capt_hwpar, &nfrags, &dir) || (nfrags != _nfrags) || dir)
+ {
+ fprintf (stderr, "Alsa_driver: can't get requested number of periods for capture.\n");
+ return;
+ }
+
+ if (_play_handle) _synced = ! snd_pcm_link (_play_handle, _capt_handle);
+
+ snd_pcm_hw_params_get_format (_capt_hwpar, &_capt_format);
+ snd_pcm_hw_params_get_access (_capt_hwpar, &_capt_access);
+
+ switch (_capt_format)
+ {
+ case SND_PCM_FORMAT_S32_LE:
+ _capt_func = capt_32le;
+ break;
+
+ case SND_PCM_FORMAT_S24_3LE:
+ _capt_func = capt_24le;
+ break;
+
+ case SND_PCM_FORMAT_S16_LE:
+ _capt_func = capt_16le;
+ break;
+
+ default:
+ fprintf (stderr, "Alsa_driver: can't handle capture sample format.\n");
+ return;
+ }
+
+ _capt_npfd = snd_pcm_poll_descriptors_count (_capt_handle);
+ }
+
+ if (_play_npfd + _capt_npfd > MAXPFD)
+ {
+ fprintf (stderr, "Alsa_driver: interface requires more than %d pollfd\n", MAXPFD);
+ return;
+ }
+
+ _stat = 0;
+}
+
+
int Alsa_driver::set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int *nchan)
{
int err;
@@ -534,15 +572,16 @@ int Alsa_driver::set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, cons
}
if ( ((err = snd_pcm_hw_params_set_access (handle, hwpar, SND_PCM_ACCESS_MMAP_NONINTERLEAVED)) < 0)
- && ((err = snd_pcm_hw_params_set_access (handle, hwpar, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0))
+ && ((err = snd_pcm_hw_params_set_access (handle, hwpar, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0)
+ && ((err = snd_pcm_hw_params_set_access (handle, hwpar, SND_PCM_ACCESS_MMAP_COMPLEX)) < 0))
{
fprintf (stderr, "Alsa_driver: the %s interface doesn't support mmap-based access.\n", sname);
return -1;
}
- if ( ((err = snd_pcm_hw_params_set_format (handle, hwpar, SND_PCM_FORMAT_S32)) < 0)
+ if ( ((err = snd_pcm_hw_params_set_format (handle, hwpar, SND_PCM_FORMAT_S32_LE)) < 0)
&& ((err = snd_pcm_hw_params_set_format (handle, hwpar, SND_PCM_FORMAT_S24_3LE)) < 0)
- && ((err = snd_pcm_hw_params_set_format (handle, hwpar, SND_PCM_FORMAT_S16)) < 0))
+ && ((err = snd_pcm_hw_params_set_format (handle, hwpar, SND_PCM_FORMAT_S16_LE)) < 0))
{
fprintf (stderr, "Alsa_driver: the %s interface doesn't support 32, 24 or 16 bit access.\n.", sname);
return -1;
diff --git a/clalsadrv.h b/libs/clalsadrv.h
similarity index 84%
rename from clalsadrv.h
rename to libs/clalsadrv.h
index f9ee7ae..5bab86b 100644
--- a/clalsadrv.h
+++ b/libs/clalsadrv.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2003-2006 Fons Adriaensen <fons.adriaensen at skynet.be>
+ Copyright (C) 2003-2008 Fons Adriaensen <fons at kokkinizita.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
@@ -33,6 +33,13 @@ class Alsa_driver
{
public:
+ Alsa_driver (const char *play_name,
+ const char *capt_name,
+ const char *ctrl_name,
+ unsigned int rate,
+ snd_pcm_uframes_t frsize,
+ unsigned int nfrags);
+
Alsa_driver (const char *name,
unsigned int rate,
snd_pcm_uframes_t frsize,
@@ -95,19 +102,22 @@ private:
typedef char *(*play_function)(const float *, char *, int, int);
typedef const char *(*capt_function) (const char *, float *, int, int);
- enum { MAXPFD = 8, MAXPLAY = 32, MAXCAPT = 32 };
+ enum { MAXPFD = 16, MAXPLAY = 64, MAXCAPT = 64 };
- int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int *nchan);
- int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname);
+ void initialise (const char *play_name,
+ const char *capt_name,
+ const char *ctrl_name,
+ unsigned int rate,
+ snd_pcm_uframes_t frsize,
+ unsigned int nfrags);
+
+ int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int *nchan);
+ int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname);
int recover (void);
unsigned int _rate;
snd_pcm_uframes_t _frsize;
unsigned int _nfrags;
- snd_pcm_format_t _play_format;
- snd_pcm_format_t _capt_format;
- snd_pcm_access_t _play_access;
- snd_pcm_access_t _capt_access;
snd_pcm_t *_play_handle;
snd_pcm_t *_capt_handle;
snd_ctl_t *_ctrl_handle;
@@ -115,6 +125,10 @@ private:
snd_pcm_sw_params_t *_play_swpar;
snd_pcm_hw_params_t *_capt_hwpar;
snd_pcm_sw_params_t *_capt_swpar;
+ snd_pcm_format_t _play_format;
+ snd_pcm_format_t _capt_format;
+ snd_pcm_access_t _play_access;
+ snd_pcm_access_t _capt_access;
unsigned int _play_nchan;
unsigned int _capt_nchan;
int _play_npfd;
--
clalsadrv packaging
More information about the pkg-multimedia-commits
mailing list