1
0
Fork 0
blockofighter/src/audio.h

64 lines
1.2 KiB
C
Raw Normal View History

2014-02-16 14:32:28 +00:00
#ifndef __AUDIO_H_INCLUDED__
#define __AUDIO_H_INCLUDED__
2021-06-10 18:06:20 +00:00
#include "SDL_mixer.h"
2014-02-16 14:32:28 +00:00
class Sound;
2015-06-03 12:29:34 +00:00
typedef void (*STOPCALLBACK)(Sound *sound);
2014-02-16 14:32:28 +00:00
#define SOUNDTYPE_AUTODETECT 0
2021-06-10 18:06:20 +00:00
#define SOUNDTYPE_STREAM 1
#define SOUNDTYPE_SAMPLE 2
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
#define BGSONG DATAPATH "boom.mp3"
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
class Sound {
2014-02-16 14:32:28 +00:00
private:
2021-06-10 18:06:20 +00:00
Mix_Chunk *chunk;
Mix_Music *music;
2015-06-03 12:29:34 +00:00
int channel;
2021-06-10 18:06:20 +00:00
2015-06-03 12:29:34 +00:00
bool loops;
bool finished;
bool running;
float volume;
STOPCALLBACK stopcallback;
bool isFinished(void);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
int fadepos, fadetarget;
int fademode;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
int minduration;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
char *filename;
2014-02-16 14:32:28 +00:00
public:
2015-06-03 12:29:34 +00:00
Sound(Sound *source);
Sound(char *filename);
Sound(char *filename, int type);
Sound(char *filename, bool loops);
Sound(char *filename, int type, bool loops);
void load(char *filename, int type, bool loops);
bool play(void);
// Plays sound for at least minduration frames until sound
// can be played again. Doesn't prevent stopping of the sound
void play(int minduration);
void stop();
void setStopCallback(STOPCALLBACK callback);
void setVolume(float volume);
void fadeIn(int length);
void fadeOut(int length);
// Do not use methods below
void setFinished(void);
void update(void);
2014-02-16 14:32:28 +00:00
};
void initAudio(void);
void uninitAudio(void);
void updateAudio(void);
#endif