sndio OpenBSD audio & MIDI framework for music and desktop applications



Similar documents
MP3 Player CSEE 4840 SPRING 2010 PROJECT DESIGN.

Computer Organization & Architecture Lecture #19

Have both hardware and software. Want to hide the details from the programmer (user).

Network Attached Storage. Jinfeng Yang Oct/19/2015

Implementing an In-Service, Non- Intrusive Measurement Device in Telecommunication Networks Using the TMS320C31

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

The Secrets of Flow Control in Serial Communication

CSC 2405: Computer Systems II

Quick Start. Guide. The. Guide

technology brief RAID Levels March 1997 Introduction Characteristics of RAID Levels

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Chapter 11 I/O Management and Disk Scheduling

I/O Device and Drivers

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Narrow Bandwidth Streaming Video Codec

The Bus (PCI and PCI-Express)

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

Computer-System Architecture

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

OPTIMIZE DMA CONFIGURATION IN ENCRYPTION USE CASE. Guillène Ribière, CEO, System Architect

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Project 4: Pseudo USB Simulation Introduction to UNIVERSAL SERIAL BUS (USB) STANDARD

EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH CERN ACCELERATORS AND TECHNOLOGY SECTOR A REMOTE TRACING FACILITY FOR DISTRIBUTED SYSTEMS

Multimedia Systems Hardware & Software THETOPPERSWAY.COM

Rackspace Cloud Databases and Container-based Virtualization

Obj: Sec 1.0, to describe the relationship between hardware and software HW: Read p.2 9. Do Now: Name 3 parts of the computer.

CSE 237A Final Project Final Report

8-ch RAID0 Design by using SATA Host IP Manual Rev1.0 9-Jun-15

Chapter 13 Embedded Operating Systems

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Distributed File System. MCSN N. Tonellotto Complements of Distributed Enabling Platforms

AT&T Connect Video conferencing functional and architectural overview

Hello, and welcome to this presentation of the STM32 SDMMC controller module. It covers the main features of the controller which is used to connect

Configuring Apache Derby for Performance and Durability Olav Sandstå

SAN Conceptual and Design Basics

Main Points. Scheduling policy: what to do next, when there are multiple threads ready to run. Definitions. Uniprocessor policies

Axia IP-Audio Driver Update v June, 2013

ivms-4200 Client Software Quick Start Guide V1.02

Midi Workshop. SAWStudio. From RML Labs. To order this product, or download a free demo, visit

Levels of Software Testing. Functional Testing

Network Scanning: A New Feature for Digital Copiers

Operating system Dr. Shroouq J.

evm Virtualization Platform for Windows

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Networked Music Performance(NMP)

COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware

What is LOG Storm and what is it useful for?

ReactOS is (not) Windows. Windows internals and why ReactOS couldn t just use a Linux kernel

Performance Evaluation of Linux Bridge

Example of Standard API

Analog Representations of Sound

Communicating with devices

Linux Kernel Architecture

The diagram below illustrates the steps from stored music to audio device; key elements of the audio chain are discussed later in this guide.

Information Technology Career Field Pathways and Course Structure

x64 Servers: Do you want 64 or 32 bit apps with that server?

Virtualization for Cloud Computing

Why Threads Are A Bad Idea (for most purposes)

New protocol concept for wireless MIDI connections via Bluetooth

Computer Systems Structure Input/Output

Voice Over Internet Protocol(VoIP)

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

Distributed RAID Architectures for Cluster I/O Computing. Kai Hwang

Computer Performance. Topic 3. Contents. Prerequisite knowledge Before studying this topic you should be able to:

Performance Tuning Guidelines for PowerExchange for Microsoft Dynamics CRM

Achieving Nanosecond Latency Between Applications with IPC Shared Memory Messaging

Performance Monitoring User s Manual

Competitive Analysis Retrospect And Our Competition

Hello, and welcome to this presentation of the STM32 Serial Audio Interface. I will present the features of this interface, which is used to connect

QLIKVIEW SERVER MEMORY MANAGEMENT AND CPU UTILIZATION

Using the US-122 with GigaStudio and Cubasis

I/O. Input/Output. Types of devices. Interface. Computer hardware

ReSound Unite TV FREQUENTLY ASKED QUESTIONS. Setup & Configuration. Use & Operation. Troubleshooting

SPI I2C LIN Ethernet. u Today: Wired embedded networks. u Next lecture: CAN bus u Then: wireless embedded network

Lesson Plans Microsoft s Managing and Maintaining a Microsoft Windows Server 2003 Environment

21152 PCI-to-PCI Bridge

Serial Communications

SIB relays C++ API SQL API. Kernel. Hardware Desc. XML. XML Parser parser.h. State. Misc. Mgmt. I/O Manager iomgr.h. Data Acq. XCR. Batt. Mgmt.

Next Generation Operating Systems

Simple Voice over IP (VoIP) Implementation

CLOUD GAMING WITH NVIDIA GRID TECHNOLOGIES Franck DIARD, Ph.D., SW Chief Software Architect GDC 2014

Operating System Structures

Distributed Realtime Systems Framework for Sustainable Industry 4.0 applications

Welcome to the tutorial for the MPLAB Starter Kit for dspic DSCs

Integrating the Internet into Your Measurement System. DataSocket Technical Overview

CPU Scheduling. CPU Scheduling

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING UNIT 5 INPUT/OUTPUT UNIT JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

CHAPTER 15: Operating Systems: An Overview

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

Advanced Memory and Storage Considerations for Provisioning Services

1. Memory technology & Hierarchy

SIMERO Software System Design and Implementation

Mobile Operating Systems Lesson 05 Windows CE Part 1

The Model A032-ET of Riga Event Timers

Chapter 3 Operating-System Structures

Survey on Job Schedulers in Hadoop Cluster

Uses for Virtual Machines. Virtual Machines. There are several uses for virtual machines:

AND Recorder 5.4. Overview. Benefits. Datenblatt

Software Sequencing Basics

Transcription:

sndio OpenBSD & MIDI framework for music and desktop applications Alexandre Ratchov alex@caoua.org AsiaBSDCon 2010 13 march 2010 A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 1 / 31

Outline 1 The problem to solve Introduction Purpose of the & MIDI subsystem The problem to solve : goal 2 Design choices Kernel vs. user-space implementation Formats & algorithms to support 3 Architecture and implementation Audio server Synchronization & MIDI control 4 Examples 5 Conclusion A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 2 / 31

Introduction A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 3 / 31

What is digital? Sequence of samples at fixed rate. Played or recorded by the interface. Full-duplex : n-th sample played while n-th sample recorded. Consequences Clock source (each sample is a clock tick). Can be streamed (samples can be buffered). A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 4 / 31

What is MIDI? Slow unidirectional serial link. Transmits events to control (start, stop, volume). Standardized in 1985, used by most professional equipment. Real-time (i.e., events are processed immediately). Consequences Not a clock source, but can carry clock ticks. Usable to control (start, stop, volume). A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 5 / 31

Purpose of the & MIDI subsystem application application subsystem hardware Fill the gap between the software and the hardware. Format conversions, resampling. Allow multiple programs to use the hardware concurrently. Mixing, splitting hardware in subdevices. Allow multiple programs to cooperate. Synchronization, communication between programs. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 6 / 31

The problem to solve A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 7 / 31

Conversions & resampling Application may not support hardware parameters. Two programs may not support common parameters at least one of them requires conversions. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 8 / 31

Splitting hardware in subdevices & mixing Using a 4-channel card as two independent stereo cards. Example Headphones (channels 0,1) for telephony. Speakers (channels 2,3) for music. Remark : mixing two streams is trivial at this stage. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 9 / 31

Synchronization and communication Unix philosophy Write programs that do one thing and do it well. Write programs to work together. Doug McIlroy To work together, programs must: Be synchronized. Communicate. This is the role of and MIDI subsystems. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 10 / 31

Fault tolerance and correctness Error recovery Effects of transient errors must be transient e.g., a load burst may not cause a program to go out of sync. Isolation Error in one program should break no other program. Correctness Complicated architecture leads to bogus implementation. Complicated APIs are misused and lead to broken programs. Complicated tools are misused and lead to broken configurations. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 11 / 31

Design considerations A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 12 / 31

Performance vs. responsiveness Performance CPU time consumed e.g., how many CPU cycles to compress a file. Responsiveness Latency in processing events e.g., how long it takes to read a block from disk. For any subsystem: The CPU usage is negligible. Performance is not a concern. Delays causes the sound to stutter. Responsiveness is of first importance. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 13 / 31

User-space vs. kernel: extra latency? What is latency? The time between a program produces samples and the time they are played. Samples are buffered. Buffers are consumed at fixed rate (sample rate). The latency is the buffer usage. No extra latency Whether buffers are located in kernel or user space doesn t matter for the latency. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 14 / 31

User-space vs. kernel: stability? Why do the sound stutter? The machine is busy, the program (or the subsystem) don t get enough CPU to produce samples to play. During a load burst: User-space components may underrun. Kernel components can t underrun. During a load burst, the application underruns, so we re toast. No matter whether the subsystem has user-space components. Fixing stuttering Write programs that don t block. Give enough CPU to programs. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 15 / 31

Sample formats choice Integers (a.k.a fixed point numbers) yes. Any combination of width, signedness, byte order and alignment. Used by most hardware. IEEE floats used only in the [ 1;1] range no. Equivalent to integers (fixed range). Trivial to convert from/to integers (FPU required). Mostly used to save development costs. µ-law & a-law no. Not usable for processing (not linear). Already handled by telephony applications. Encrypted/compressed opaque formats no. Not desirable (computers are to process data). Alternatives exist, i.e., the user is not locked. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 16 / 31

Architecture and implementation A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 17 / 31

Overview Audio server Conversions, resampling, mixing, channel mapping. Subdevices per-subdevice properties. MIDI controlled per-application volume. MIDI exposed clock source for non- applications. MIDI controlled synchronization between applications. MIDI server software MIDI thru box hub for MIDI data. Software or hardware can be connected to it. Library-based programming interface Very simple. Mimics kernel APIs (read, write,...). No need to handle synchronization and error recovery. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 18 / 31

Audio server architecture - processing chain The server framework: Elementary data processing units with: conversions, resampling (1 input, 1 output), mixing (N inputs, 1 output), channel extraction (1 input, N outputs), socket I/O, file I/O (either no inputs or no outputs). Processing units are interconnected by FIFOs. Event-driven framework for non-blocking I/O (no threads). Server = network of elementary units Server behavior is determined by: the choice of processing units, the way they are interconnected. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 19 / 31

Audio processing chain server example in decode resamp. mix play in socket1 socket2 device out out encode resamp. demux record A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 20 / 31

Audio processing chain non-server example file1 and file2 are mixed/merged and the result is stored into file3 and file4 (of different formats). file1 decode resamp. mix file2 file3 file4 encode resamp. demux A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 21 / 31

Latency flow control Latency latency = buffered = written played rate rate Control the number of samples written. Minimum theoretical latency: Single application: 2 blocks (1 for the device + 1 for the application). Server with independent applications: 1 extra block to allow 1 application to underrun without disturbing others. Current implementation allows 3-block latency (i.e., the minimum). A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 22 / 31

MIDI controlled per-application volume Why MIDI control? Standard since 1985. Very simple to use and impliment. Both software and hardware support MIDI. Current limitations: Which MIDI channel corresponds to which application? Mapping should be exposed through the standard mixer interface. No MIDI control utility in OpenBSD yet one must use the bulky MIDI hardware or non-openbsd software....work in progress! A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 23 / 31

MIDI controlled synchronization Start process MMC start message blocks all streams. Once all streams are ready, the server starts. No need to modify application code. preparing ready waiting app1 app2 app3 start signal actual start time A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 24 / 31

Sound card clock exposed through MIDI Why? Allows MIDI-aware software (or hardware!) to be synchronized to non-midi-aware programs. Typical scenario: The user manipulates a MIDI sequencer. The sequencer controls streams. The server sends feedback to the sequencer. The sequencer stays in sync to streams. Simple programs work together to achieve a complex task. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 25 / 31

Examples A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 26 / 31

Example: MIDI sequencer, player, recorder MIDI thru box recorder player volume start/stop (MMC) start, stop, relocate... (MMC) server MIDI sequencer clock (MTC) hardware MIDI keyboard MIDI sythesizer Without the server and the MIDI thru box, the same task would require a monolithic application. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 27 / 31

Integration in OpenBSD Single binary to start the server on the default device: $ aucat -l No configuration file, options are on the command line: E.g., to create spkr and hp subdevices: $ aucat -l -c 0:1 -s spkr -c 2:3 -s hp Audio player, recorder and off-line conversion utility: $ aucat -i file_to_play.wav Devices can be either hardware (character devices) or software subdevices (server connections) new naming scheme is required: <type>:<unit>[.subdevice] E.g., aucat:0.hp, rmidi:5, midithru:0,... A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 28 / 31

Demo: simple tools working together MIDI thru box start, stop, relocate (MMC) player player clock (MTC), start/stop (MTC) server hardware volume start/stop (MMC) MIDI sequencer MIDI thru box MIDI controller Playing two files simultaneously. Controlling volume through MIDI. Synchronizing a MIDI sequencer to record automation. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 29 / 31

Demo: simple tools working together MIDI thru box start, stop, relocate (MMC) player player clock (MTC), start/stop (MMC) server hardware volume start/stop (MMC) MIDI sequencer MIDI thru box MIDI controller Playing two files simultaneously. Controlling volume through MIDI. Synchronizing a MIDI sequencer to record automation. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 29 / 31

Demo: simple tools working together MIDI thru box start, stop, relocate (MMC) player player clock (MTC), start/stop (MMC) server hardware volume start/stop (MMC) MIDI sequencer MIDI thru box MIDI controller Playing two files simultaneously. Controlling volume through MIDI. Synchronizing a MIDI sequencer to record automation. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 29 / 31

Future work Less is more keep it simple! Port more code to sndio, improve quality of existing code. MIDI mixer use a single mixer framework. Record played streams (e.g., record from softsynths). Avoid useless data copying use shared memory. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 30 / 31

Conclusion Very simple framework (hopefully!). User-space implementation. Single binary, no configuration file. Stable and reliable by design. Fast and structured non-blocking framework. Strict latency control (theoretical minimum reached). Synchronization maintained after underruns. Problems of desktop application addressed: Conversions, resampling, mixing, channel mapping, volume control. Subdevices per-subdevice properties. Problems of music applications addressed: MIDI controlled synchronization between applications. Software MIDI ports allowing applications to communicate. A. Ratchov (AsiaBSDCon) OpenBSD and MIDI subsystem 13 march 2010 31 / 31