Jan Newmarch

Linux Sound Programming

Jan Newmarch

Oakleigh, Victoria, Australia

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 .

ISBN 978-1-4842-2495-3

e-ISBN 978-1-4842-2496-0

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

Library of Congress Control Number: 2017931692

© Jan Newmarch 2017

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.

Printed on acid-free paper

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 [email protected], 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.

Contents

  1. Chapter 1:​ Basic Concepts of Sound
    1. Sampled Audio
    2. Sample Rate
    3. Sample Format
    4. Frames
    5. Pulse-Code Modulation
    6. Overrun and Underrun
    7. Latency
    8. Jitter
    9. Mixing
    10. Conclusion
  2. Chapter 2:​ User-Level Tools
    1. Players
      1. MPlayer
      2. VLC
      3. Totem
    2. Sound Tools
      1. sox
      2. FFmpeg/​avconv
      3. GStreamer
      4. Audacity
    3. Conclusion
  3. Chapter 3:​ Sound Codecs and File Formats
    1. Overview
    2. PCM
    3. WAV
    4. MP3
    5. Ogg Vorbis
    6. WMA
    7. Matroska
    8. Conclusion
  4. Chapter 4:​ Overview of Linux Sound Architecture
    1. Resources
    2. Components
      1. Device Drivers
      2. Sound Servers
      3. Complexities
    3. Conclusion
  5. Chapter 5:​ ALSA
    1. Resources
    2. User Space Tools
      1. alsamixer
      2. alsactl
      3. speaker-test
      4. aplay/​arecord
      5. Identifying ALSA Cards
      6. Device Names
      7. ALSA Configuration Files
      8. alsa-info
      9. Applications Using ALSA
    3. Programming ALSA
      1. Hardware Device Information
      2. PCM Device Information
      3. Configuration Space Information
      4. ALSA Initialization
      5. Capture Audio to a File
      6. Playback Audio from a File
      7. Using Interrupts
      8. Managing Latency
      9. Playback of Captured Sound
    4. Mixing Audio
      1. Mixing Using dmix
      2. Mixing Using PulseAudio
      3. Simple Mixer API:​ Volume Control
    5. Writing an ALSA Device Driver
    6. Conclusion
  6. Chapter 6:​ PulseAudio
    1. Resources
    2. Starting, Stopping, and Pausing PulseAudio
    3. User Space Tools
      1. paman
      2. pavumeter
      3. pavucontrol
      4. Gnome Control Center (Sound)
      5. parec/​paplay/​pacat
      6. pactl/​pacmd
      7. Device Names
      8. Loopback Module
      9. PulseAudio and ALSA
    4. Programming with PulseAudio
    5. Simple API
      1. Play a File
      2. Record to a File
      3. Play from Source to Sink
    6. Asynchronous API
      1. List of Devices
      2. Monitoring Ongoing Changes:​ New Sources and Sinks
      3. Record a Stream
      4. Play a File
      5. Play a File Using I/​O Callbacks
      6. Controlling Latency
      7. Play Microphone to Speaker
      8. Setting the Volume on Devices
      9. Listing Clients
      10. Listing Client Sources and Sinks
      11. Controlling the Volume of a Sink Client
    7. Conclusion
  7. Chapter 7:​ Jack
    1. Resources
    2. Starting Jack
    3. User Tools
    4. Applications Using Jack
      1. mplayer
      2. VLC
      3. TiMidity
      4. Jack-Supplied Programs
      5. Other Jack Programs
    5. Using a Different Sound Card
    6. How Can I Use Multiple Sound Cards with Jack?​
    7. Mixing Audio
    8. Writing Audio Applications with Jack
    9. Compiling
    10. Port Information
    11. Copy Input to Output
    12. Delaying Audio
    13. Audacity with Jack
    14. Play a Sine Wave
    15. Saving Input to Disk
    16. Interacting with ALSA Devices
    17. Conclusion
  8. Chapter 8:​ Session Management
    1. Resources
    2. Session Management Issues
    3. jack_​connect
    4. LASH
    5. Jack Sessions
    6. LADISH
    7. Jack Session API
    8. LADISH API
    9. Conclusion
  9. Chapter 9:​ Java Sound
    1. Resources
    2. Key Java Sound Classes
    3. Information About Devices
    4. Playing Audio from a File
    5. Recording Audio to a File
    6. Play Microphone to Speaker
    7. Where Does JavaSound Get Its Devices From?​
    8. Conclusion
  10. Chapter 10:​ GStreamer
    1. Resources
    2. Overview
    3. Command-Line Processing
      1. gst-inspect
      2. gst-discoverer
      3. gst-device-monitor
      4. gst-play
      5. gst-launch
    4. C Programming
    5. Writing Plug-ins
    6. Conclusion
  11. Chapter 11:​ libao
    1. Resources
    2. libao
    3. Conclusion
  12. Chapter 12:​ FFmpeg/​Libav
    1. Resources
    2. The FFmpeg/​Libav Controversy
    3. FFmpeg Command-Line Tools
    4. Programming
    5. Decoding an MP3 File
    6. Conclusion
  13. Chapter 13:​ OpenMAX IL
    1. Resources
    2. Quotes
    3. OpenMAX IL Concepts
    4. OpenMAX IL Components
    5. Implementations
      1. Raspberry Pi
      2. Bellagio
      3. LIM
      4. Hardware-Supported Versions
    6. Implementations of Components
      1. Getting Information About an IL Component
    7. Playing PCM Audio Files
      1. State
      2. Threads
      3. Hungarian Notation in OpenMAX IL
      4. Callbacks
      5. Component Resources
      6. Setting the Output Device
      7. Main Loop
      8. Complete Program
    8. Conclusion
  14. Chapter 14:​ LADSPA
    1. Resources
    2. User-Level Tools
    3. The Type LADSPA_​Descriptor
    4. Loading a Plug-in
    5. A Mono Amplifier Client
    6. A Stereo Amplifer with GUI
    7. The amp Program
    8. Conclusion
  15. Chapter 15:​ Displaying Video with Overlays Using Gtk and FFmpeg
    1. FFmpeg
    2. Basic Gtk
    3. Versions of Gtk
    4. Displaying the Video Using Gtk
      1. Pixmaps
      2. Pixbufs
      3. X, Wayland, and Mir
      4. Gtk 3.​0
      5. Gtk 2.​0
      6. Threads and Gtk
      7. The Code
    5. Overlaying an Image on Top of an Image
    6. Alpha Channel
    7. Using Cairo to Draw on an Image
    8. Drawing Text Using Pango
    9. Conclusion
  16. Chapter 16:​ MIDI
    1. Resources
    2. Components of a MIDI System
      1. Synthesizer
      2. Sequencers
      3. Other Components
    3. MIDI Events
      1. Program Change Events
      2. Note Events
      3. Meta Events
    4. Conclusion
  17. Chapter 17:​ User-Level Tools for MIDI
    1. Resources
    2. Sound Fonts
    3. TiMidity
      1. TiMidity as a Server
      2. Setting TiMidity Output Device
      3. TiMidity and Jack
    4. GStreamer
    5. fluidsynth
      1. fluidsynth as a Server
    6. Rosegarden
    7. WildMIDI
    8. Comparison
    9. VLC
    10. Conclusion
  18. Chapter 18:​ MIDI Java Sound
    1. Resources
    2. Key Java Sound MIDI Classes
    3. Device Information
    4. Dumping a MIDI File
    5. Playing a MIDI File
    6. Changing the Soundbank
    7. Changing Pitch and Speed
    8. Using TiMidity Instead of the Default Gervill Synthesizer
    9. Conclusion
  19. Chapter 19:​ MIDI ALSA
    1. Resources
    2. ALSA Sequencer Clients
    3. aconnect
    4. seqdemo
    5. aplaymidi
    6. Raw MIDI Ports
      1. Raw MIDI Physical Devices
      2. Raw MIDI Virtual Devices
      3. Mapping MIDI Clients into MIDI Raw Space
    7. Turning Off All Notes
    8. Conclusion
  20. Chapter 20:​ FluidSynth
    1. Resources
    2. Players
    3. Play MIDI Files
    4. Python
    5. Conclusion
  21. Chapter 21:​ TiMidity
    1. TiMidity Design
    2. Turning TiMidity into a Library
      1. Managed Environments Hook
      2. Building the Library
      3. Library Entry Points
      4. A Minimal Application
      5. Playing a Background Video to a MIDI File
    3. Building a New Interface
      1. Shared Objects
      2. Entry Point
      3. ControlMode
      4. Include Files
      5. My Simple Interface
      6. Running My Simple Interface
      7. Playing a Background Video to a MIDI File
    4. Conclusion
  22. Chapter 22:​ Overview of Karaoke Systems
  23. Chapter 23:​ Karaoke User-Level Tools
    1. Video CD Systems
    2. CD+G Discs
    3. MP3+G Files
    4. Buying CD+G or MP3+G Files
    5. Converting MP3+G to Video Files
    6. MPEG-4 Files
    7. Karaoke Machines
    8. MIDI Players
    9. Finding MIDI Files
    10. KAR File Format
    11. PyKaraoke
    12. kmid 3
    13. Microphone Inputs and Reverb Effects
    14. Conclusion
  24. Chapter 24:​ MP3+G
    1. File Organization
    2. Song Information
    3. Song Table
    4. Favorites
    5. All Favorites
    6. Swing Song Table
    7. Playing Songs
    8. VLC
    9. Playing Songs Across the Network
    10. Conclusion
  25. Chapter 25:​ Karaoke Applications Using Java Sound
    1. Resources
    2. KaraokePlayer
    3. MidiPlayer
    4. DisplayReceiver
    5. MidiGUI
    6. AttributedLyricP​anel
    7. PianoPanel
    8. MelodyPanel
    9. SequenceInformat​ion
    10. PinYin
    11. Karaoke Player with Sampling
    12. Comments on Device Choices
    13. Performance
    14. Conclusion
  26. Chapter 26:​ Subtitles and Closed Captions
    1. Resources
    2. Subtitle Formats
      1. MPlayer
      2. VLC
      3. Gnome Subtitles
      4. SubStation Alpha
    3. Karaoke Effects in ASS Files
    4. Multiline Karaoke
    5. libass
    6. Converting KAR Files to MKV Files with ASS Subtitles
    7. HTML5 Subtitles
    8. Conclusion
  27. Chapter 27:​ Karaoke FluidSynth
    1. Resources
    2. Players
    3. Play MIDI Files
    4. Extending FluidSynth with Callbacks
    5. Displaying and Coloring Text with Gtk
    6. Playing a Background Video with Gtk
    7. Conclusion
  28. Chapter 28:​ TiMidity and Karaoke
    1. TiMidity and Jack
    2. TiMidity Interface
    3. Getting the List of Lyrics
    4. TiMidity Options
    5. Playing Lyrics Using Pango + Cairo + Xlib
    6. Playing a Background Video with Gtk
    7. Background Video with TiMidity as Library
    8. Background Video with TiMidity as Front End
    9. Adding Microphone Input
    10. Conclusion
  29. Chapter 29:​ Jack and Karaoke
    1. Using Jack Rack for Effects
    2. Playing MIDI
    3. TiMidity Plus Jack Rack
    4. Customizing TiMidity Build
    5. Playing MP3+G with Jack Rack Pitch Shifting
    6. Conclusion
  30. Chapter 30:​ Streaming Audio
    1. HTTP
      1. HTTP Servers
      2. HTTP Clients
      3. Streaming vs.​ Downloading
    2. HTML5
    3. DLNA
    4. Icecast
    5. Flumotion
    6. Conclusion
  31. Chapter 31:​ Raspberry Pi
    1. Resources
    2. The Basics
      1. Hardware
      2. Alternative Single-Board Computers
      3. Distros
    3. No Sound
    4. ALSA
    5. Sampled Audio Players
      1. MPlayer
      2. VLC
      3. alsaplayer
      4. omxplayer
      5. Is It X Using the CPU?​
    6. Sampled Audio Capture
      1. ALSA
    7. MIDI Players
      1. TiMidity
      2. pykaraoke
      3. FluidSynth/​qsynth
    8. Java Sound
    9. PulseAudio
    10. Java MIDI
    11. OpenMAX
    12. Conclusion
  32. Chapter 32:​ Conclusion
    1. Where Did I Start?​
    2. Where Did I Get To?​
    3. How Did I Get There?​
  33. Appendix A:​ Decoding the DKD Files on the Sonken Karaoke DVD
    1. Introduction
    2. Format Shifting
    3. Files on the DVD
      1. BACK01.​MPG
      2. DTSMUS00.​DKD to DTSMUS07.​DKD
      3. DTSMUS10.​DKD
      4. DTSMUS20.​DKD
    4. Decoding DTSMUS20.​DKD
      1. Song Information
      2. Beginning/​End of Data
      3. Chinese Songs
      4. Other Languages
      5. Programs
    5. The Data Files
      1. General
      2. My Route into This
      3. The Superblock
      4. Song Start Tables
      5. Locating Song Entry from Song Number
      6. Song Entries
      7. Song Data
    6. Decoding MIDI Files
      1. Lyric Block
    7. Playing MIDI Files
    8. Playing WMA Files
    9. KAR Format
    10. Playing Songs with pykar
      1. Tempo
      2. Language Encoding
      3. Songs with No Notes
    11. Conclusion
  34. Index

About the Author and About the Technical Reviewer

About the Author

A435426_1_En_BookFrontmatter_Figb_HTML.jpg

Jan Newmarch is the head of ICT (Higher Education) at Box Hill Institute, adjunct professor at Canberra University, and adjunct lecturer in the School of Information Technology, Computing, and Mathematics at Charles Sturt University. He is interested in more aspects of computing than he has time to pursue, but the major thrust over the last few years has developed from user interfaces under Unix into Java and the Web and then into general distributed systems. Jan developed a number of publicly available software systems in these areas. For the last few years he has been looking at sound for Linux systems and programming the Raspberry Pi’s GPU. He is now exploring aspects of the IoT. He lives in Melbourne, Australia, and enjoys the food and culture there but is not so impressed by the weather.

About the Technical Reviewer

A435426_1_En_BookFrontmatter_Figc_HTML.jpg

Jeff Tranter has been using Linux since 1992 and has written and contributed to a number of open source and commercial Linux applications and tools. He has written about Linux and multimedia in numerous magazine articles, Linux HOWTOs, and books, including Linux Multimedia Guide way back in 1996. Jeff received his bachelor’s degree in electrical engineering from the University of Western Ontario. He currently works as an engineering manager for a software consulting company, telecommuting from Ottawa in Ontario, Canada.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset