Etterna 0.74.4
Loading...
Searching...
No Matches
RageSoundReader_Chain.h
1/* RageSoundReader_Chain - Chain sounds together */
2
3#ifndef RAGE_SOUND_READER_CHAIN
4#define RAGE_SOUND_READER_CHAIN
5
6#include "RageSoundReader.h"
7
8#include <map>
9
11{
12 public:
14 ~RageSoundReader_Chain() override;
15 RageSoundReader_Chain* Copy() const override;
16
17 /* Set the preferred sample rate. This will only be used if the source
18 * sounds use different sample rates. */
19 void SetPreferredSampleRate(int iSampleRate)
20 {
21 m_iPreferredSampleRate = iSampleRate;
22 }
23
24 int LoadSound(std::string sPath);
25 int LoadSound(RageSoundReader* pSound);
26
27 /* Add the given sound to play after fOffsetSecs seconds. Takes ownership
28 * of pSound. */
29 void AddSound(int iIndex, float fOffsetSecs, float fPan);
30
31 /* Finish adding sounds. */
32 void Finish();
33
34 /* Return the number of added sounds. */
35 int GetNumSounds() const { return m_aSounds.size(); }
36
37 int GetLength() const override;
38 int GetLength_Fast() const override;
39 int SetPosition(int iFrame) override;
40 int Read(float* pBuf, int iFrames) override;
41 int GetSampleRate() const override { return m_iActualSampleRate; }
42 unsigned GetNumChannels() const override { return m_iChannels; }
43 bool SetProperty(const std::string& sProperty, float fValue) override;
44 int GetNextSourceFrame() const override;
45 float GetStreamToSourceRatio() const override;
46 std::string GetError() const override { return ""; }
47
48 private:
49 int GetSampleRateInternal() const;
50
51 int m_iPreferredSampleRate;
52 int m_iActualSampleRate;
53 unsigned m_iChannels;
54
55 std::map<std::string, RageSoundReader*> m_apNamedSounds;
56 std::vector<RageSoundReader*> m_apLoadedSounds;
57
58 struct Sound
59 {
60 int iIndex; // into m_apLoadedSounds
61 int iOffsetMS;
62 float fPan;
63 RageSoundReader* pSound; // NULL if not activated
64
65 int GetOffsetFrame(int iSampleRate) const
66 {
67 return int(int64_t(iOffsetMS) * iSampleRate / 1000);
68 }
69 bool operator<(const Sound& rhs) const
70 {
71 return iOffsetMS < rhs.iOffsetMS;
72 }
73 };
74 std::vector<Sound> m_aSounds;
75
76 /* Read state: */
77 int m_iCurrentFrame;
78 unsigned m_iNextSound;
79 std::vector<Sound*> m_apActiveSounds;
80
81 void ActivateSound(Sound* s);
82 void ReleaseSound(Sound* s);
83};
84
85#endif
Definition RageSoundReader_Chain.h:11
Definition RageSoundReader.h:7