From 3087895772cf86610b127af963722259f8c6ffa0 Mon Sep 17 00:00:00 2001 From: Matt Flax Date: Tue, 10 Dec 2013 09:50:45 +1100 Subject: [PATCH] Added the beginnings of the IIO driver. --- codeBlocks/jack2.cbp | 660 ++++++++++++++++++++++++++++++++++++++ codeBlocks/jack2.layout | 179 +++++++++++ linux/iio/JackIIODriver.C | 172 ++++++++++ linux/iio/JackIIODriver.H | 65 ++++ linux/wscript | 45 ++- wscript | 13 +- 6 files changed, 1125 insertions(+), 9 deletions(-) create mode 100644 codeBlocks/jack2.cbp create mode 100644 codeBlocks/jack2.layout create mode 100644 linux/iio/JackIIODriver.C create mode 100644 linux/iio/JackIIODriver.H diff --git a/codeBlocks/jack2.cbp b/codeBlocks/jack2.cbp new file mode 100644 index 00000000..f2f56db0 --- /dev/null +++ b/codeBlocks/jack2.cbp @@ -0,0 +1,660 @@ + + + + + + diff --git a/codeBlocks/jack2.layout b/codeBlocks/jack2.layout new file mode 100644 index 00000000..5246258c --- /dev/null +++ b/codeBlocks/jack2.layout @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/linux/iio/JackIIODriver.C b/linux/iio/JackIIODriver.C new file mode 100644 index 00000000..1b598c9c --- /dev/null +++ b/linux/iio/JackIIODriver.C @@ -0,0 +1,172 @@ +/* +Copyright (C) 2013 Matt Flax + +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 "JackIIODriver.H" +#include "driver_interface.h" + +#define IIO_DEFAULT_SAMPLERATE 1e6; ///< The default sample rate for the default chip +#define IIO_DEFAULT_PERIODSIZE 1024; ///< The defaul period size + +namespace Jack { + +int JackIIODriver::Open(jack_nframes_t buffer_size, + jack_nframes_t samplerate, + bool capturing, + bool playing, + int inchannels, + int outchannels, + bool monitor, + const char* capture_driver_name, + const char* playback_driver_name, + jack_nframes_t capture_latency, + jack_nframes_t playback_latency) +{ + return JackAudioDriver::Open(buffer_size, samplerate, capturing, playing, inchannels, outchannels, + monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency); +} + +} // end namespace Jack + + +#ifdef __cplusplus +extern "C" +{ +#endif + + SERVER_EXPORT const jack_driver_desc_t * + driver_get_descriptor () { + jack_driver_desc_t * desc; + jack_driver_desc_filler_t filler; + jack_driver_param_value_t value; + + desc = jack_driver_descriptor_construct("iio", JackDriverMaster, "Linux Industrial IO backend", &filler); + + strcpy(value.str, "AD7476"); + jack_driver_descriptor_add_parameter( + desc, + &filler, + "device", + 'd', + JackDriverParamString, + &value, + NULL, + "The IIO chip to use.", + "The IIO chip to use. Specifies which chip name to scan for on all devices present in /sys/bus/iio."); + + value.ui = IIO_DEFAULT_PERIODSIZE; + jack_driver_descriptor_add_parameter(desc, &filler, "period", 'p', JackDriverParamUInt, &value, NULL, "Frames per period", NULL); + + value.ui = 2; + jack_driver_descriptor_add_parameter(desc, &filler, "nperiods", 'n', JackDriverParamUInt, &value, NULL, "Number of periods of playback latency", NULL); + + value.ui = (IIO_DEFAULT_SAMPLERATE)U; + jack_driver_descriptor_add_parameter(desc, &filler, "rate", 'r', JackDriverParamUInt, &value, NULL, "Sample rate", NULL); + + value.i = 0; + jack_driver_descriptor_add_parameter(desc, &filler, "capture", 'C', JackDriverParamBool, &value, NULL, "Provide capture ports.", NULL); + jack_driver_descriptor_add_parameter(desc, &filler, "playback", 'P', JackDriverParamBool, &value, NULL, "Provide playback ports.", NULL); + + value.i = 0; + jack_driver_descriptor_add_parameter(desc, &filler, "duplex", 'D', JackDriverParamBool, &value, NULL, "Provide both capture and playback ports.", NULL); + + value.ui = 0; + jack_driver_descriptor_add_parameter(desc, &filler, "input-latency", 'I', JackDriverParamUInt, &value, NULL, "Extra input latency (frames)", NULL); + jack_driver_descriptor_add_parameter(desc, &filler, "output-latency", 'O', JackDriverParamUInt, &value, NULL, "Extra output latency (frames)", NULL); + + value.ui = 0; + jack_driver_descriptor_add_parameter(desc, &filler, "inchannels", 'i', JackDriverParamUInt, &value, NULL, "Number of input channels to provide (note: currently ignored)", NULL); + jack_driver_descriptor_add_parameter(desc, &filler, "outchannels", 'o', JackDriverParamUInt, &value, NULL, "Number of output channels to provide (note: currently ignored)", NULL); + + value.ui = 3; + jack_driver_descriptor_add_parameter(desc, &filler, "verbose", 'v', JackDriverParamUInt, &value, NULL, "gtkIOStream verbose level", NULL); + +// value.i = 0; +// jack_driver_descriptor_add_parameter(desc, &filler, "snoop", 'X', JackDriverParamBool, &value, NULL, "Snoop firewire traffic", NULL); + + return desc; + } + + SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params) { + const JSList * node; + const jack_driver_param_t * param; + + char *device_name=(char*)"AD7476"; + + for (node = params; node; node = jack_slist_next (node)) { + param = (jack_driver_param_t *) node->data; + + switch (param->character) { + case 'd': + device_name = const_cast(param->value.str); + break; + case 'p': + cmlparams.period_size = param->value.ui; + cmlparams.period_size_set = 1; + break; + case 'n': + cmlparams.buffer_size = param->value.ui; + cmlparams.buffer_size_set = 1; + break; + case 'r': + cmlparams.sample_rate = param->value.ui; + cmlparams.sample_rate_set = 1; + break; + case 'i': + cmlparams.capture_ports = param->value.ui; + break; + case 'o': + cmlparams.playback_ports = param->value.ui; + break; + case 'I': + cmlparams.capture_frame_latency = param->value.ui; + break; + case 'O': + cmlparams.playback_frame_latency = param->value.ui; + break; + case 'x': + cmlparams.slave_mode = param->value.ui; + break; +// case 'X': +// cmlparams.snoop_mode = param->value.i; +// break; + case 'v': + cmlparams.verbose_level = param->value.ui; + } + } + + /* duplex is the default */ + if (!cmlparams.playback_ports && !cmlparams.capture_ports) { + cmlparams.playback_ports = 1; + cmlparams.capture_ports = 1; + } + + iio.findDevicesByChipName(chipName); + + // Special open for FFADO driver... + if (ffado_driver->Open(&cmlparams) == 0) { + return threaded_driver; + } else { + delete threaded_driver; // Delete the decorated driver + return NULL; + } + } + +#ifdef __cplusplus +} +#endif diff --git a/linux/iio/JackIIODriver.H b/linux/iio/JackIIODriver.H new file mode 100644 index 00000000..d93e5999 --- /dev/null +++ b/linux/iio/JackIIODriver.H @@ -0,0 +1,65 @@ +/* +Copyright (C) 2013 Matt Flax + +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. + +*/ + +#ifndef JACKIIODRIVER_H +#define JACKIIODRIVER_H + +#include "JackAudioDriver.h" +#include "JackThreadedDriver.h" + +#include + +namespace Jack { + +/** The Linux Industrial IO (IIO) subsystem driver for Jack. +Currently this driver only supports capture. +*/ +class JackIIODriver : public JackAudioDriver { + + IIO iio; ///< The actual IIO device + +public: + /** Constructor + */ + JackIIODriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table) : JackAudioDriver(name, alias, engine, table) { + } + + /** Destructor + */ + virtual ~JackIIODriver() { + } + + /** + */ + virtual int Open(jack_nframes_t buffer_size, + jack_nframes_t samplerate, + bool capturing, + bool playing, + int inchannels, + int outchannels, + bool monitor, + const char* capture_driver_name, + const char* playback_driver_name, + jack_nframes_t capture_latency, + jack_nframes_t playback_latency); + +}; + +} // end of Jack namespace +#endif // JACKIIODRIVER_H diff --git a/linux/wscript b/linux/wscript index a2bb6ba5..3cd94265 100644 --- a/linux/wscript +++ b/linux/wscript @@ -1,6 +1,8 @@ #! /usr/bin/env python # encoding: utf-8 +from waflib import Context + def configure(conf): conf.check_cfg(package='alsa', atleast_version='1.0.18', args='--cflags --libs', mandatory=False) conf.env['BUILD_DRIVER_ALSA'] = conf.is_defined('HAVE_ALSA') @@ -11,7 +13,35 @@ def configure(conf): conf. check_cfg(package='libffado', atleast_version='1.999.17', args='--cflags --libs', mandatory=False) conf.env['BUILD_DRIVER_FFADO'] = conf.is_defined('HAVE_LIBFFADO') - conf.define('HAVE_PPOLL', 1 ) + conf.check_cfg(package='gtkIOStream', atleast_version='1.4.0', args='--cflags --libs', mandatory=False) + conf.env['BUILD_DRIVER_IIO'] = conf.is_defined('HAVE_GTKIOSTREAM') + conf.check_cfg(package='eigen3', atleast_version='3.2.0', args='--cflags --libs', mandatory=False) + conf.env['BUILD_DRIVER_IIO'] += conf.is_defined('HAVE_EIGEN3') + conf.check_cfg(package='sox', atleast_version='14.4.1', args='--cflags --libs', mandatory=False) + conf.env['BUILD_DRIVER_IIO'] += conf.is_defined('HAVE_SOX') + #conf.env['BUILD_DRIVER_IIO'] += conf.is_defined('HAVE_EIGEN3') + #print conf.env + #conffile.write("\n".join(myconf)) + #conf.define('HAVE_PPOLL', 1 ) + + conf.find_program("mkoctfile", var="MKOCTFILE") + if conf.env.MKOCTFILE: + conf.env['HAVE_OCTAVE']=1 + conf.env['define_key'] += ['HAVE_OCTAVE'] + conf.env['DEFINES'] += ['HAVE_OCTAVE=1'] + #conf.env('Octave') + conf.env['INCLUDES_OCTAVE'] = conf.cmd_and_log([conf.env.MKOCTFILE, "--print", "INCFLAGS" ], + output=Context.STDOUT).replace('\n', '').replace('-I','').split() + lflags = conf.cmd_and_log([conf.env.MKOCTFILE, "--print", "LFLAGS" ], + output=Context.STDOUT) + conf.env['LIB_OCTAVE'] = conf.cmd_and_log([conf.env.MKOCTFILE, "--print", "OCTAVE_LIBS" ], + output=Context.STDOUT).replace('\n', '').replace('-l','').split() + #conf.append("INCFLAGS: " + incflags) + #conf.append("LFLAGS: " + lflags) + #conf.append("LIBS: " + libs) + print conf.env + #import pdb; pdb.set_trace() + def create_jack_driver_obj(bld, target, sources, uselib = None): driver = bld(features = ['c', 'cxx', 'cxxshlib', 'cshlib']) @@ -36,15 +66,15 @@ def build(bld): jackd.defines = ['HAVE_CONFIG_H','SERVER_SIDE'] jackd.source = ['../common/Jackdmp.cpp'] jackd.use = ['serverlib'] - if bld.env['IS_LINUX'] and bld.env['BUILD_JACKDBUS']: - jackd.source += ['../dbus/reserve.c', '../dbus/audio_reserve.c'] + if bld.env['IS_LINUX'] and bld.env['BUILD_JACKDBUS']: + jackd.source += ['../dbus/reserve.c', '../dbus/audio_reserve.c'] jackd.use += ['PTHREAD', 'DL', 'RT', 'M', 'STDC++', 'DBUS-1'] else: jackd.use += ['PTHREAD', 'DL', 'RT', 'M', 'STDC++'] jackd.target = 'jackd' - + create_jack_driver_obj(bld, 'dummy', '../common/JackDummyDriver.cpp') - + alsa_driver_src = [ 'alsa/JackAlsaDriver.cpp', 'alsa/alsa_rawmidi.c', @@ -74,6 +104,8 @@ def build(bld): 'firewire/JackFFADOMidiSendQueue.cpp' ] + iio_driver_src = ['iio/JackIIODriver.C'] + if bld.env['BUILD_DRIVER_ALSA'] == True: create_jack_driver_obj(bld, 'alsa', alsa_driver_src, ["ALSA"]) create_jack_driver_obj(bld, 'alsarawmidi', alsarawmidi_driver_src, @@ -85,6 +117,9 @@ def build(bld): if bld.env['BUILD_DRIVER_FFADO'] == True: create_jack_driver_obj(bld, 'firewire', ffado_driver_src, ["LIBFFADO"]) + if bld.env['BUILD_DRIVER_IIO'] == True: + create_jack_driver_obj(bld, 'iio', iio_driver_src, ["GTKIOSTREAM", "EIGEN3", "OCTAVE"]) + create_jack_driver_obj(bld, 'net', '../common/JackNetDriver.cpp') create_jack_driver_obj(bld, 'loopback', '../common/JackLoopbackDriver.cpp') diff --git a/wscript b/wscript index 0c3b350c..aef4bd89 100644 --- a/wscript +++ b/wscript @@ -83,6 +83,7 @@ def options(opt): opt.add_option('--firewire', action='store_true', default=False, help='Enable FireWire driver (FFADO)') opt.add_option('--freebob', action='store_true', default=False, help='Enable FreeBob driver') opt.add_option('--alsa', action='store_true', default=False, help='Enable ALSA driver') + opt.add_option('--iio', action='store_true', default=False, help='Enable IIO driver') opt.add_option('--autostart', type='string', default="default", help='Autostart method. Possible values: "default", "classic", "dbus", "none"') opt.add_option('--portaudio', action='store_true', default=False, help='Enable Portaudio driver') opt.add_option('--winmme', action='store_true', default=False, help='Enable WinMME driver') @@ -136,7 +137,7 @@ def configure(conf): conf.check_tool('compiler_cc') conf.env.append_unique('CCDEFINES', '_POSIX') conf.env.append_unique('CXXDEFINES', '_POSIX') - + conf.env.append_unique('CXXFLAGS', '-Wall') conf.env.append_unique('CFLAGS', '-Wall') @@ -149,9 +150,12 @@ def configure(conf): conf.fatal('FreeBob driver was explicitly requested but cannot be built') if Options.options.firewire and not conf.env['BUILD_DRIVER_FFADO']: conf.fatal('FFADO driver was explicitly requested but cannot be built') + if Options.options.iio and not conf.env['BUILD_DRIVER_IIO']: + conf.fatal('IIO driver was explicitly requested but cannot be built') conf.env['BUILD_DRIVER_ALSA'] = Options.options.alsa conf.env['BUILD_DRIVER_FFADO'] = Options.options.firewire conf.env['BUILD_DRIVER_FREEBOB'] = Options.options.freebob + conf.env['BUILD_DRIVER_IIO'] = Options.options.iio if conf.env['IS_WINDOWS']: conf.sub_config('windows') if Options.options.portaudio and not conf.env['BUILD_DRIVER_PORTAUDIO']: @@ -319,7 +323,7 @@ def configure(conf): print("Build with a maximum of %d JACK clients" % Options.options.clients) print("Build with a maximum of %d ports per application" % Options.options.application_ports) - + display_msg("Install prefix", conf.env['PREFIX'], 'CYAN') display_msg("Library directory", conf.all_envs[""]['LIBDIR'], 'CYAN') if conf.env['BUILD_WITH_32_64'] == True: @@ -350,11 +354,12 @@ def configure(conf): display_feature('Build with ALSA support', conf.env['BUILD_DRIVER_ALSA'] == True) display_feature('Build with FireWire (FreeBob) support', conf.env['BUILD_DRIVER_FREEBOB'] == True) display_feature('Build with FireWire (FFADO) support', conf.env['BUILD_DRIVER_FFADO'] == True) + display_feature('Build with IIO support', conf.env['BUILD_DRIVER_IIO'] == True) if conf.env['IS_WINDOWS']: display_feature('Build with WinMME support', conf.env['BUILD_DRIVER_WINMME'] == True) display_feature('Build with Portaudio support', conf.env['BUILD_DRIVER_PORTAUDIO'] == True) - + if conf.env['BUILD_JACKDBUS'] == True: display_msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], 'CYAN') #display_msg('Settings persistence', xxx) @@ -407,7 +412,7 @@ def build(bld): bld.add_subdirs('man') if bld.env['BUILD_JACKDBUS'] == True: bld.add_subdirs('dbus') - + if bld.env['IS_MACOSX']: bld.add_subdirs('macosx') bld.add_subdirs('example-clients')