use libxmp instead

This commit is contained in:
Nishi 2026-05-27 23:51:37 +09:00
commit 6f8ee4c7ae
26 changed files with 333 additions and 4039 deletions

View file

@ -0,0 +1,27 @@
#ifndef __FISHBONE_FILE_H__
#define __FISHBONE_FILE_H__
namespace fishbone {
class File;
};
#include <fishbone/machdep.h>
namespace fishbone {
class File {
std::ifstream ifs;
std::ofstream ofs;
public:
File(std::string path, std::string type);
~File();
size_t read(void* buffer, size_t size);
size_t write(const void* buffer, size_t size);
size_t size;
bool good;
};
}; // namespace fishbone
#endif

View file

@ -5,5 +5,6 @@
#include <fishbone/sound.h>
#include <fishbone/mixer.h>
#include <fishbone/thread.h>
#include <fishbone/file.h>
#endif

View file

@ -2,6 +2,10 @@
#define __FISHBONE_MACHDEP_H__
#include <vector>
#include <string>
#include <fstream>
#include <cstdio>
#include <fishbone/config.h>
@ -11,8 +15,7 @@
#endif
#define STB_VORBIS_HEADER_ONLY
#include <jar_xm.h>
#include <jar_mod.h>
#include <xmp.h>
#include <dr_mp3.h>
#include <dr_wav.h>
#include <dr_flac.h>

View file

@ -19,6 +19,8 @@ namespace fishbone {
void read(short* buffer, size_t frames);
fishbone::Sound* open(const char* path);
void lock();
void unlock();
static const int rate = 44100;
std::vector<fishbone::SoundLoader*> loaders;

View file

@ -1,10 +1,35 @@
#ifndef __FISHBONE_SOUND_H__
#define __FISHBONE_SOUND_H__
#define FB_SOUND_DECL(prefix) \
class prefix##SoundLoader; \
class prefix##Sound
#define FB_SOUND_DEF(prefix) \
class prefix##SoundLoader : public SoundLoader { \
public: \
Sound* open(Mixer* mixer, void* buffer, size_t size); \
int read(Sound* sound, short* buffer, size_t frames); \
void seek(Sound* sound, size_t pos); \
}; \
\
class prefix##Sound : public Sound { \
public: \
prefix##Sound(Mixer* mixer, prefix##SoundLoader* loader, struct Sound::Impl* impl) \
: Sound(mixer, loader, impl){}; \
~prefix##Sound(); \
}
#define FB_SOUND_LOADERS LOADER(XMP)
namespace fishbone {
class SoundDriver;
class SoundLoader;
class Sound;
#define LOADER(X) FB_SOUND_DECL(X);
FB_SOUND_LOADERS
#undef LOADER
}; // namespace fishbone
#include <fishbone/machdep.h>
@ -27,21 +52,43 @@ namespace fishbone {
SoundLoader();
~SoundLoader();
virtual Sound* open(void* buffer, size_t size);
virtual Sound* open(Mixer* mixer, void* buffer, size_t size);
virtual int read(Sound* sound, short* buffer, size_t frames);
virtual void seek(Sound* sound, size_t pos);
};
class Sound {
public:
struct Impl;
Impl* impl;
private:
SoundLoader* loader;
Mixer* mixer;
protected:
bool loop;
bool paused;
public:
Sound(SoundLoader* loader);
Sound(Mixer* mixer, SoundLoader* loader, struct Impl* impl);
int read(short* buffer, size_t frames);
int read(short* buffer, size_t frames);
void seek(size_t pos);
void resume();
void pause();
void pauseNoLock(); /* do NOT use this! */
bool isPaused();
void setLoop(bool v);
bool isLoop();
int rate;
int channels;
};
#define LOADER(X) FB_SOUND_DEF(X);
FB_SOUND_LOADERS
#undef LOADER
}; // namespace fishbone
#endif