00001
#ifndef RAGE_SOUND_H
00002
#define RAGE_SOUND_H
00003
00004
#include <deque>
00005
#include "RageThreads.h"
00006
#include "RageTimer.h"
00007
#include "RageUtil_CircularBuffer.h"
00008
#include "RageSoundPosMap.h"
00009
00010
class SoundReader;
00011
00012
00013 class RageSoundBase
00014 {
00015
public:
00016 virtual ~RageSoundBase() { }
00017
virtual void SoundIsFinishedPlaying() = 0;
00018
virtual bool GetDataToPlay( int16_t *buffer,
int size,
int &pos,
int &got_bytes ) = 0;
00019
virtual int GetPCM(
char *buffer,
int size, int64_t frameno ) = 0;
00020
virtual int GetSampleRate() const = 0;
00021 virtual
RageTimer GetStartTime()
const {
return RageZeroTimer; }
00022
virtual float GetVolume() const = 0;
00023 virtual
int GetID() const = 0;
00024 virtual CString GetLoadedFilePath() const = 0;
00025 virtual
bool IsStreamingFromDisk() const = 0;
00026 };
00027
00028
00029
00030 struct
RageSoundParams
00031 {
00032 RageSoundParams();
00033
00034
00035 float m_StartSecond;
00036 float m_LengthSeconds;
00037
00038
00039 float m_FadeLength;
00040
00041 void SetNoFade() { m_FadeLength = 0; }
00042
00043 float m_Volume;
00044
00045
00046 float m_Balance;
00047
00048
00049
00050 int speed_input_samples, speed_output_samples;
00051
void SetPlaybackRate(
float fScale );
00052
00053 bool AccurateSync;
00054
00055
00056
00057 RageTimer StartTime;
00058
00059
00060
00061
00062 enum StopMode_t {
00063 M_STOP,
00064 M_LOOP,
00065 M_CONTINUE,
00066 M_AUTO
00067 } StopMode;
00068 };
00069
00070 class RageSound:
public RageSoundBase
00071 {
00072
public:
00073
RageSound();
00074 ~
RageSound();
00075
RageSound(
const RageSound &cpy);
00076
RageSound &operator=(
const RageSound &cpy );
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
bool Load(
CString fn,
int precache = 2);
00095
00096
00097
00098
void LoadSoundReader(
SoundReader *pSound );
00099
void Unload();
00100
bool IsLoaded()
const;
00101
00102
void StartPlaying();
00103
void StopPlaying();
00104
00105 CString GetError()
const {
return error; }
00106 bool Error()
const {
return !
error.empty(); }
00107
00108
RageSound *Play(
const RageSoundParams *params=NULL );
00109
void Stop();
00110
00111
float GetLengthSeconds();
00112
float GetPositionSeconds(
bool *approximate=NULL,
RageTimer *Timestamp=NULL )
const;
00113
int GetSampleRate() const;
00114
bool IsStreamingFromDisk() const;
00115
bool SetPositionSeconds(
float fSeconds );
00116 CString GetLoadedFilePath()
const {
return m_sFilePath; }
00117 bool IsPlaying()
const {
return playing; }
00118
00119
00120
void LockSound();
00121
void UnlockSound();
00122
00123
float GetPlaybackRate() const;
00124
RageTimer GetStartTime() const;
00125
float GetVolume() const;
00126 int GetID()
const {
return ID; }
00127
void SetParams(
const RageSoundParams &p );
00128 const RageSoundParams &GetParams()
const {
return m_Param; }
00129
00130
private:
00131 mutable RageMutex m_Mutex;
00132
00133 SoundReader *Sample;
00134 CircBuf<char> databuf;
00135
int FillBuf(
int bytes);
00136
00137
00138 pos_map_queue pos_map;
00139
00140 CString m_sFilePath;
00141
00142 RageSoundParams m_Param;
00143
00144
00145
00146 int decode_position;
00147
00148
00149
00150
00151
00152
00153
00154 int stopped_position;
00155 bool playing;
00156
00157
00158 mutable int64_t max_driver_frame;
00159
00160
00161 int ID;
00162
00163 CString error;
00164
00165 int64_t GetPositionSecondsInternal(
bool *approximate=NULL )
const;
00166
bool SetPositionFrames(
int frames = -1 );
00167
int GetData(
char *buffer,
int size);
00168
void Fail(CString reason);
00169
int Bytes_Available() const;
00170
RageSoundParams::StopMode_t GetStopMode() const;
00171
00172
void SoundIsFinishedPlaying();
00173
00174 static
void RateChange(
char *buf,
int &cnt,
int speed_input_samples,
int speed_output_samples,
int channels);
00175
00176 public:
00177
00178
00179
00180
00181
00182
int GetPCM(
char *buffer,
int size, int64_t frameno );
00183
bool GetDataToPlay( int16_t *buffer,
int size,
int &pos,
int &got_bytes );
00184
void CommitPlayingPosition( int64_t frameno,
int pos,
int got_bytes );
00185 };
00186
00187 #endif
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212