Echoaudio support

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Echoaudio support

Bugzilla from pochini@shiny.it

Hi all.

I'm writing the driver for Echoaudio soundcards. I need some tools to fiddle
with hw metering and monitor in order to test my code.



--
Giuliano.


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Echoaudio support

Lee Revell
On Tue, 2005-07-19 at 18:03 +0200, Giuliano Pochini wrote:
> Hi all.
>
> I'm writing the driver for Echoaudio soundcards. I need some tools to fiddle
> with hw metering and monitor in order to test my code.

I posted about this a while ago wrt emu10k1 devices and didn't get a
response.

AFAICT HW metering is not really implemented.

HW monitoring does work.  See jack/drivers/alsa/generic_hw.c for a
template and jack/drivers/alsa/ice1712.c for a working example.  You can
test it with jack_monitor_client.

Lee



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Echoaudio support

Bugzilla from pochini@shiny.it
On Tue, 19 Jul 2005 13:07:19 -0400
Lee Revell <[hidden email]> wrote:

> On Tue, 2005-07-19 at 18:03 +0200, Giuliano Pochini wrote:
> > Hi all.
> >
> > I'm writing the driver for Echoaudio soundcards. I need some tools to fiddle
> > with hw metering and monitor in order to test my code.
>
> I posted about this a while ago wrt emu10k1 devices and didn't get a
> response.
>
> AFAICT HW metering is not really implemented.
>
> HW monitoring does work.  See jack/drivers/alsa/generic_hw.c for a
> template and jack/drivers/alsa/ice1712.c for a working example.  You can
> test it with jack_monitor_client.

Ok, but I cannot make it work. The driver is called at startup and it seems
to init ok, but the callback funtions never get called when I do:
jack_monitor_client alsa_pcm:capture_1 (w/ or w/o something is recording).
Probably there is some stupid bug, since I never wrote anything for Jack
before.

This is the (still buggy and incomplete) driver for Jack 0.99:


--- jack-audio-connection-kit-0.99.0__orig/drivers/alsa/Makefile.am Sat Mar 27 01:51:38 2004
+++ jack-audio-connection-kit-0.99.0/drivers/alsa/Makefile.am Wed Jun 29 19:11:50 2005
@@ -8,12 +8,13 @@
 
 jack_alsa_la_LDFLAGS = -module -avoid-version
 jack_alsa_la_SOURCES = alsa_driver.c generic_hw.c memops.c \
-       hammerfall.c hdsp.c ice1712.c
+       hammerfall.c hdsp.c ice1712.c echoaudio.c
 
 noinst_HEADERS = alsa_driver.h \
  generic.h \
  hammerfall.h \
  hdsp.h \
- ice1712.h
+ ice1712.h \
+ echoaudio.h
 
 jack_alsa_la_LIBADD = $(ALSA_LIBS)
--- jack-audio-connection-kit-0.99.0__orig/drivers/alsa/alsa_driver.c Mon Sep 13 04:11:46 2004
+++ jack-audio-connection-kit-0.99.0/drivers/alsa/alsa_driver.c Tue Jul 19 17:48:57 2005
@@ -153,6 +153,13 @@
 }
 
 static int
+alsa_driver_echo_hardware (alsa_driver_t *driver)
+{
+ driver->hw = jack_alsa_echo_hw_new (driver);
+ return 0;
+}
+
+static int
 alsa_driver_generic_hardware (alsa_driver_t *driver)
 {
  driver->hw = jack_alsa_generic_hw_new (driver);
@@ -177,6 +184,10 @@
                 if ((err = alsa_driver_ice1712_hardware (driver)) !=0) {
                         return err;
                 }
+ } else if (!strncmp(driver->alsa_driver, "Echo_", 5)) {
+                if ((err = alsa_driver_echo_hardware (driver)) !=0) {
+                        return err;
+                }
  } else {
         if ((err = alsa_driver_generic_hardware (driver)) != 0) {
  return err;
--- jack-audio-connection-kit-0.99.0__orig/drivers/alsa/echoaudio.h Thu Jan  1 01:00:00 1970
+++ jack-audio-connection-kit-0.99.0/drivers/alsa/echoaudio.h Sun Jul 24 14:35:23 2005
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2005 Giuliano Pochini
+    
+    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.
+
+    $Id: echoaudio.h,v 1.1 2003/08/29 00:06:30 trutkin Exp $
+*/
+
+#ifndef __jack_echo_h__
+#define __jack_echo_h__
+
+#include <sys/time.h>
+
+
+struct echo_mmixer_s {
+ int numid;
+ int value;
+};
+
+typedef struct {
+ alsa_driver_t *driver;
+ int input_channels, output_channels;
+ struct echo_mmixer_s echo_mmixer[32][32];
+} echo_t;
+
+jack_hardware_t *jack_alsa_echo_hw_new (alsa_driver_t *driver);
+
+#endif /* __jack_echo_h__*/
--- jack-audio-connection-kit-0.99.0__orig/drivers/alsa/echoaudio.c Thu Jan  1 01:00:00 1970
+++ jack-audio-connection-kit-0.99.0/drivers/alsa/echoaudio.c Sun Jul 24 15:09:49 2005
@@ -0,0 +1,226 @@
+/*
+    Copyright (C) 2005 Giuliano Pochini
+
+    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 <jack/hardware.h>
+#include "alsa_driver.h"
+#include "echoaudio.h"
+#include <jack/internal.h>
+
+#define PRINT(fmt, args...) fprintf(stderr, fmt, ## args)
+
+static const int ECHO_MUTE = (-128);
+static const int ECHO_UNITY_GAIN = 0;
+static const int ECHO_MAX_GAIN = 6;
+
+
+
+/* Function for checking argument values */
+static int clamp_int(int value, int lower_bound, int upper_bound)
+{
+  if(value < lower_bound) {
+    return lower_bound;
+  }
+  if(value > upper_bound) {
+    return upper_bound;
+  }
+  return value;
+}
+
+
+
+/* The echoaudio matrix mixer lets you connect any input to */
+/* any output with gain from -127dB to +6dB or muted (-128). */
+
+static int echo_set_mixer_gain(jack_hardware_t *hw, int output_channel, int input_channel, int gain)
+{
+ echo_t *e = (echo_t *)hw->private;
+ snd_ctl_elem_id_t *id;
+ snd_ctl_elem_value_t *val;
+ int err;
+
+ /* Check args */
+ input_channel = clamp_int(input_channel, 0, e->input_channels);
+ output_channel = clamp_int(output_channel, 0, e->output_channels);
+ gain = clamp_int(gain, ECHO_MUTE, ECHO_MAX_GAIN);
+
+ snd_ctl_elem_id_alloca(&id);
+ snd_ctl_elem_value_alloca(&val);
+ snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
+ snd_ctl_elem_id_set_numid(id, e->echo_mmixer[output_channel][input_channel].numid);
+ snd_ctl_elem_value_set_id(val, id);
+ snd_ctl_elem_value_set_integer(val, 0, gain);
+
+ PRINT("echo_set_mixer_gain(o=%d, i=%d, g=%d)", output_channel, input_channel, gain);
+
+ if ((err = snd_ctl_elem_write(e->driver->ctl_handle, val)) < 0) {
+ jack_error("ALSA/ECHOAUDIO: cannot set mixer gain (%s)", snd_strerror (err));
+ return err;
+ }
+
+ return 0;
+}
+
+
+
+static int echo_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
+{
+ int i;
+
+ PRINT("echo_set_input_monitor_mask %x\n", mask);
+ /* For each input channel */
+ for (i = 0; i < 26; i++) {
+ /* Monitoring requested for this channel? */
+ if (mask & (1<<i)) {
+ /* Yes.  Connect physical input to output */
+ if (echo_set_mixer_gain(hw, i, i, ECHO_UNITY_GAIN) != 0)
+ return -1;
+ } else {
+ /* No.  Disconnect physical input from output */
+ if (echo_set_mixer_gain(hw, i, i, ECHO_MUTE) != 0)
+ return -1;
+ }
+ }
+ /* Cache the monitor mask */
+ hw->input_monitor_mask = mask;
+ return 0;
+}
+
+
+
+static double echo_get_hardware_peak(jack_port_t *port, jack_nframes_t frame)
+{
+ return 0;
+}
+
+
+
+static double echo_get_hardware_power(jack_port_t *port, jack_nframes_t frame)
+{
+ return 0;
+}
+
+
+
+void jack_alsa_echo_release(jack_hardware_t *hw)
+{
+ echo_t *e = (echo_t *)hw->private;
+
+ if (e)
+ free(e);
+}
+
+
+
+// Scan all controls and sets up the structures needed to access them.
+int echo_scan_controls(echo_t *e, const char *card) {
+  int err, i, o;
+  int numid, count, monitorId, channelsId;
+  snd_hctl_t *handle;
+  snd_hctl_elem_t *elem;
+  snd_ctl_elem_id_t *id;
+  snd_ctl_elem_info_t *info;
+
+  monitorId=channelsId=0;
+  snd_ctl_elem_id_alloca(&id);
+  snd_ctl_elem_info_alloca(&info);
+
+  if ((err=snd_hctl_open(&handle, card, 0))<0) {
+    jack_error("Control %s open error: %s", card, snd_strerror(err));
+    return err;
+  }
+  if ((err=snd_hctl_load(handle))<0) {
+    jack_error("Control %s local error: %s\n", card, snd_strerror(err));
+    return err;
+  }
+  for (elem=snd_hctl_first_elem(handle); elem; elem=snd_hctl_elem_next(elem)) {
+    if ((err=snd_hctl_elem_info(elem, info))<0) {
+      jack_error("Control %s snd_hctl_elem_info error: %s\n", card, snd_strerror(err));
+      return err;
+    }
+    if (snd_ctl_elem_info_is_inactive(info))
+      continue;
+    snd_hctl_elem_get_id(elem, id);
+    numid=snd_ctl_elem_id_get_numid(id);
+    count=snd_ctl_elem_info_get_count(info);
+    if (!strcmp("Monitor Mixer Volume", snd_ctl_elem_id_get_name(id))) {
+      if (!monitorId) {
+        monitorId=numid;
+ PRINT("First Mixer id=%d\n", monitorId);
+        e->output_channels=snd_ctl_elem_info_get_dimension(info, 0);
+        e->input_channels=snd_ctl_elem_info_get_dimension(info, 1);
+      }
+      PRINT("numid=%2d *%s\n", numid, snd_ctl_elem_id_get_name(id));
+    } else if (!strcmp("Channels info", snd_ctl_elem_id_get_name(id))) {
+      channelsId=numid;
+      PRINT("id=%2d *%s\n", numid, snd_ctl_elem_id_get_name(id));
+    } else {
+      PRINT("numid=%2d  %s\n", numid, snd_ctl_elem_id_get_name(id));
+    }
+  }
+
+//  GetChannels();
+  snd_hctl_close(handle);
+
+  //@ Assumes all mixer and vmixer controls are contiguous
+  if (monitorId) {
+    for (o=0, numid=monitorId; o<e->output_channels; o++) {
+      for (i=0; i<e->input_channels; i++) {
+        e->echo_mmixer[o][i].numid=numid++;
+      }
+    }
+    return(0);
+  }
+  return(-ENXIO);
+}
+
+
+
+
+/* Mostly copied directly from hdsp.c */
+jack_hardware_t *jack_alsa_echo_hw_new(alsa_driver_t *driver)
+{
+ jack_hardware_t *hw;
+ echo_t *e;
+
+ if (!(hw = (jack_hardware_t *)calloc(1, sizeof(jack_hardware_t))))
+ return 0;
+
+ //hw->capabilities = Cap_HardwareMonitoring|Cap_AutoSync|Cap_WordClock|Cap_ClockMaster|Cap_ClockLockReporting;
+ hw->capabilities = Cap_HardwareMonitoring | Cap_HardwareMetering;
+ hw->input_monitor_mask = 0;
+ hw->private = 0;
+
+ hw->set_input_monitor_mask = echo_set_input_monitor_mask;
+ //hw->change_sample_clock = hdsp_change_sample_clock;
+ hw->release = jack_alsa_echo_release;
+ hw->get_hardware_peak = echo_get_hardware_peak;
+ hw->get_hardware_power = echo_get_hardware_power;
+
+ if ((e = (echo_t *)calloc(1, sizeof(echo_t))) && echo_scan_controls(e, "hw:0") == 0) {
+ e->driver = driver;
+ hw->private = e;
+ PRINT("jack_alsa_echo_hw_new() ok\n");
+ return hw;
+ }
+
+ free(e);
+ free(hw);
+ return 0;
+}
+
+




--
Giuliano.


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel