Nsound  0.9.4
Functions | Variables
example3.cc File Reference
#include <Nsound/NsoundAll.h>
#include <iostream>
Include dependency graph for example3.cc:

Go to the source code of this file.

Functions

Buffer drum (float32 duration, float32 attack_time, float32 high_frequency, float32 low_frequency, float32 tension, float32 resident_frequency)
 
int my_main (void)
 
int main (void)
 

Variables

float64 sr = 44100.0
 
uint64 SAMPLE_RATE = static_cast<uint64>(sr)
 
uint64 BITS_PER_SAMPLE = 16
 

Function Documentation

Buffer drum ( float32  duration,
float32  attack_time,
float32  high_frequency,
float32  low_frequency,
float32  tension,
float32  resident_frequency 
)

Definition at line 30 of file example3.cc.

References Nsound::Generator::drawLine(), Nsound::Generator::drawParabola(), Nsound::Generator::generate(), and sr.

Referenced by my_main().

37 {
38  Sine sin(sr);
39 
40  Buffer frequency_sweep;
41  frequency_sweep
42  << sin.drawLine(attack_time, high_frequency, low_frequency)
43  << sin.drawLine((duration - attack_time), low_frequency, low_frequency);
44 
45  Buffer hz_20 = sin.generate(duration, resident_frequency);
46 
47  Buffer rezzy = hz_20 * frequency_sweep;
48 
49  Buffer parabola = sin.drawParabola(duration, 1.0, duration / 2, 0.25, 0.0);
50 
51  rezzy *= parabola;
52 
53  Buffer temp1 = rezzy * tension;
54 
55  frequency_sweep -= temp1;
56 
57  Buffer audio = sin.generate(duration, frequency_sweep);
58 
59  audio *= sin.drawParabola(duration, 1.0, 0.5 * duration, 0.3, 0.0);
60 
61  return audio;
62 }
A Buffer for storing audio samples.
Definition: Buffer.h:60
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24
int my_main ( void  )

Definition at line 65 of file example3.cc.

References drum(), Nsound::ReverberationRoom::filter(), Nsound::DrumBD01::play(), Nsound::DrumKickBass::play(), Nsound::Hat::play(), Nsound::Generator::silence(), and sr.

Referenced by main().

66 {
67  Sine sine(sr);
68 
69  DrumBD01 db01(sr);
70  DrumKickBass dkb(sr, 266, 0.0);
71 
72  AudioStream out(sr, 1);
73 
74  out << db01.play()
75  << sine.silence(0.25)
76  << dkb.play()
77  << sine.silence(0.25)
78 
79  // duration, attack, high f, low f, tension, ressonance
80  << drum(0.5f, 0.012f, 160, 51, 0.9f, 54)
81  << drum(0.5f, 0.012f, 160, 51, 0.9f, 54)
82  << drum(0.5f, 0.012f, 160, 51, 0.9f, 54)
83  << drum(0.5f, 0.012f, 160, 51, 0.9f, 54)
84  << sine.silence(0.25);
85 
86  out *= 0.5;
87 
88  Hat hat(sr);
89 
90  out << 0.666 * hat.play() << sine.silence(0.25);
91 
92  out >> "example3.wav";
93 
94  // ReverberationRoom(sample_rate, room_feedback, wet_percent, dry_percent, low_pass_freq)
95  ReverberationRoom room(sr, 0.60, 0.5, 1.0, 100.0);
96 
97  AudioStream out2 = 0.5 * room.filter(out);
98 
99  out2 >> "example3_reverb.wav";
100 
101  // Try to play the audio
102 
103  try
104  {
105  AudioPlayback pb(sr, 2, 16);
106  out2 >> pb;
107  }
108  catch(std::exception & e)
109  {
110  cerr << "Warning: Could not play audio: " << e.what() << endl;
111  }
112 
113  return 0;
114 }
Buffer drum(float32 duration, float32 attack_time, float32 high_frequency, float32 low_frequency, float32 tension, float32 resident_frequency)
Definition: example3.cc:30
Class DrumBD01.
Definition: DrumBD01.h:50
Class Hat.
Definition: Hat.h:61
DOXME.
Definition: Sine.h:43
float64 sr
Definition: example3.cc:24
int main ( void  )

Definition at line 117 of file example3.cc.

References my_main().

118 {
119  try
120  {
121  my_main();
122  }
123  catch(std::exception & e)
124  {
125  cerr << "Exception: " << e.what() << endl;
126  return 1;
127  }
128 
129  return 0;
130 }
int my_main(void)
Definition: example3.cc:65

Variable Documentation

float64 sr = 44100.0
uint64 SAMPLE_RATE = static_cast<uint64>(sr)

Definition at line 25 of file example3.cc.

Referenced by main().

uint64 BITS_PER_SAMPLE = 16

Definition at line 26 of file example3.cc.