Home > Store

Programmer's Guide to Sound, A

Register your product to gain access to bonus material or receive a coupon.

Programmer's Guide to Sound, A

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 1998
  • Dimensions: 7-3/8" x 9-1/8"
  • Pages: 464
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-41972-6
  • ISBN-13: 978-0-201-41972-6

Author appearance

"I just wish this book had been available years ago."
-Bobby Prince, composer and sound designer for computer games including Doom and Duke Nukem 3D

"This is the kind of book that will stand as one of the defining works in the specialization of audio programming."
-Gene Turnbow, senior programmer and game designer for Sound Source Interactive, Inc.

"I'm amazed at the breadth and depth of Tim's coverage."
-George Wright
Information Systems, Loyola College, Maryland

A Programmer's Guide To Sound provides detailed technical information about audio storage, processing, and compression, and includes tested C++ source code. Developers who want to add sound technology to their applications will find all the details they need to:

  • access low-level sound services on Win32, Mac OS, and UNIX
  • decompress MPEG, IMA ADPCM, and µ-Law data
  • read from WAVE, VOC, AIFF, and AU file formats
  • play MIDI and MOD music files.

This book also includes accessible introductions to related topics, such as instrument synthesis, musical tuning, human sound perception, digital filtering, and Fourier Transforms.

Developers will especially appreciate the emphasis placed on practical details. For every topic, the author provides complete source code to demonstrate the principles involved. The source code from the book compiles into a sample program that reads and plays a wide variety of different sound files on Win32, Mac OS, and UNIX. The CD-ROM includes all 40,000 lines of source code from the book, in addition to project files for popular compilers, sample sound files, and contributed software and related information.

Whether you are an audio professional who wants to learn more about programming or a computer programmer who wants to know more about implementing audio, this comprehensive resource will be an invaluable reference for years to come.



0201419726B04062001

Downloads

CD Contents

Untitled Document Download the CD Contents related to this title.

Sample Content

Table of Contents



Introduction.


Source Code.


About This Book.


Acknowledgements.

I. BASICS.

1. From Hollow Logs to Cyberspace.

What is Sound?

Natural Sounds.

Electronic Sounds.

Sounds We Hear.

Digital Sounds.

Other Resources.

2. Human Sound Perception.

Frequency and Pitch.

Musical Pitch.

Pitch and Frequency Aren’t the Same.

Noise.

Loudness, Amplitude, and Power.

Overall Quality.

3. Storing Sound Digitally.

Sampled Sound Formats.

Pulse Amplitude Modulation (PAM).

Pulse Width Modulation (PWM).

Pulse Code Modulation (PCM).

Side Effects of Sampling.

Aliasing.

Output Aliasing.

Resampling.

Quantization Error.

Dithering.

Clipping.

Floating-Point Samples.

4. A C++ Sound Framework.

The AudioAbstract Class.

Stereo.

Negotiation.

Reading and Writing Integers.

A SineWave Class.

II. SYSTEM SPECIFICS.

5. Player Objects.

Player Basics.

Implementing the Queue.

Opening an Unknown Sound File.

6. Playing Audio on Windows.

Play.

The Callback.

Selecting an Audio Device.

A Sample Windows Application.

7. Playing Audio on Mac OS.

Callback.

Double Buffered Sound Under Mac OS.

A Sample Mac OS Program.

Playing a Mac File.

8. UNIX and the Network Audio System.

Servers and Flows.

Callbacks and Events.

Configuring a Flow and Attaching to the Server.

A Sample UNIX Application.

III. COMPRESSION.

9. Audio Compression.

Lossless Compression.

Non-Linear PCM.

Differential PCM.

Adaptive Differential PCM.

Predictor-Based Compression.

Subband Coding.

Human Speech Compression.

Checkpointing.

Progressive Compression.

10. Decompression Classes.

8-Bit PCM.

Signed 8-Bit PCM.

Unsigned 8-Bit PCM.

16-Bit PCM.

MSB 16-Bit PCM.

LSB 16-Bit PCM.

11. Nonlinear Sound Formats.

Logarithmic Compression.

mu-Law Compression.

A-Law.

Properties of Logarithmic Encodings.

12. Differential PCM.

Two DPCM Encodings.

13. IMA ADPCM Compression.

General Operation.

Decompression.

Compression.

Practical IMA ADPCM Decompression.

Microsoft’s IMA ADPCM Variant.

Apple’s IMA ADPCM Variant.

Comparing Microsoft’s and Apple’s IMA ADPCM Codecs Notes on IMA ADPCM.

Unraveling ADPCM Formats.

Credits.

14. MPEG Audio.

A Survey of the MPEG Standards.

MPEG-1.

MPEG-2.

MPEG-3.

MPEG-4.

MPEG Audio.

General Structure.

Managing the Byte Stream.

MPE’s Frame Header.

Slots and Frames.

Layer 1/Layer 2 Subband Synthesis.

Matrixing.

Slow Matrixing.

Fast Matrixing.

Synthesis Window Coefficients.

MPEG Stereo Encoding.

Layer 1.

Layer 1 Allocation Storage.

Layer 1 Scale Factors.

Layer 1 Sample Storage.

Layer 1 Requantization and Scaling.

Layer 2.

Layer 2 Allocation Storage.

Layer 2 Scale Factors.

Reading Layer 2 Samples.

Layer 2 Requantization.

Layer 3.

A Reader for MPEG Files.

More Information.

IV. GENERAL FILE FORMATS.

15. AU File Format.

Identifying AU Files.

Reading AU Files.

Writing AU Files.

A Simple AU Filter.

16. VOC File Format.

Identifying VOC Files.

VOC Header.

Data Blocks.

Terminator Block (Type 0).

Sound Data Block (Type 1).

Sound Continuation Block (Type 2).

Silence Block (Type 3).

Marker Block (Type 4).

Text Block (Type 5).

Repeat Loops (Types 6 and 7).

Extension Block (Type 8).

Extension Block (Type 9).

Other Blocks.

Reading VOC Files.

17. WAVE File Format.

Identifying WAVE Files.

About RIFF and other IFF Files.

An Overview of WAVE.

The WaveRead Class.

Reading WAVE Files.

Containers.

The RIFF WAVE Container.

The fmt Chunk.

Creating a Decompression Object.

PCM Data.

IMA ADPCM Data.

mu-Law and A-Law.

Other Compression Methods.

The data Chunk.

Text chunks.

18. AIFF and AIFF-C File Formats.

Identifying AIFF Files.

The AiffRead Class.

Reading AIFF Files.

Containers.

The FORM AIFF Container.

The FVER Chunk.

The COMM Chunk.

PCM Data.

mu-Law Data.

IMA ADPCM Data.

The SSND Chunk.

19. IFF/8SVX File Format.

Identifying IFF/8SVX Files.

An Overview of IFF/8SVX.

Reading IFF/8SVX Files.

Overview.

Containers.

The FORM 8SVX Container.

The VHDR Chunk.

PCM Data.

Fibonacci DPCM Encoding.

Exponential DPCM Encoding.

The BODY Chunk.

IFF/8SVX Errata.

Text Chunks.

V. MUSIC FILE FORMATS.

20. Programming Music.

Instruments.

Notes.

21. Synthesizing Instruments.

Sampled Instruments.

A Sine Wave Generator.

Amplitude Control.

Envelope Control with Sampled Instruments.

Other Types of Envelope Control.

FM and Wavetable Synthesis.

Plucked Strings.

Implementing the Plucked-String Algorithm.

Testing Notes.

22. MIDI.

Standard MIDI Files.

Identifying MIDI Files.

MIDI Header Chunk.

MIDI Tracks.

Variable-Length Integers.

Delta Times.

Reading MIDI Tracks.

MIDI Events.

Numbering Conventions.

Running Status.

Managing MIDI Events.

Reading MIDI Events.

Sysex Events.

Meta Events.

Track Sequence Number Meta Event (Type 0).

Text Meta Events (Types 1 through 15).

End of Track Meta Event (Type 47).

Tempo Meta Event (Type 81).

Time Signature (Type 88).

Key Signature Meta Event (Type 89).

Sequencer-Specific Meta Events (Type 127).

MIDI Timing.

SMPTE-Based Timing.

Tempo-Based Timing.

General MIDI.

Downloadable Samples.

A MIDI Player.

Post-Processing the MIDI Event Stream.

Base and Extended MIDI.

Playing a MIDI Event Stream.

MIDI Channels.

Aftertouch and Pitch Wheel.

Controllers and Modes.

7-Bit Controllers.

14-Bit Controllers.

Parameters.

Channel Modes.

Implementation.

MIDI Tuning.

MIDI Instruments.

Caveats.

MIDI Wire Protocol.

Real-Time Commands.

Other MIDI File Formats.

23. MOD.

Identifying MOD Files.

Amiga Sound Hardware.

MOD Format Overview.

Instruments.

Timing.

Notes.

Beats.

Patterns.

Play list.

Format Details.

Instruments.

Notes.

Song Storage.

Overall File Structure.

Playing MOD Files.

The PlayBeat Method.

Playing Notes with Effects.

Effect 0: Arpeggio.

Effect 1: Slide Up.

Effect 2: Slide Down.

Effect 3: Pitch Slide.

Effect 4: Vibrato.

Effect 5: Pitch Slide plus Volume Slide.

Effect 6: Vibrato plus Volume Slide.

Effect 7: Tremolo.

Effect 8: Unused.

Effect 9: Set Sample Offset.

Effect 10: Volume Slide.

Effect 11: Far Jump.

Effect 12: Set Volume.

Effect 13: Pattern Break (Small Jump).

Effect 14/0: Set Filter.

Effect 14/1: Fine Slide Up.

Effect 14/2: Fine Slide Down.

Effect 14/3: Set Glissando.

Effect 14/4: Set Vibrato Waveform.

Effect 14/5: Set Finetune.

Effect 14/6: Pattern Loop.

Effect 14/7: Set Tremolo Waveform.

Effect 14/8: Unused.

Effect 14/9: Retrigger.

Effect 14/10: Volume Up.

Effect 14/11: Volume Down.

Effect 14/12: Cut Note.

Effect 14/13: Delay Note.

Effect 14/14: Delay Pattern.

Effect 14/15: Invert Loop.

Effect 15: Set Speed.

VI. AUDIO PROCESSING.

24. Fourier Transforms.

Fourier Transform Basics.

Sine Waves.

Measuring One Frequency at a Time.

Accounting for Phase.

Implementing the DFT.

Scaling.

Measuring the Entire Spectrum at Once.

Small FFTs.

Decomposing Long FFTs.

2-Point FFT.

Four-Point FFTs.

Formal Derivation of the FFT.

Programming the FFT.

Speed.

Playing with FFTs.

Using FFTs.

Windowing.

Observations.

25. Filtering.

Adding Sine Waves.

FIR Filters.

Designing Simple FIR Filters.

Implementing FIR Filters.

Phase Shift.

IIR Filters.

Music Synthesis with Filters.

II. APPENDICES.

A. About the CD-ROM.

Source Code.

Project Files.

Windows.

Mac OS.

UNIX.

Others.

Sample Files.

Contributed Materials.

Sound Forge.

Cool Edit 96.

Articles on Music Production by Donald Griffin.

SoundApp.

WHAM.

XAudio.

B. A Brief Introduction to C++.

Improving C: A Better struct.

Toward Object-Oriented Programming.

Real OOP: Classes and Inheritance.

Inheritance.

Virtual Functions.

Real-World Considerations.

Constructor Initializations.

Double-Colon Notation.

Defining Methods in Separate Files.

C++ I/O.

Operator Overloading.

I/O.

Miscellany.

C++ Casts.

References.

this.

Friends.

C. Coding Style.
D. Systems Used.
E. Reusing My Source Code.
Index. 0201419726T04062001

Introduction

Some years ago, I found myself researching a variety of different file formats. For graphics formats such as GIF, I had no trouble finding good, detailed descriptions of the overall format and the bit-by-bit details of the underlying compression. However, I was hard pressed to find comparable information for even the most popular audio formats. Although basic formats are outlined in several places, solid information about the compression methods used is surprisingly hard to find.

I'm clearly not the only person to have encountered this problem. I've seen many audio tools that boast of support for a vast number of file formats but lack support for any compression methods at all.

In the intervening years, I have managed to piece together much of the necessary information and wrote this book to bring it together in a single place. This book documents a variety of common audio file formats and audio compression standards and also discusses many related issues that arise in programming audio on a variety of systems.

Source Code

As a programmer, I'm often frustrated when otherwise excellent books stop just short of giving me the details I need. For that reason, when I write about programming, I include detailed, tested source code. Even if the text description omits some critical detail, you can always look at the source code, which must somehow address that issue. By organizing the book around the source code, I hope to ensure that every detail you need is here.

In many cases, you may be able to use my source code directly in your software project. I encourage you to do so. But please pay attention to the conditions listed at the top of each source file. If you have any questions, please feel free to contact me through the publisher. Even if you don't have questions, I'd like to hear about how you used my code and what your experiences were. If there's enough interest and the publisher is willing, I may update this book to better fit your needs.

About This Book

The software in this book was tested by automatically extracting the source code from the electronic files for the book. The book was produced using noweb, LaTeX2e and dvips typesetting software running on FreeBSD 2.1. The source code was tested under FreeBSD 2.1 with the GNU GCC compiler suite, Windows 95 using Microsoft Visual C++ 5.0, and Mac OS 7.6 using Metrowerks CodeWarrior Gold 11. NuMega's BoundsChecker and ParaSoft's CodeWizard were also used to test the source. The text fonts are Adobe Garamond and Computer Modern Typewriter; headings are in Adobe Helvetica and Monotype Arial. Artwork is from the Digitart Musicville collection from Image Club Graphics.

Acknowledgements

Many people have generously contributed to the production of this book: Mary Treseler and the staff at Addison-Wesley patiently endured my seemingly endless revisions and last-minute changes. George Wright, John Miles, Bobby Prince, Gene Turnbow, Tom White, and several others provided thoughtful, honest criticism of my early drafts, which immeasurably improved the end product. Jon Erickson and the staff at Dr. Dobb's supported my efforts. Above all, Beth provided invaluable help in organizing, editing, indexing, and endless other tasks.

As always, any errors that remain are my own.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020