|
Ecasound Control Interface documentationKai Vehmanen09072001Table of Contents
1: IntroductionIdea behind the Ecasound Control Interface (ECI) is to take a subset of functionality provided by libecasound, write a simple API for it, and port it to various languages. At the moment, at least C++, C and Python implementations of the ECI API are available and part of the main ecasound distribution. ECI is heavily based on ecasound's interactive mode (EIAM), and the services it provides. See ecasound-iam(1) manual page for detailed EIAM documentation.2: GeneralECI doesn't provide any routines that directly manipulate audio or ecasound objects. What is does provide is an easy and generic way to issue EIAM (ecasound interactive mode) commands, access to the command return-values and error handling.This approach has two benefits. First, it's possible to keep the API small, and thus make it easier to port ECI to new languages. Secondly, it's possible to keep ECI relatively stable. Ecasound itself is a large, developing library. New features are added all the time, and from time to time, older parts of the library will get rewritten to better suit new uses. Now for application developers wanting to take advantage of libecasound, these constant changes are very annoying, especially if your specific app doesn't need the latest new features. In these cases, ECI is the best choice. 2.1: What's it good for?Specific tasks ECI is aimed at: 2.2: Services and behaviourHere's a list of services provided by all ECI implementations:
Each EIAM command has exactly one return value type. After a command has been issued, only one last_type() functions returns a non-empty value. Not all EIAM commands return a value (return type is void).
2.3: Porting to new environmentsPorting ECI to new languages should be easy. All there is to do is to implement the services listed in the previous section to the target language. In most cases it's to easist to use the C++ or C ECI as the underlying implementation.3: Implementations3.1: General3.1.1: OverviewThis section contains overview of how ECI is implemented in the discussed language (eg. as a single class, set of classes, set of routines, etc). A quick tutorial to get you started. Implementation of the following:
3.2: C++3.2.1: OverviewC++ implementation is based around the ECA_CONTROL_INTERFACE class. STL vector is used for representing collections of objects (last_string_list()).
#include <iostream> #include <unistd.h> #include <ecasound/eca-control-interface.h> int main(int argc, char *argv[]) { double cutoff_inc = 500.0; ECA_CONTROL_INTERFACE e; e.command("cs-add play_chainsetup"); e.command("c-add 1st_chain"); e.command("-i:some_file.wav"); e.command("-o:/dev/dsp"); e.command("cop-add -efl:100"); e.command("cop-select 1"); e.command("copp-select 1"); e.command("cs-connect"); e.command("start"); while(1) { sleep(1); e.command("engine-status"); if (e.last_string() != "running") break; e.command("get-position"); double curpos = e.last_float(); if (curpos > 15.0) break; e.command("copp-get"); double next_cutoff = cutoff_inc + e.last_float(); e.command_float_arg("copp-set", next_cutoff); } e.command("stop"); e.command("cs-disconnect"); e.command("cop-status"); cerr << "Chain operator status: " << e.last_string() << endl; return(0); } 3.3: C3.3.1: OverviewAll C ECI functions are prefixed with "eci_". When returning string values, a const pointer to a null-terminated char array (const char*) is returned. It's important to keep in mind that these are "borrowed" references. If you need to later use the data, you must copy it to application's own buffers. Returning a list of strings is implemented using two functions: eci_last_string_list_count() returns the number of strings available, and eci_last_string_list_item(int n) returns a pointer (const char*) to the string at index n. Note! As of ecasound 2.0.1, the C ECI implementation also provides reentrant access to the ECI API. These alternative routines are marked with '_r' postfix.
#include <stdio.h> #include <unistd.h> #include <ecasound/ecasoundc.h> int main(int argc, char *argv[]) { double cutoff_inc = 500.0; eci_init(); eci_command("cs-add play_chainsetup"); eci_command("c-add 1st_chain"); eci_command("-i:some_file.wav"); eci_command("-o:/dev/dsp"); eci_command("cop-add -efl:100"); eci_command("cop-select 1"); eci_command("copp-select 1"); eci_command("cs-connect"); eci_command("start"); while(1) { double curpos, next_cutoff; sleep(1); eci_command("engine-status"); if (strcmp(eci_last_string(), "running") != 0) break; eci_command("get-position"); curpos = eci_last_float(); if (curpos > 15.0) break; eci_command("copp-get"); next_cutoff = cutoff_inc + eci_last_float(); eci_command_float_arg("copp-set", next_cutoff); } eci_command("stop"); eci_command("cs-disconnect"); eci_command("cop-status"); printf("Chain operator status: %s", eci_last_string()); eci_cleanup(); return(0); } 3.4: Python3.4.1: OverviewPython implementation is based around the ECA_CONTROL_INTERFACE class. Lists are used for representing collections of objects. Note! Eric S. Tiedemann has written an alternative Python interface to ECI. You'll find this interface included in the main ecasound packege, in pyecasound/esteci.py. To use this instead of the standard interface, just 'import eci' and you're set! :)
#!/usr/local/bin/python import time from pyeca import * e = ECA_CONTROL_INTERFACE() e.command("cs-add play_chainsetup") e.command("c-add 1st_chain") e.command("-i:some_file.wav") e.command("-o:/dev/dsp") e.command("cop-add -efl:100") e.command("cop-select 1") e.command("copp-select 1") e.command("cs-connect") e.command("start") cutoff_inc = 500.0 while 1: time.sleep(1) e.command("engine-status") if e.last_string() != "running": break e.command("get-position") curpos = e.last_float() if curpos > 15: break e.command("copp-get") next_cutoff = cutoff_inc + e.last_float() e.command_float_arg("copp-set", next_cutoff) e.command("stop") e.command("cs-disconnect") e.command("cop-status") print "Chain operator status: ", e.last_string() 3.5: Perl3.5.1: OverviewAudio::Ecasound provides perl bindings to the ecasound control interface of the ecasound program. You can use perl to automate or interact with ecasound so you don't have to turn you back on the adoring masses packed into Wembly Stadium. Audio::Ecasound was written by Brad Bowman. At the moment this module is not distributed with ecasound. To get the latest version, check the following CPAN link. See the below example. For more info, here's another CPAN link. use Audio::Ecasound qw(:simple); eci("cs-add play_chainsetup"); eci("c-add 1st_chain"); eci("-i:some_file.wav"); eci("-o:/dev/dsp"); # multiple \n separated commands eci("cop-add -efl:100 # with comments cop-select 1 copp-select 1 cs-connect"); eci("start"); my $cutoff_inc = 500.0; while (1) { sleep(1); last if eci("engine-status") ne "running"; my $curpos = eci("get-position"); last if $curpos > 15; my $next_cutoff = $cutoff_inc + eci("copp-get"); # Optional float argument eci("copp-set", $next_cutoff); } eci("stop"); eci("cs-disconnect"); print "Chain operator status: ", eci("cop-status");
|