CHAPTER 5

A Choir of Bells

In this chapter, the simple bell program developed in Chapter 4 is built up into a bell choir capable of playing any score you care to type into an ordinary text file. Several scores that it can play are included on the companion disk.

The code examples of Chapter 4 are difficult to use in the more demanding project of this chapter. A whole new approach to writing these programs is needed. The old “monolithic” style, which uses global variables and built-in constants, must be abandoned. The first order of business is planning the project. Then, a modern, encapsulated programming style is developed to support the many bells needed in the bell choir.

5.1 PLANNING THE PROJECT

The bell choir will be driven by a musical score stored in a disk file. There are two basic events that must be handled by each bell: striking and muting. A bell may be muted at a specific time, allowed to ring until it is inaudible, or struck several times without any muting. An unmuted bell rings for a long time before becoming inaudible, but it will eventually stop sounding. The program should, therefore, check for active bells that are no longer loud enough to be heard and can, therefore, be inactivated to save computation time.

Two basic approaches are possible for storing all the required bells. First, an array of all bells that might be needed could be established before any music is produced. The whole array of bells would exist, even though only a few would be used at any one ...

Get Signal Processing in C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.