Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Linux Sound Programming
PREMIUM
Số trang
609
Kích thước
7.2 MB
Định dạng
PDF
Lượt xem
1156

Linux Sound Programming

Nội dung xem thử

Mô tả chi tiết

Linux Sound

Programming —

Jan Newmarch

Linux Sound

Programming

Jan Newmarch

Linux Sound Programming

Jan Newmarch

Oakleigh, Victoria, Australia

ISBN-13 (pbk): 978-1-4842-2495-3 ISBN-13 (electronic): 978-1-4842-2496-0

DOI 10.1007/978-1-4842-2496-0

Library of Congress Control Number: 2017931692

Copyright © 2017 by Jan Newmarch

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the

material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,

broadcasting, reproduction on microfilms or in any other physical way, and transmission or information

storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now

known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol

with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only

in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the

trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are

not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to

proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication,

neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or

omissions that may be made. The publisher makes no warranty, express or implied, with respect to the

material contained herein.

Managing Director: Welmoed Spahr

Acquisitions Editor: Steve Anglin

Development Editor: Matthew Moodie

Technical Reviewer: Jeff Tranter

Coordinating Editor: Mark Powers

Copy Editor: Kim Wimpsett

Compositor: SPi Global

Indexer: SPi Global

Artist: SPi Global

Cover image designed by Freepik

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,

6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer￾sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member

(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a

Delaware corporation.

For information on translations, please e-mail [email protected], or visit http://www.apress.com/rights￾permission.

Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and

licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web

page at http://www.apress.com/bulk-sales.

Any source code or other supplementary material referenced by the author in this book is available to readers

via the book’s product page, located at www.apress.com/9781484224953. For more detailed information,

please visit http://www.apress.com/source-code.

Printed on acid-free paper

iii

Contents at a Glance

About the Author ����������������������������������������������������������������������������������������������������xxi

About the Technical Reviewer ������������������������������������������������������������������������������xxiii

■Chapter 1: Basic Concepts of Sound���������������������������������������������������������������������� 1

■Chapter 2: User-Level Tools ����������������������������������������������������������������������������������� 7

■Chapter 3: Sound Codecs and File Formats��������������������������������������������������������� 11

■Chapter 4: Overview of Linux Sound Architecture����������������������������������������������� 15

■Chapter 5: ALSA��������������������������������������������������������������������������������������������������� 21

■Chapter 6: PulseAudio ����������������������������������������������������������������������������������������� 61

■Chapter 7: Jack ������������������������������������������������������������������������������������������������� 143

■Chapter 8: Session Management����������������������������������������������������������������������� 179

■Chapter 9: Java Sound �������������������������������������������������������������������������������������� 197

■Chapter 10: GStreamer�������������������������������������������������������������������������������������� 211

■Chapter 11: libao ����������������������������������������������������������������������������������������������� 223

■Chapter 12: FFmpeg/Libav��������������������������������������������������������������������������������� 227

■Chapter 13: OpenMAX IL������������������������������������������������������������������������������������ 235

■Chapter 14: LADSPA������������������������������������������������������������������������������������������� 277

■Chapter 15: Displaying Video with Overlays Using Gtk and FFmpeg����������������� 293

■Chapter 16: MIDI������������������������������������������������������������������������������������������������ 317

■Chapter 17: User-Level Tools for MIDI ��������������������������������������������������������������� 321

■Chapter 18: MIDI Java Sound ���������������������������������������������������������������������������� 327

■ Contents at a Glance

iv

■Chapter 19: MIDI ALSA �������������������������������������������������������������������������������������� 343

■Chapter 20: FluidSynth�������������������������������������������������������������������������������������� 351

■Chapter 21: TiMidity ������������������������������������������������������������������������������������������ 355

■Chapter 22: Overview of Karaoke Systems ������������������������������������������������������� 369

■Chapter 23: Karaoke User-Level Tools��������������������������������������������������������������� 371

■Chapter 24: MP3+G ������������������������������������������������������������������������������������������� 381

■Chapter 25: Karaoke Applications Using Java Sound���������������������������������������� 407

■Chapter 26: Subtitles and Closed Captions ������������������������������������������������������� 443

■Chapter 27: Karaoke FluidSynth������������������������������������������������������������������������ 465

■Chapter 28: TiMidity and Karaoke ��������������������������������������������������������������������� 499

■Chapter 29: Jack and Karaoke �������������������������������������������������������������������������� 523

■Chapter 30: Streaming Audio ���������������������������������������������������������������������������� 533

■Chapter 31: Raspberry Pi ���������������������������������������������������������������������������������� 537

■Chapter 32: Conclusion ������������������������������������������������������������������������������������� 547

■Appendix A: Decoding the DKD Files on the Sonken Karaoke DVD�������������������� 549

Index��������������������������������������������������������������������������������������������������������������������� 603

v

Contents

About the Author ����������������������������������������������������������������������������������������������������xxi

About the Technical Reviewer ������������������������������������������������������������������������������xxiii

■Chapter 1: Basic Concepts of Sound���������������������������������������������������������������������� 1

Sampled Audio ����������������������������������������������������������������������������������������������������������������� 1

Sample Rate��������������������������������������������������������������������������������������������������������������������� 1

Sample Format����������������������������������������������������������������������������������������������������������������� 2

Frames ����������������������������������������������������������������������������������������������������������������������������� 2

Pulse-Code Modulation ���������������������������������������������������������������������������������������������������� 2

Overrun and Underrun������������������������������������������������������������������������������������������������������ 3

Latency����������������������������������������������������������������������������������������������������������������������������� 3

Jitter��������������������������������������������������������������������������������������������������������������������������������� 4

Mixing������������������������������������������������������������������������������������������������������������������������������� 5

Conclusion������������������������������������������������������������������������������������������������������������������������ 5

■Chapter 2: User-Level Tools ����������������������������������������������������������������������������������� 7

Players������������������������������������������������������������������������������������������������������������������������������ 7

MPlayer��������������������������������������������������������������������������������������������������������������������������������������������������� 7

VLC����������������������������������������������������������������������������������������������������������������������������������������������������������7

Totem������������������������������������������������������������������������������������������������������������������������������������������������������ 8

■ Contents

vi

Sound Tools ���������������������������������������������������������������������������������������������������������������������� 8

sox ����������������������������������������������������������������������������������������������������������������������������������������������������������8

FFmpeg/avconv �������������������������������������������������������������������������������������������������������������������������������������� 9

GStreamer����������������������������������������������������������������������������������������������������������������������������������������������� 9

Audacity�������������������������������������������������������������������������������������������������������������������������������������������������� 9

Conclusion������������������������������������������������������������������������������������������������������������������������ 9

■Chapter 3: Sound Codecs and File Formats��������������������������������������������������������� 11

Overview ������������������������������������������������������������������������������������������������������������������������ 11

PCM�������������������������������������������������������������������������������������������������������������������������������� 11

WAV �������������������������������������������������������������������������������������������������������������������������������� 12

MP3 �������������������������������������������������������������������������������������������������������������������������������� 12

Ogg Vorbis ���������������������������������������������������������������������������������������������������������������������� 12

WMA������������������������������������������������������������������������������������������������������������������������������� 13

Matroska ������������������������������������������������������������������������������������������������������������������������ 13

Conclusion���������������������������������������������������������������������������������������������������������������������� 14

■Chapter 4: Overview of Linux Sound Architecture����������������������������������������������� 15

Resources����������������������������������������������������������������������������������������������������������������������� 15

Components ������������������������������������������������������������������������������������������������������������������� 15

Device Drivers �������������������������������������������������������������������������������������������������������������������������������������� 16

Sound Servers �������������������������������������������������������������������������������������������������������������������������������������� 17

Complexities ����������������������������������������������������������������������������������������������������������������������������������������� 18

Conclusion���������������������������������������������������������������������������������������������������������������������� 19

■Chapter 5: ALSA��������������������������������������������������������������������������������������������������� 21

Resources����������������������������������������������������������������������������������������������������������������������� 21

User Space Tools ������������������������������������������������������������������������������������������������������������ 21

alsamixer���������������������������������������������������������������������������������������������������������������������������������������������� 21

alsactl ��������������������������������������������������������������������������������������������������������������������������������������������������� 22

speaker-test ����������������������������������������������������������������������������������������������������������������������������������������� 22

aplay/arecord���������������������������������������������������������������������������������������������������������������������������������������� 23

Identifying ALSA Cards ������������������������������������������������������������������������������������������������������������������������� 23

■ Contents

vii

Device Names��������������������������������������������������������������������������������������������������������������������������������������� 24

ALSA Configuration Files ���������������������������������������������������������������������������������������������������������������������� 27

alsa-info ����������������������������������������������������������������������������������������������������������������������������������������������� 27

Applications Using ALSA����������������������������������������������������������������������������������������������������������������������� 32

Programming ALSA �������������������������������������������������������������������������������������������������������� 33

Hardware Device Information��������������������������������������������������������������������������������������������������������������� 34

PCM Device Information ����������������������������������������������������������������������������������������������������������������������� 37

Configuration Space Information���������������������������������������������������������������������������������������������������������� 40

ALSA Initialization��������������������������������������������������������������������������������������������������������������������������������� 46

Capture Audio to a File ������������������������������������������������������������������������������������������������������������������������� 46

Playback Audio from a File ������������������������������������������������������������������������������������������������������������������� 49

Using Interrupts ������������������������������������������������������������������������������������������������������������������������������������ 52

Managing Latency �������������������������������������������������������������������������������������������������������������������������������� 52

Playback of Captured Sound ���������������������������������������������������������������������������������������������������������������� 52

Mixing Audio������������������������������������������������������������������������������������������������������������������� 58

Mixing Using dmix �������������������������������������������������������������������������������������������������������������������������������� 58

Mixing Using PulseAudio ���������������������������������������������������������������������������������������������������������������������� 59

Simple Mixer API: Volume Control��������������������������������������������������������������������������������������������������������� 59

Writing an ALSA Device Driver ��������������������������������������������������������������������������������������� 60

Conclusion���������������������������������������������������������������������������������������������������������������������� 60

■Chapter 6: PulseAudio ����������������������������������������������������������������������������������������� 61

Resources����������������������������������������������������������������������������������������������������������������������� 61

Starting, Stopping, and Pausing PulseAudio ������������������������������������������������������������������ 61

User Space Tools ������������������������������������������������������������������������������������������������������������ 62

paman��������������������������������������������������������������������������������������������������������������������������������������������������� 62

pavumeter �������������������������������������������������������������������������������������������������������������������������������������������� 64

pavucontrol������������������������������������������������������������������������������������������������������������������������������������������� 64

Gnome Control Center (Sound) ������������������������������������������������������������������������������������������������������������� 66

parec/paplay/pacat������������������������������������������������������������������������������������������������������������������������������� 67

pactl/pacmd������������������������������������������������������������������������������������������������������������������������������������������ 68

Device Names��������������������������������������������������������������������������������������������������������������������������������������� 69

■ Contents

viii

Loopback Module ��������������������������������������������������������������������������������������������������������������������������������� 69

PulseAudio and ALSA���������������������������������������������������������������������������������������������������������������������������� 70

Programming with PulseAudio��������������������������������������������������������������������������������������� 70

Simple API ���������������������������������������������������������������������������������������������������������������������� 70

Play a File �������������������������������������������������������������������������������������������������������������������������������������������� 71

Record to a File������������������������������������������������������������������������������������������������������������������������������������� 73

Play from Source to Sink ���������������������������������������������������������������������������������������������������������������������� 76

Asynchronous API����������������������������������������������������������������������������������������������������������� 78

List of Devices �������������������������������������������������������������������������������������������������������������������������������������� 79

Monitoring Ongoing Changes: New Sources and Sinks������������������������������������������������������������������������ 84

Record a Stream����������������������������������������������������������������������������������������������������������������������������������� 89

Play a File ��������������������������������������������������������������������������������������������������������������������������������������������� 93

Play a File Using I/O Callbacks ����������������������������������������������������������������������������������������������������������� 101

Controlling Latency����������������������������������������������������������������������������������������������������������������������������� 112

Play Microphone to Speaker��������������������������������������������������������������������������������������������������������������� 120

Setting the Volume on Devices ����������������������������������������������������������������������������������������������������������� 126

Listing Clients ������������������������������������������������������������������������������������������������������������������������������������� 128

Listing Client Sources and Sinks �������������������������������������������������������������������������������������������������������� 133

Controlling the Volume of a Sink Client ���������������������������������������������������������������������������������������������� 138

Conclusion�������������������������������������������������������������������������������������������������������������������� 141

■Chapter 7: Jack ������������������������������������������������������������������������������������������������� 143

Resources��������������������������������������������������������������������������������������������������������������������� 143

Starting Jack ���������������������������������������������������������������������������������������������������������������� 143

User Tools��������������������������������������������������������������������������������������������������������������������� 146

Applications Using Jack ����������������������������������������������������������������������������������������������� 146

mplayer����������������������������������������������������������������������������������������������������������������������������������������������� 146

VLC������������������������������������������������������������������������������������������������������������������������������������������������������146

TiMidity����������������������������������������������������������������������������������������������������������������������������������������������� 147

Jack-Supplied Programs �������������������������������������������������������������������������������������������������������������������� 147

Other Jack Programs�������������������������������������������������������������������������������������������������������������������������� 147

■ Contents

ix

Using a Different Sound Card��������������������������������������������������������������������������������������� 147

How Can I Use Multiple Sound Cards with Jack?��������������������������������������������������������� 148

Mixing Audio����������������������������������������������������������������������������������������������������������������� 148

Writing Audio Applications with Jack ��������������������������������������������������������������������������� 149

Compiling ��������������������������������������������������������������������������������������������������������������������� 150

Port Information ����������������������������������������������������������������������������������������������������������� 151

Copy Input to Output����������������������������������������������������������������������������������������������������� 153

Delaying Audio�������������������������������������������������������������������������������������������������������������� 157

Audacity with Jack������������������������������������������������������������������������������������������������������� 163

Play a Sine Wave ���������������������������������������������������������������������������������������������������������� 165

Saving Input to Disk ����������������������������������������������������������������������������������������������������� 170

Interacting with ALSA Devices ������������������������������������������������������������������������������������� 177

Conclusion�������������������������������������������������������������������������������������������������������������������� 177

■Chapter 8: Session Management����������������������������������������������������������������������� 179

Resources��������������������������������������������������������������������������������������������������������������������� 179

Session Management Issues���������������������������������������������������������������������������������������� 179

jack_connect���������������������������������������������������������������������������������������������������������������� 181

LASH����������������������������������������������������������������������������������������������������������������������������� 181

Jack Sessions �������������������������������������������������������������������������������������������������������������� 181

LADISH�������������������������������������������������������������������������������������������������������������������������� 184

Jack Session API ���������������������������������������������������������������������������������������������������������� 189

LADISH API ������������������������������������������������������������������������������������������������������������������� 196

Conclusion�������������������������������������������������������������������������������������������������������������������� 196

■Chapter 9: Java Sound �������������������������������������������������������������������������������������� 197

Resources��������������������������������������������������������������������������������������������������������������������� 197

Key Java Sound Classes����������������������������������������������������������������������������������������������� 197

Information About Devices ������������������������������������������������������������������������������������������� 198

Playing Audio from a File���������������������������������������������������������������������������������������������� 199

■ Contents

x

Recording Audio to a File ��������������������������������������������������������������������������������������������� 202

Play Microphone to Speaker ���������������������������������������������������������������������������������������� 206

Where Does JavaSound Get Its Devices From?������������������������������������������������������������ 210

Conclusion�������������������������������������������������������������������������������������������������������������������� 210

■Chapter 10: GStreamer�������������������������������������������������������������������������������������� 211

Resources��������������������������������������������������������������������������������������������������������������������� 211

Overview ���������������������������������������������������������������������������������������������������������������������� 211

Command-Line Processing ������������������������������������������������������������������������������������������ 213

gst-inspect ����������������������������������������������������������������������������������������������������������������������������������������� 213

gst-discoverer ������������������������������������������������������������������������������������������������������������������������������������ 215

gst-device-monitor����������������������������������������������������������������������������������������������������������������������������� 216

gst-play����������������������������������������������������������������������������������������������������������������������������������������������� 216

gst-launch ������������������������������������������������������������������������������������������������������������������������������������������ 217

C Programming ������������������������������������������������������������������������������������������������������������ 217

Writing Plug-ins������������������������������������������������������������������������������������������������������������ 221

Conclusion�������������������������������������������������������������������������������������������������������������������� 221

■Chapter 11: libao ����������������������������������������������������������������������������������������������� 223

Resources��������������������������������������������������������������������������������������������������������������������� 223

libao������������������������������������������������������������������������������������������������������������������������������ 223

Conclusion�������������������������������������������������������������������������������������������������������������������� 225

■Chapter 12: FFmpeg/Libav��������������������������������������������������������������������������������� 227

Resources��������������������������������������������������������������������������������������������������������������������� 227

The FFmpeg/Libav Controversy������������������������������������������������������������������������������������ 227

FFmpeg Command-Line Tools�������������������������������������������������������������������������������������� 228

Programming���������������������������������������������������������������������������������������������������������������� 228

Decoding an MP3 File��������������������������������������������������������������������������������������������������� 229

Conclusion�������������������������������������������������������������������������������������������������������������������� 234

■ Contents

xi

■Chapter 13: OpenMAX IL������������������������������������������������������������������������������������ 235

Resources��������������������������������������������������������������������������������������������������������������������� 235

Quotes �������������������������������������������������������������������������������������������������������������������������� 236

OpenMAX IL Concepts �������������������������������������������������������������������������������������������������� 236

OpenMAX IL Components��������������������������������������������������������������������������������������������� 237

Implementations ���������������������������������������������������������������������������������������������������������� 237

Raspberry Pi ��������������������������������������������������������������������������������������������������������������������������������������� 237

Bellagio����������������������������������������������������������������������������������������������������������������������������������������������� 238

LIM������������������������������������������������������������������������������������������������������������������������������������������������������ 238

Hardware-Supported Versions������������������������������������������������������������������������������������������������������������ 239

Implementations of Components ��������������������������������������������������������������������������������� 239

Getting Information About an IL Component��������������������������������������������������������������������������������������� 244

Playing PCM Audio Files ����������������������������������������������������������������������������������������������� 260

State ��������������������������������������������������������������������������������������������������������������������������������������������������� 260

Threads����������������������������������������������������������������������������������������������������������������������������������������������� 260

Hungarian Notation in OpenMAX IL ���������������������������������������������������������������������������������������������������� 262

Callbacks �������������������������������������������������������������������������������������������������������������������������������������������� 262

Component Resources������������������������������������������������������������������������������������������������������������������������ 262

Setting the Output Device������������������������������������������������������������������������������������������������������������������� 265

Main Loop������������������������������������������������������������������������������������������������������������������������������������������� 265

Complete Program������������������������������������������������������������������������������������������������������������������������������ 266

Conclusion�������������������������������������������������������������������������������������������������������������������� 275

■Chapter 14: LADSPA������������������������������������������������������������������������������������������� 277

Resources��������������������������������������������������������������������������������������������������������������������� 277

User-Level Tools ����������������������������������������������������������������������������������������������������������� 277

The Type LADSPA_Descriptor��������������������������������������������������������������������������������������� 279

Loading a Plug-in ��������������������������������������������������������������������������������������������������������� 280

A Mono Amplifier Client������������������������������������������������������������������������������������������������ 280

A Stereo Amplifer with GUI������������������������������������������������������������������������������������������� 286

■ Contents

xii

The amp Program��������������������������������������������������������������������������������������������������������� 291

Conclusion�������������������������������������������������������������������������������������������������������������������� 292

■Chapter 15: Displaying Video with Overlays Using Gtk and FFmpeg����������������� 293

FFmpeg ������������������������������������������������������������������������������������������������������������������������ 293

Basic Gtk ���������������������������������������������������������������������������������������������������������������������� 297

Versions of Gtk ������������������������������������������������������������������������������������������������������������� 299

Displaying the Video Using Gtk������������������������������������������������������������������������������������� 300

Pixmaps���������������������������������������������������������������������������������������������������������������������������������������������� 300

Pixbufs������������������������������������������������������������������������������������������������������������������������������������������������ 300

X, Wayland, and Mir���������������������������������������������������������������������������������������������������������������������������� 300

Gtk 3.0 ������������������������������������������������������������������������������������������������������������������������������������������������ 301

Gtk 2.0 ������������������������������������������������������������������������������������������������������������������������������������������������ 301

Threads and Gtk ��������������������������������������������������������������������������������������������������������������������������������� 302

The Code��������������������������������������������������������������������������������������������������������������������������������������������� 302

Overlaying an Image on Top of an Image ��������������������������������������������������������������������� 306

Alpha Channel �������������������������������������������������������������������������������������������������������������� 308

Using Cairo to Draw on an Image��������������������������������������������������������������������������������� 309

Drawing Text Using Pango�������������������������������������������������������������������������������������������� 312

Conclusion�������������������������������������������������������������������������������������������������������������������� 315

■Chapter 16: MIDI������������������������������������������������������������������������������������������������ 317

Resources��������������������������������������������������������������������������������������������������������������������� 317

Components of a MIDI System ������������������������������������������������������������������������������������� 317

Synthesizer����������������������������������������������������������������������������������������������������������������������������������������� 317

Sequencers����������������������������������������������������������������������������������������������������������������������������������������� 318

Other Components������������������������������������������������������������������������������������������������������������������������������ 318

MIDI Events ������������������������������������������������������������������������������������������������������������������ 318

Program Change Events ��������������������������������������������������������������������������������������������������������������������� 318

Note Events ���������������������������������������������������������������������������������������������������������������������������������������� 318

Meta Events���������������������������������������������������������������������������������������������������������������������������������������� 318

Conclusion�������������������������������������������������������������������������������������������������������������������� 319

■ Contents

xiii

■Chapter 17: User-Level Tools for MIDI ��������������������������������������������������������������� 321

Resources��������������������������������������������������������������������������������������������������������������������� 321

Sound Fonts ����������������������������������������������������������������������������������������������������������������� 321

TiMidity������������������������������������������������������������������������������������������������������������������������� 322

TiMidity as a Server���������������������������������������������������������������������������������������������������������������������������� 322

Setting TiMidity Output Device ����������������������������������������������������������������������������������������������������������� 323

TiMidity and Jack ������������������������������������������������������������������������������������������������������������������������������� 323

GStreamer �������������������������������������������������������������������������������������������������������������������� 323

fluidsynth���������������������������������������������������������������������������������������������������������������������� 324

fluidsynth as a Server������������������������������������������������������������������������������������������������������������������������� 324

Rosegarden ������������������������������������������������������������������������������������������������������������������ 324

WildMIDI ����������������������������������������������������������������������������������������������������������������������� 324

Comparison ������������������������������������������������������������������������������������������������������������������ 324

VLC ������������������������������������������������������������������������������������������������������������������������������� 325

Conclusion�������������������������������������������������������������������������������������������������������������������� 325

■Chapter 18: MIDI Java Sound ���������������������������������������������������������������������������� 327

Resources��������������������������������������������������������������������������������������������������������������������� 327

Key Java Sound MIDI Classes �������������������������������������������������������������������������������������� 327

Device Information ������������������������������������������������������������������������������������������������������� 328

Dumping a MIDI File ����������������������������������������������������������������������������������������������������� 330

Playing a MIDI File�������������������������������������������������������������������������������������������������������� 334

Changing the Soundbank ��������������������������������������������������������������������������������������������� 340

Changing Pitch and Speed ������������������������������������������������������������������������������������������� 340

Using TiMidity Instead of the Default Gervill Synthesizer��������������������������������������������� 342

Conclusion�������������������������������������������������������������������������������������������������������������������� 342

■Chapter 19: MIDI ALSA �������������������������������������������������������������������������������������� 343

Resources��������������������������������������������������������������������������������������������������������������������� 343

ALSA Sequencer Clients����������������������������������������������������������������������������������������������� 343

aconnect����������������������������������������������������������������������������������������������������������������������� 344

■ Contents

xiv

seqdemo����������������������������������������������������������������������������������������������������������������������� 345

aplaymidi���������������������������������������������������������������������������������������������������������������������� 346

Raw MIDI Ports������������������������������������������������������������������������������������������������������������� 347

Raw MIDI Physical Devices����������������������������������������������������������������������������������������������������������������� 347

Raw MIDI Virtual Devices�������������������������������������������������������������������������������������������������������������������� 347

Mapping MIDI Clients into MIDI Raw Space���������������������������������������������������������������������������������������� 348

Turning Off All Notes����������������������������������������������������������������������������������������������������� 349

Conclusion�������������������������������������������������������������������������������������������������������������������� 349

■Chapter 20: FluidSynth�������������������������������������������������������������������������������������� 351

Resources��������������������������������������������������������������������������������������������������������������������� 351

Players�������������������������������������������������������������������������������������������������������������������������� 351

Play MIDI Files�������������������������������������������������������������������������������������������������������������� 352

Python �������������������������������������������������������������������������������������������������������������������������� 353

Conclusion�������������������������������������������������������������������������������������������������������������������� 353

■Chapter 21: TiMidity ������������������������������������������������������������������������������������������ 355

TiMidity Design������������������������������������������������������������������������������������������������������������� 355

Turning TiMidity into a Library�������������������������������������������������������������������������������������� 356

Managed Environments Hook������������������������������������������������������������������������������������������������������������� 356

Building the Library ���������������������������������������������������������������������������������������������������������������������������� 356

Library Entry Points ���������������������������������������������������������������������������������������������������������������������������� 357

A Minimal Application������������������������������������������������������������������������������������������������������������������������� 357

Playing a Background Video to a MIDI File ����������������������������������������������������������������������������������������� 358

Building a New Interface���������������������������������������������������������������������������������������������� 360

Shared Objects ����������������������������������������������������������������������������������������������������������������������������������� 360

Entry Point������������������������������������������������������������������������������������������������������������������������������������������ 360

ControlMode ��������������������������������������������������������������������������������������������������������������������������������������� 361

Include Files ��������������������������������������������������������������������������������������������������������������������������������������� 362

My Simple Interface���������������������������������������������������������������������������������������������������������������������������� 362

Tải ngay đi em, còn do dự, trời tối mất!