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