File: SoundParameterSpaceControlPoint.h

package info (click to toggle)
transcend 0.3.dfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,832 kB
  • ctags: 2,912
  • sloc: cpp: 26,890; ansic: 693; sh: 210; makefile: 131; perl: 67
file content (167 lines) | stat: -rw-r--r-- 4,974 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Modification History
 *
 * 2004-August-6   Jason Rohrer
 * Created.
 *
 * 2004-August-9   Jason Rohrer
 * Changed to use sine components.
 *
 * 2004-August-12   Jason Rohrer
 * Added support for getting blocks of samples.
 *
 * 2004-August-19   Jason Rohrer
 * Fixed bug in walking through wavetable.
 */



#ifndef SOUND_PARAMETER_SPACE_CONTROL_POINT_INCLUDED
#define SOUND_PARAMETER_SPACE_CONTROL_POINT_INCLUDED


#include "ParameterSpaceControlPoint.h"


#include <stdio.h>



/**
 * A control point in a 1-D parameterized sound space.
 *
 * @author Jason Rohrer.
 */
class SoundParameterSpaceControlPoint : public ParameterSpaceControlPoint {


    public:


        
        /**
         * Constructs a control point.
         *
         * Note that the waveform is limited to the amplitude range [-1,1]
         * and will clip if the sine components sum to produce amplitudes
         * ouside of this range.
         *
         * Start/end freqency and loudness are used to create a linear
         * sweep of these values as the sound plays.
         *
         * @param inNumWaveComponents the number of wave components.
         * @param inWaveComponentFreqencies the frequency of each sine
         *   component.  The frequency is in cycles per waveform (in other
         *   words, how many times this sine component cycles during
         *   the length of the waveform).
         *   This array will be destroyed when this class is destroyed.
         * @param inWaveComponentAmplitudes the peak amplitude for
         *   each sine component.
         *   Each value must be in the range [0,1].
         *   This array will be destroyed when this class is destroyed.
         * @param inStartFrequency the number of times the waveform should
         *   play per second at the start of the sound.
         * @param inEndFrequency the number of times the waveform should
         *   play per second at by the end of the sound.
         * @param inStartLoudness the loudness of the start of the sound
         *   in the range [0,1].
         * @param inEndLoudness the loudness of the end of the sound
         *   in the range [0,1].
         */
        SoundParameterSpaceControlPoint(
            int inNumWaveComponents,
            double *inWaveComponentFreqencies,
            double *inWaveComponentAmplitudes,
            double inStartFrequency,
            double inEndFrequency,
            double inStartLoudness,
            double inEndLoudness );
        
        

        /**
         * Constructs a control point by reading values from a text file
         * stream.
         *
         * @param inFILE the open file to read from.
         *   Must be closed by caller.
         * @param outError pointer to where error flag should be returned.
         *   Destination will be set to true if reading a control point
         *   from inFILE fails.
         */
        SoundParameterSpaceControlPoint( FILE *inFILE, char *outError );
        

        
        virtual ~SoundParameterSpaceControlPoint();


        
        // implements the ParameterSpaceControlPoint interface
        ParameterSpaceControlPoint *copy();

        ParameterSpaceControlPoint *createLinearBlend(
            ParameterSpaceControlPoint *inOtherPoint,
            double inWeightOfOtherPoint );



        /**
         * Gets a block of samples from this control point.
         *
         * @param inStartSample the index of the first sample to get.
         * @param inSampleCount the number of samples to get.
         * @param inSamplesPerSecond the current sample rate.
         * @param inSoundLengthInSeconds the total length of the sound being
         *   played.
         *
         * @return the samples.
         *   Must be destroyed by caller.
         */
        float *getSoundSamples( unsigned long inStartSample,
                                unsigned long inSampleCount,
                                unsigned long inSamplesPerSecond,
                                double inSoundLengthInSeconds );
        
        
        
        // these are public so that other Sound points can access
        // them when performing a blend.
        int mNumWaveComponents;
        double *mWaveComponentFrequencies;
        double *mWaveComponentAmplitudes;
        double mStartFrequency;
        double mEndFrequency;
        double mStartLoudness;
        double mEndLoudness; 


        
    protected:

        

        /**
         * Copies an array of doubles, producing a newly constructed array.
         *
         * @param inArray the array to copy.
         *   Must be destroyed by caller.
         * @param inLength the length of inArray.
         *
         * @return the copied array.
         *   Must be destroyed by caller.
         */
        double *copyDoubleArray( double *inArray, int inLength );



        // used when generating sound samples
        double mCurrentWavePoint;
        

    };



#endif