mp4-sa-> sfront reference manual-> developers intro |
Sections
|
IntroductionPart II of the sfront reference manual is written for two audiences:
In this chapter, we introduce both audiences to developing code for sfront. We begin with a description of how to use the off-the-shelf sfront in simple end-user applications, and show the limits of this approach. We then introduce the driver interface, a mechanism for adding application-specific code to sfront. The driver interface offers a more flexible way for application developers to use sfront in their programs. In addition, people wishing to add a new general-purpose feature to sfront can often use the driver interface, instead of directly modifying the sfront sources. The chapter ends with a roadmap for the following two chapters, which describe the driver interface in detail. These chapters describe control drivers, which lets user C code directly control the sound generation process, and audio drivers, which handle moving audio-rate streams into and out of the sound engine. |
|
Sfront in ApplicationsSome end-user applications have simple requirements for a sound-generation engine. For example, consider a program that is a graphical score editor, that lets users manually enter traditional music notation onto staves. A common feature of score editors is an audio preview function, that lets users listen to rendered versions of the audio. The right panel shows a C language code fragment that implements the feature, for Linux systems. The code on the right panel assumes that the application program has created a SASL file ss, that contains the notes values and durations from the graphical score in SASL notation. The code also assumes that the program has created a SAOL file, sl, to orchestrate the score. Typically, the application will have a library of SAOL programs available, and includes a user-interface for mapping different musical lines to SAOL instruments. The code on the right panel uses the ANSI C library call system() to execute other programs. As an ANSI library function, this method should work with any ANSI-compliant C compiler. However, the commands to be executed must exist on the platform. Three programs are executed in sequence:
In practice, a production application would include additional code for error checking and file management, as described on the right panel. |
Sample Code#include <stdlib.h> /* application first generates */ /* file "sl" holding the SAOL */ /* program, and file "ss" */ /* holding the SASL notes. */ /* run sfront on sl and ss */ system( "sfront -aout linux -orc sl -sco ss" ); /* compile sfront's output */ system("gcc -O3 sa.c -o sa"); /* run executable */ system("./sa"); In Production Code:[1] Write all files to /tmp, use tempnam() to create unique names, and delete files after use. [2] Examine return value of system() call for errors. [3] Use POSIX and Windows replacements for system() for enhanced features. [4] Redirect stdout and stderr for each command to a log file: system("sa >& /tmp/log"); [5] Make sure the complexity of the SAOL code in sl and the note density of the score in ss matches the speed of the CPU. |
Adding Features to SfrontThe score transcription application described in the last section specifies the notes to be played in a static manner. It writes a SASL file, and then invokes sfront to create a sound engine that plays the file. The application also statically specifies the audio routing, by invoking sfront with the -aout linux option. However, some end-user applications are a bad match for a static audio and control approach. Examples of such applications include:
For sfront to support these programs, application-specific code must be added to the sa.c file that sfront produces. A host program would still use system commands to prepare and launch the sa.c program, but the application-specific code in the sa.c program could handle the dynamic functions, perhaps by communicating to the host program using inter-process communication. The sfront driver interface lets application developers add C or C++ code into the sa.c file in a standardized way. In addition to supporting application-specific uses for sfront, the driver interface is the mechanism for adding general-purpose sfront features that involve control and audio communication. In the final section of this chapter, we introduce the concept of audio and control drivers. The next two chapters describe the process of writing control and audio drivers in depth. |
|
The Driver InterfaceThe driver interface lets users specify, on the the sfront command line, the inclusion of C or C++ code into the generated C file. Two types of drivers are currently supported:
To create a new driver, two tasks are involved. The larger task is to create the C or C++ code that is included into the sa.c file. This code includes a set of functions, described in the API, that are called by sfront at regular intervals. The control driver calls allow the driver to insert control data into the running program, while the audio driver calls let the driver pick up or deliver audio streaming data. During each function call, the driver can communicate with other processes running on the system, as well as read and write external hardware devices such as MIDI In ports. In addition to creating the included C or C++ code, a new driver needs to be registered with sfront, so that -cin, -ain, and -aout flags recognize the driver. This registration task involves appending information to parsing functions in the sfront source files. Current LimitationsAt the current time, the audio and control driver APIs do not support adding new plug-in formats to sfront. The AudioUnit drivers work using private additions to the driver APIs. We intend to generalize these additions so that they will support other plug-in formats, and add them to the official control and audio driver APIs. At the current time, only one control driver (specified by the -cin flag on the sfront command line) and two audio control drivers (an audio input driver, specified by the -ain flag, and an audio output driver, specified by the -aout flag) may be specified. However, the APIs have been designed to support future expansion to support multiple audio and control drivers, and we believe that adding this feature would not break backward compatibility for properly written drivers. At the current time, the registration process requires recompilation of the sfront sources. Future enhancements will support adding new drivers to sfront without recompilation. |
|
Next section: Part II/2A: Control Driver Overview |
|
mp4-sa-> sfront reference manual-> developers intro |