summaryrefslogtreecommitdiff
path: root/avstream/avssamp/wave.h
blob: d8546e3eabe83526831394b5858a7cf8cafb0645 (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**************************************************************************

    AVStream Filter-Centric Sample

    Copyright (c) 1999 - 2001, Microsoft Corporation

    File:

        wave.h

    Abstract:

        Wave object header.

    History:

        Created 6/28/01

**************************************************************************/

//
// The CWaveObject is a class which will parse PCM wave files, read the
// data, and expose the data in a loop.  This allows the sample to "synthesize"
// audio data by using any PCM wave file the user wishes.
//
class CWaveObject {

private:

    //
    // The wave format.
    //
    WAVEFORMATEX m_WaveFormat;

    //
    // The wave data.
    //
    PUCHAR m_WaveData;

    //
    // The size of the wave data.
    //
    ULONG m_WaveSize;

    //
    // The filename for the wave file.  This string must be constant and 
    // static over the lifetime of the wave object.
    //
    PWCHAR m_FileName;

    //
    // The time we have synthesized to.
    //
    LONGLONG m_SynthesisTime;

    //
    // The pointer into the wave data that we have synthesized to.
    //
    ULONG m_WavePointer;

    //
    // ParseBlock():
    //
    // Parse the wave file, starting at the specified location, until the
    // specified block has been found.  The pointer will be updated to
    // point to the block data and the amount of data in the block will
    // be returned in a variable. 
    //
    NTSTATUS
    ParseForBlock (
        IN HANDLE FileHandle,
        IN ULONG BlockHeader,
        IN OUT PLARGE_INTEGER BlockPointer,
        OUT PULONG BlockSize
        );

public:

    //
    // CWaveObject():
    //
    // Construct a new wave object using the specified file name.
    //
    CWaveObject (
        _In_ LPWSTR FileName
        ) :
        m_FileName (FileName)
    {
        m_WaveData = NULL;
    }

    //
    // ~CWaveObject():
    //
    // Destroy a wave object.
    //
    ~CWaveObject (
        );

    //
    // ParseAndRead():
    //
    // Parse the wave file and read it into an internally allocated buffer
    // inside the wave object.  This is preparation to synthesize looped
    // audio based on the wave.
    //
    NTSTATUS
    ParseAndRead (
        );

    //
    // WriteRange():
    //
    // Given the address of a KSDATARANGE_AUDIO, write out a range which
    // matches exactly the specifications of the wave we're using to
    // synthesize audio data.
    //
    // The GUIDs must be filled out already.  This only fills out the 
    // channel, bps, and freq fields.
    //
    void
    WriteRange (
        PKSDATARANGE_AUDIO AudioRange
        );

    //
    // SynthesizeTo():
    //
    // Given a specific stream time, synthesize from the current stream time
    // (assume 0) to the supplied stream time.
    //
    ULONG
    SynthesizeTo (
        IN LONGLONG StreamTime,
        IN PVOID Data,
        IN ULONG BufferSize
        );

    //
    // SynthesizeFixed():
    //
    // Given a specific amount of time, synthesize forward in time that
    // particular amount.  Units expressed in 100nS increments.
    //
    ULONG
    SynthesizeFixed (
        IN LONGLONG TimeDelta,
        IN PVOID Data,
        IN ULONG BufferSize
        );

    //
    // SkipFixed():
    //
    // Given a specific amount of time, skip forward in time that
    // particular amount.  Units expressed in 100nS increments.
    //
    void
    SkipFixed (
        IN LONGLONG TimeDelta
        );

    //
    // Reset():
    //
    // Reset the synthesis time and block pointers.  This will cause the
    // clock with respect to this wave object to go to zero.
    //
    void
    Reset (
        )
    {
        m_WavePointer = 0;
        m_SynthesisTime = 0;
    }

    //
    // Cleanup():
    //
    // This is a bag cleanup callback.  It merely deletes the wave object
    // instead of letting the default of ExFreePool free it.
    //
    static
    void
    Cleanup (
        IN CWaveObject *This
        )
    {
        delete This;
    }

};