logo资料库

The Haskell School of Music -- From Signals to Symphonies.pdf

第1页 / 共441页
第2页 / 共441页
第3页 / 共441页
第4页 / 共441页
第5页 / 共441页
第6页 / 共441页
第7页 / 共441页
第8页 / 共441页
资料共441页,剩余部分请下载后查看
Table of Contents
List of Figures
List of Tables
Preface
Computer Music, Euterpea, and Haskell
The Note vs. Signal Dichotomy
Basic Principles of Programming
Computation by Calculation
Expressions and Values
Types
Function Types and Type Signatures
Abstraction, Abstraction, Abstraction
Haskell Equality vs. Euterpean Equality
Code Reuse and Modularity
[Advanced] Programming with Numbers
Simple Music
Preliminaries
Notes, Music, and Polymorphism
Convenient Auxiliary Functions
Absolute Pitches
Polymorphic & Higher-Order Functions
Polymorphic Types
Abstraction Over Recursive Definitions
Append
Fold
[Advanced] A Final Example: Reverse
Currying
Errors
A Musical Interlude
Modules
Transcribing an Existing Score
Simple Algorithmic Composition
Syntactic Magic
Sections
Anonymous Functions
List Comprehensions
Function Composition
Higher-Order Thinking
Infix Function Application
More Music
Delay and Repeat
Inversion and Retrograde
Polyrhythms
Symbolic Meter Changes
Computing Duration
Super-retrograde
takeM and dropM
Removing Zeros
Truncating Parallel Composition
Trills
Grace Notes
Percussion
A Map for Music
A Fold for Music
Crazy Recursion
Qualified Types and Type Classes
Motivation
Equality
Defining Our Own Type Classes
Haskell's Standard Type Classes
Other Derived Instances
The type of play
Reasoning With Type Classes
Interpretation and Performance
Abstract Performance
Players
Putting it all Together
Self-Similar Music
Self-Similar Melody
Self-Similar Harmony
Other Self-Similar Structures
Proof by Induction
Induction and Recursion
Examples of List Induction
Proving Function Equivalences
Useful Properties on Lists
Induction on the Music Data Type
[Advanced] Induction on Other Data Types
An Algebra of Music
Musical Equivalance
Some Simple Axioms
The Fundamental Axiom Set
An Algebraic Semantics
Other Musical Properties
L-Systems and Generative Grammars
Generative Grammars
An L-System Grammar for Music
Random Numbers ... and Markov Chains
Random Numbers
Probability Distributions
Markov Chains
From Performance to Midi
An Introduction to Midi
Converting a Performance into Midi
Putting It All Together
Basic Input/Output
IO in Haskell
do Syntax
Actions are Just Values
Reading and Writing MIDI Files
Higher-Order Types and Monads
The Functor Class
The Monad Class
The MonadPlus Class
State Monads
Type Class Type Errors
Musical User Interface
Introduction
Basic Concepts
The UISF Arrow
Non-Widget Signal Functions
Musical Examples
Special Purpose and Custom Widgets
Advanced Topics
Sound and Signals
The Nature of Sound
Digital Audio
Euterpea's Signal Functions
Signals and Signal Functions
Generating Sound
Instruments
Spectrum Analysis
Fourier's Theorem
The Discrete Fourier Transform
The Fast Fourier Transform
Further Pragmatics
References
Additive and Subtractive Synthesis
Additive Synthesis
Subtractive Synthesis
Amplitude and Frequency Modulation
Amplitude Modulation
Frequency Modulation
Physical Modelling
Introduction
Delay Lines
Karplus-Strong Algorithm
Waveguide Synthesis
Sound Effects
Appendix
The PreludeList Module
The PreludeList Module
Simple List Selector Functions
Index-Based Selector Functions
Predicate-Based Selector Functions
Fold-like Functions
List Generators
String-Based Functions
Boolean List Functions
List Membership Functions
Arithmetic on Lists
List Combining Functions
Haskell's Standard Type Classes
The Ordered Class
The Enumeration Class
The Bounded Class
The Show Class
The Read Class
The Index Class
The Numeric Classes
Built-in Types Are Not Special
Pattern-Matching Details
Bibliography
The Haskell School of Music — From Signals to Symphonies — Paul Hudak Yale University Department of Computer Science Version 2.6 (January 2014)
i The Haskell School of Music — From Signals to Symphonies — Paul Hudak Yale University Department of Computer Science New Haven, CT, USA Version 2.6 (January 2014) Copyright c Paul Hudak January 2011, 2012, 2013, 2014 All rights reserved. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a data base or retrieval system, without the prior written permission of the author. Cover image: Euterpe, the Greek Muse of Music (attribution unknown)
Contents Table of Contents List of Figures List of Tables Preface 1 Computer Music, Euterpea, and Haskell 1.1 The Note vs. Signal Dichotomy . . . . . . . . . . . . . . . . . 1.2 Basic Principles of Programming . . . . . . . . . . . . . . . . 1.3 Computation by Calculation . . . . . . . . . . . . . . . . . . . 1.4 Expressions and Values . . . . . . . . . . . . . . . . . . . . . 1.5 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.6 Function Types and Type Signatures . . . . . . . . . . . . . . 1.7 Abstraction, Abstraction, Abstraction . . . . . . . . . . . . . 1.8 Haskell Equality vs. Euterpean Equality . . . . . . . . . . . . 1.9 Code Reuse and Modularity . . . . . . . . . . . . . . . . . . . 1.10 [Advanced] Programming with Numbers . . . . . . . . . . . . 2 Simple Music 2.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Notes, Music, and Polymorphism . . . . . . . . . . . . . . . . 2.3 Convenient Auxiliary Functions . . . . . . . . . . . . . . . . . ii viii xii xiii xiv 1 2 3 4 8 10 11 13 22 23 24 28 28 30 34
CONTENTS iii 2.4 Absolute Pitches . . . . . . . . . . . . . . . . . . . . . . . . . 41 3 Polymorphic & Higher-Order Functions 3.1 Polymorphic Types . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Abstraction Over Recursive Definitions . . . . . . . . . . . . . 3.3 Append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4 Fold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5 [Advanced] A Final Example: Reverse . . . . . . . . . . . . . 3.6 Currying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.7 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 A Musical Interlude 4.1 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Transcribing an Existing Score . . . . . . . . . . . . . . . . . 4.3 Simple Algorithmic Composition . . . . . . . . . . . . . . . . 5 Syntactic Magic 5.1 Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . 5.3 List Comprehensions . . . . . . . . . . . . . . . . . . . . . . . 5.4 Function Composition . . . . . . . . . . . . . . . . . . . . . . 5.5 Higher-Order Thinking . . . . . . . . . . . . . . . . . . . . . . 5.6 Infix Function Application . . . . . . . . . . . . . . . . . . . . 6 More Music 6.1 Delay and Repeat . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Inversion and Retrograde . . . . . . . . . . . . . . . . . . . . 6.3 Polyrhythms . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.4 Symbolic Meter Changes . . . . . . . . . . . . . . . . . . . . . 6.5 Computing Duration . . . . . . . . . . . . . . . . . . . . . . . 6.6 Super-retrograde . . . . . . . . . . . . . . . . . . . . . . . . . 6.7 takeM and dropM . . . . . . . . . . . . . . . . . . . . . . . . 6.8 Removing Zeros . . . . . . . . . . . . . . . . . . . . . . . . . . 45 46 47 51 53 58 60 64 67 67 69 74 77 77 79 80 83 84 85 87 87 88 90 92 93 93 94 95
CONTENTS 6.9 Truncating Parallel Composition . . . . . . . . . . . . . . . . 6.10 Trills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv 97 99 6.11 Grace Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 6.12 Percussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 6.13 A Map for Music . . . . . . . . . . . . . . . . . . . . . . . . . 104 6.14 A Fold for Music . . . . . . . . . . . . . . . . . . . . . . . . . 107 6.15 Crazy Recursion . . . . . . . . . . . . . . . . . . . . . . . . . 108 7 Qualified Types and Type Classes 111 7.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 7.2 Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 7.3 Defining Our Own Type Classes . . . . . . . . . . . . . . . . 115 7.4 Haskell’s Standard Type Classes . . . . . . . . . . . . . . . . 121 7.5 Other Derived Instances . . . . . . . . . . . . . . . . . . . . . 126 7.6 The type of play . . . . . . . . . . . . . . . . . . . . . . . . . 130 7.7 Reasoning With Type Classes . . . . . . . . . . . . . . . . . . 130 8 Interpretation and Performance 134 8.1 Abstract Performance . . . . . . . . . . . . . . . . . . . . . . 135 8.2 Players . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 8.3 Putting it all Together . . . . . . . . . . . . . . . . . . . . . . 149 9 Self-Similar Music 153 9.1 Self-Similar Melody . . . . . . . . . . . . . . . . . . . . . . . . 153 9.2 Self-Similar Harmony . . . . . . . . . . . . . . . . . . . . . . . 157 9.3 Other Self-Similar Structures . . . . . . . . . . . . . . . . . . 158 10 Proof by Induction 161 10.1 Induction and Recursion . . . . . . . . . . . . . . . . . . . . . 161 10.2 Examples of List Induction . . . . . . . . . . . . . . . . . . . 162 10.3 Proving Function Equivalences . . . . . . . . . . . . . . . . . 164 10.4 Useful Properties on Lists . . . . . . . . . . . . . . . . . . . . 168 10.5 Induction on the Music Data Type . . . . . . . . . . . . . . . 172
CONTENTS v 10.6 [Advanced] Induction on Other Data Types . . . . . . . . . . 176 11 An Algebra of Music 182 11.1 Musical Equivalance . . . . . . . . . . . . . . . . . . . . . . . 182 11.2 Some Simple Axioms . . . . . . . . . . . . . . . . . . . . . . . 184 11.3 The Fundamental Axiom Set . . . . . . . . . . . . . . . . . . 187 11.4 An Algebraic Semantics . . . . . . . . . . . . . . . . . . . . . 189 11.5 Other Musical Properties . . . . . . . . . . . . . . . . . . . . 189 12 L-Systems and Generative Grammars 191 12.1 Generative Grammars . . . . . . . . . . . . . . . . . . . . . . 191 12.2 An L-System Grammar for Music . . . . . . . . . . . . . . . . 197 13 Random Numbers ... and Markov Chains 201 13.1 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . 201 13.2 Probability Distributions . . . . . . . . . . . . . . . . . . . . . 204 13.3 Markov Chains . . . . . . . . . . . . . . . . . . . . . . . . . . 210 14 From Performance to Midi 214 14.1 An Introduction to Midi . . . . . . . . . . . . . . . . . . . . . 215 14.2 Converting a Performance into Midi . . . . . . . . . . . . . . 220 14.3 Putting It All Together . . . . . . . . . . . . . . . . . . . . . 223 15 Basic Input/Output 224 15.1 IO in Haskell . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 15.2 do Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 15.3 Actions are Just Values . . . . . . . . . . . . . . . . . . . . . 227 15.4 Reading and Writing MIDI Files . . . . . . . . . . . . . . . . 229 16 Higher-Order Types and Monads 230 16.1 The Functor Class . . . . . . . . . . . . . . . . . . . . . . . . 230 16.2 The Monad Class . . . . . . . . . . . . . . . . . . . . . . . . . 233 16.3 The MonadPlus Class . . . . . . . . . . . . . . . . . . . . . . 240
CONTENTS vi 16.4 State Monads . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 16.5 Type Class Type Errors . . . . . . . . . . . . . . . . . . . . . 245 17 Musical User Interface Daniel Winograd-Cort 247 17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 17.2 Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . 248 17.3 The UISF Arrow . . . . . . . . . . . . . . . . . . . . . . . . . 254 17.4 Non-Widget Signal Functions . . . . . . . . . . . . . . . . . . 264 17.5 Musical Examples . . . . . . . . . . . . . . . . . . . . . . . . 269 17.6 Special Purpose and Custom Widgets . . . . . . . . . . . . . 274 17.7 Advanced Topics . . . . . . . . . . . . . . . . . . . . . . . . . 282 18 Sound and Signals 289 18.1 The Nature of Sound . . . . . . . . . . . . . . . . . . . . . . . 289 18.2 Digital Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 19 Euterpea’s Signal Functions 311 19.1 Signals and Signal Functions . . . . . . . . . . . . . . . . . . 312 19.2 Generating Sound . . . . . . . . . . . . . . . . . . . . . . . . 322 19.3 Instruments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 20 Spectrum Analysis 331 20.1 Fourier’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . 331 20.2 The Discrete Fourier Transform . . . . . . . . . . . . . . . . . 335 20.3 The Fast Fourier Transform . . . . . . . . . . . . . . . . . . . 348 20.4 Further Pragmatics . . . . . . . . . . . . . . . . . . . . . . . . 349 20.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 21 Additive and Subtractive Synthesis 351 21.1 Additive Synthesis . . . . . . . . . . . . . . . . . . . . . . . . 352 21.2 Subtractive Synthesis . . . . . . . . . . . . . . . . . . . . . . . 360
CONTENTS 22 Amplitude and Frequency Modulation vii 369 22.1 Amplitude Modulation . . . . . . . . . . . . . . . . . . . . . . 369 22.2 Frequency Modulation . . . . . . . . . . . . . . . . . . . . . . 372 23 Physical Modelling 377 23.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 23.2 Delay Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 23.3 Karplus-Strong Algorithm . . . . . . . . . . . . . . . . . . . . 381 23.4 Waveguide Synthesis . . . . . . . . . . . . . . . . . . . . . . . 382 24 Sound Effects Appendix A The PreludeList Module 386 387 388 A.1 The PreludeList Module . . . . . . . . . . . . . . . . . . . . . 389 A.2 Simple List Selector Functions . . . . . . . . . . . . . . . . . 389 A.3 Index-Based Selector Functions . . . . . . . . . . . . . . . . . 390 A.4 Predicate-Based Selector Functions . . . . . . . . . . . . . . . 392 A.5 Fold-like Functions . . . . . . . . . . . . . . . . . . . . . . . . 392 A.6 List Generators . . . . . . . . . . . . . . . . . . . . . . . . . . 394 A.7 String-Based Functions . . . . . . . . . . . . . . . . . . . . . . 394 A.8 Boolean List Functions . . . . . . . . . . . . . . . . . . . . . . 395 A.9 List Membership Functions . . . . . . . . . . . . . . . . . . . 396 A.10 Arithmetic on Lists . . . . . . . . . . . . . . . . . . . . . . . . 396 A.11 List Combining Functions . . . . . . . . . . . . . . . . . . . . 397 B Haskell’s Standard Type Classes 399 B.1 The Ordered Class . . . . . . . . . . . . . . . . . . . . . . . . 399 B.2 The Enumeration Class . . . . . . . . . . . . . . . . . . . . . 400 B.3 The Bounded Class . . . . . . . . . . . . . . . . . . . . . . . . 401 B.4 The Show Class . . . . . . . . . . . . . . . . . . . . . . . . . . 402
分享到:
收藏