ghy
Alejandro Acuña
2025-03-12 26319e4c5bfbee722c15b8e7ccca9b6127bb1cb8
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
// WaveFileSouce.h: interface for the WaveFileSouce class.
//
//////////////////////////////////////////////////////////////////////
 
#ifndef AFX_WAVEFILESOURCE_H__79D1D906_37F1_4F0C_BE82_8B23848FE677__INCLUDED_
#define AFX_WAVEFILESOURCE_H__79D1D906_37F1_4F0C_BE82_8B23848FE677__INCLUDED_
 
#include "AudioSource.h"
#include "Parameters.h"
#include "EventSource.h"
#include <mmsystem.h>
 
enum WaveFileSourceEvents
{
    FILE_STARTED = 0,
    FILE_STOPPED = 1
};
 
class WaveFileSourceListener;
 
class WaveFileSource : 
    public AudioSource,
    public EventSource
{
 
    class FireEventThreadParams
    {
    public:
        WaveFileSource *waveFileSource;
        int eventType;
        char waveFileName[1024];
    };
 
public:
    WaveFileSource();
    virtual ~WaveFileSource();
    int SourceStarted();
    int SourceStopped();
    int SourceThreadStarted(HANDLE sourceThreadHandle, DWORD sourceThreadID);
    int SourceThreadStopped(HANDLE sourceThreadHandle, DWORD sourceThreadID);
    int OpenWaveFile(const char *inputFileName);
    int GetFormat(WAVEFORMATEX *wfx);
    int SetBufferDuration(int bufferDurationMillisec);
    int AddFilePlayListener(WaveFileSourceListener *waveFileSourceListener);
    int RemoveFilePlayListener(WaveFileSourceListener *waveFileSourceListener);
    int PlayInLoop();
    int PlayOnce();
protected:
    virtual int GenerateData(AudioSample **ppAudioSample);
    virtual int SetTraceLevel();
private:
    int FireEvent(int eventType, char *waveFileName);
    int CloseMMIO();
    static DWORD WINAPI FireEventThread(LPVOID param);
private:
    char        szFileName[128];    // filename of file to open 
    HMMIO       hmmio;              // file handle for open file 
    MMCKINFO    mmckinfoParent;     // parent chunk information 
    MMCKINFO    mmckinfoSubchunk;   // subchunk information structure 
    DWORD       dwFmtSize;          // size of "FMT" chunk 
    DWORD       dwDataSize;         // size of "DATA" chunk 
    WAVEFORMATEX *pFormat;          // address of "FMT" chunk 
    HPSTR       lpData;             // address of "DATA" chunk
    int         bufferDuration;     // duration of audio to put in each buffer
    bool        bRunning;           // whether the filter is running
    LONG        dataStartPosition;  // start file position of the data part (for looping playback)
    bool        looping;            // whether the file is to be played in a loop
    CRITICAL_SECTION filterMutex;   // mutex for the filter
};
 
class WaveFileSourceListener
{
public:
    virtual void FilePlayStarted(WaveFileSource *waveFileSource, char *waveFileName);
    virtual void FilePlayStopped(WaveFileSource *waveFileSource, char *waveFileName);
};
 
#endif // !defined(AFX_WAVEFILESOUCE_H__79D1D906_37F1_4F0C_BE82_8B23848FE677__INCLUDED_)