File: ParameterizedStereoSound.cpp

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 (123 lines) | stat: -rw-r--r-- 3,230 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
/*
 * Modification History
 *
 * 2004-August-9   Jason Rohrer
 * Created.
 */



#include "ParameterizedStereoSound.h"
#include "StereoSoundParameterSpaceControlPoint.h"
#include "SoundParameterSpaceControlPoint.h"
#include "OnePointPlayableSound.h"



ParameterizedStereoSound::ParameterizedStereoSound( FILE *inFILE,
                                                    char *outError ) {

    char readError = false;

    // read the sound length
    int numRead = fscanf( inFILE, "%lf", &mSoundLengthInSeconds );

    if( numRead != 1 ) {
        readError = true;
        
        printf( "Error:  failed to read sound length from sound space.\n" );
        }
    
    SimpleVector<ParameterSpaceControlPoint *> *controlPoints =
        new SimpleVector<ParameterSpaceControlPoint*>();
    SimpleVector<double> *controlPointParameterAnchors =
        new SimpleVector<double>();

    // keep reading parameter anchors and control points until we
    // can read no more
    
    while( !readError ) {
        
        // read the parameter space anchor
        double anchor = 0;
        numRead = fscanf( inFILE, "%lf", &anchor );

        if( numRead != 1 ) {
            readError = true;
            }
        else {

            // read the control point
            StereoSoundParameterSpaceControlPoint *point =
                new StereoSoundParameterSpaceControlPoint( inFILE,
                                                      &readError );

            if( !readError ) {
                controlPointParameterAnchors->push_back( anchor );
                controlPoints->push_back( point );
                }
            else {
                delete point;
                }
            }
        }

    mNumControlPoints = controlPoints->size();
    mControlPoints = controlPoints->getElementArray();
    mControlPointParameterAnchors =
        controlPointParameterAnchors->getElementArray();

    delete controlPoints;
    delete controlPointParameterAnchors;

    if( mNumControlPoints >= 2 ) {
        *outError = false;
        }
    else {
        // we didn't read enough control points
        *outError = true;
        }
    }



PlayableSound *ParameterizedStereoSound::getPlayableSound(
    double inParameter,
    unsigned long inSamplesPerSecond ) {

    // blend the two points, using the distance to weight them
    StereoSoundParameterSpaceControlPoint *blendedPoint =
        getBlendedControlPoint( inParameter );
    
    if( blendedPoint != NULL ) {

        return new OnePointPlayableSound( blendedPoint,
                                          mSoundLengthInSeconds,
                                          inSamplesPerSecond );
        }
    else {
        printf( "Error:  no control points in sound space.\n" );

        return NULL;
        }

    }



StereoSoundParameterSpaceControlPoint *ParameterizedStereoSound::
    getBlendedControlPoint(
        double inParameter ) {
    
    // cast result of super-class function call and return it
    return (StereoSoundParameterSpaceControlPoint*)
        ParameterizedSpace::getBlendedControlPoint( inParameter );
    
    }



double ParameterizedStereoSound::getSoundLengthInSeconds() {
    return mSoundLengthInSeconds;
    }