Add support for .IT, .MOD, .S3M and .XM via libxmp-lite

This commit is contained in:
Joel16 2019-03-31 23:01:45 -05:00
parent 3bb4827ab0
commit 912fb550ac
8 changed files with 393 additions and 2703 deletions

View File

@ -51,6 +51,7 @@ include_directories(
link_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/libs
)
add_executable(${PROJECT_NAME}
@ -80,8 +81,9 @@ target_link_libraries(${PROJECT_NAME}
png
jpeg
z
m
c
xmp-lite
m
mpg123
SceAppUtil_stub
SceAudio_stub

View File

@ -4,10 +4,13 @@ A homebrew music player for Playstation VITA that aims to support many different
# Currently supported formats: (16 bit signed samples)
- FLAC
- IT
- MOD
- MP3
- OGG
- S3M
- WAV (A-law and u-law, Microsoft ADPCM, IMA ADPCM)
- XM (Extended module)
- XM
# Features:
- Browse ux0:/ to play the above audio formats.
@ -20,6 +23,6 @@ A homebrew music player for Playstation VITA that aims to support many different
- MPG123 contributors.
- dr_libs by mackron.
- stb_vorbis by nothings and contributors.
- jar_xm by Joshua Reisenauer.
- libxmp-lite contributors.
- Preetisketch for startup.png (banner).
- Eleven Music Player contributors for design elements.

File diff suppressed because it is too large Load Diff

358
include/xmp.h Normal file
View File

@ -0,0 +1,358 @@
#ifndef XMP_H
#define XMP_H
#ifdef __cplusplus
extern "C" {
#endif
#define XMP_VERSION "4.4.1"
#define XMP_VERCODE 0x040401
#define XMP_VER_MAJOR 4
#define XMP_VER_MINOR 4
#define XMP_VER_RELEASE 1
#if defined(_WIN32) && !defined(__CYGWIN__)
# if defined(BUILDING_STATIC)
# define EXPORT
# elif defined(BUILDING_DLL)
# define EXPORT __declspec(dllexport)
# else
# define EXPORT __declspec(dllimport)
# endif
#elif __GNUC__ >= 4 || defined(__HP_cc)
# define EXPORT __attribute__((visibility ("default")))
#elif defined(__SUNPRO_C)
# define EXPORT __global
#elif defined(EMSCRIPTEN)
# define EXPORT EMSCRIPTEN_KEEPALIVE
#else
# define EXPORT
#endif
#define XMP_NAME_SIZE 64 /* Size of module name and type */
#define XMP_KEY_OFF 0x81 /* Note number for key off event */
#define XMP_KEY_CUT 0x82 /* Note number for key cut event */
#define XMP_KEY_FADE 0x83 /* Note number for fade event */
/* mixer parameter macros */
/* sample format flags */
#define XMP_FORMAT_8BIT (1 << 0) /* Mix to 8-bit instead of 16 */
#define XMP_FORMAT_UNSIGNED (1 << 1) /* Mix to unsigned samples */
#define XMP_FORMAT_MONO (1 << 2) /* Mix to mono instead of stereo */
/* player parameters */
#define XMP_PLAYER_AMP 0 /* Amplification factor */
#define XMP_PLAYER_MIX 1 /* Stereo mixing */
#define XMP_PLAYER_INTERP 2 /* Interpolation type */
#define XMP_PLAYER_DSP 3 /* DSP effect flags */
#define XMP_PLAYER_FLAGS 4 /* Player flags */
#define XMP_PLAYER_CFLAGS 5 /* Player flags for current module */
#define XMP_PLAYER_SMPCTL 6 /* Sample control flags */
#define XMP_PLAYER_VOLUME 7 /* Player module volume */
#define XMP_PLAYER_STATE 8 /* Internal player state (read only) */
#define XMP_PLAYER_SMIX_VOLUME 9 /* SMIX volume */
#define XMP_PLAYER_DEFPAN 10 /* Default pan setting */
#define XMP_PLAYER_MODE 11 /* Player personality */
#define XMP_PLAYER_MIXER_TYPE 12 /* Current mixer (read only) */
#define XMP_PLAYER_VOICES 13 /* Maximum number of mixer voices */
/* interpolation types */
#define XMP_INTERP_NEAREST 0 /* Nearest neighbor */
#define XMP_INTERP_LINEAR 1 /* Linear (default) */
#define XMP_INTERP_SPLINE 2 /* Cubic spline */
/* dsp effect types */
#define XMP_DSP_LOWPASS (1 << 0) /* Lowpass filter effect */
#define XMP_DSP_ALL (XMP_DSP_LOWPASS)
/* player state */
#define XMP_STATE_UNLOADED 0 /* Context created */
#define XMP_STATE_LOADED 1 /* Module loaded */
#define XMP_STATE_PLAYING 2 /* Module playing */
/* player flags */
#define XMP_FLAGS_VBLANK (1 << 0) /* Use vblank timing */
#define XMP_FLAGS_FX9BUG (1 << 1) /* Emulate FX9 bug */
#define XMP_FLAGS_FIXLOOP (1 << 2) /* Emulate sample loop bug */
#define XMP_FLAGS_A500 (1 << 3) /* Use Paula mixer in Amiga modules */
/* player modes */
#define XMP_MODE_AUTO 0 /* Autodetect mode (default) */
#define XMP_MODE_MOD 1 /* Play as a generic MOD player */
#define XMP_MODE_NOISETRACKER 2 /* Play using Noisetracker quirks */
#define XMP_MODE_PROTRACKER 3 /* Play using Protracker quirks */
#define XMP_MODE_S3M 4 /* Play as a generic S3M player */
#define XMP_MODE_ST3 5 /* Play using ST3 bug emulation */
#define XMP_MODE_ST3GUS 6 /* Play using ST3+GUS quirks */
#define XMP_MODE_XM 7 /* Play as a generic XM player */
#define XMP_MODE_FT2 8 /* Play using FT2 bug emulation */
#define XMP_MODE_IT 9 /* Play using IT quirks */
#define XMP_MODE_ITSMP 10 /* Play using IT sample mode quirks */
/* mixer types */
#define XMP_MIXER_STANDARD 0 /* Standard mixer */
#define XMP_MIXER_A500 1 /* Amiga 500 */
#define XMP_MIXER_A500F 2 /* Amiga 500 with led filter */
/* sample flags */
#define XMP_SMPCTL_SKIP (1 << 0) /* Don't load samples */
/* limits */
#define XMP_MAX_KEYS 121 /* Number of valid keys */
#define XMP_MAX_ENV_POINTS 32 /* Max number of envelope points */
#define XMP_MAX_MOD_LENGTH 256 /* Max number of patterns in module */
#define XMP_MAX_CHANNELS 64 /* Max number of channels in module */
#define XMP_MAX_SRATE 49170 /* max sampling rate (Hz) */
#define XMP_MIN_SRATE 4000 /* min sampling rate (Hz) */
#define XMP_MIN_BPM 20 /* min BPM */
/* frame rate = (50 * bpm / 125) Hz */
/* frame size = (sampling rate * channels * size) / frame rate */
#define XMP_MAX_FRAMESIZE (5 * XMP_MAX_SRATE * 2 / XMP_MIN_BPM)
/* error codes */
#define XMP_END 1
#define XMP_ERROR_INTERNAL 2 /* Internal error */
#define XMP_ERROR_FORMAT 3 /* Unsupported module format */
#define XMP_ERROR_LOAD 4 /* Error loading file */
#define XMP_ERROR_DEPACK 5 /* Error depacking file */
#define XMP_ERROR_SYSTEM 6 /* System error */
#define XMP_ERROR_INVALID 7 /* Invalid parameter */
#define XMP_ERROR_STATE 8 /* Invalid player state */
struct xmp_channel {
int pan; /* Channel pan (0x80 is center) */
int vol; /* Channel volume */
#define XMP_CHANNEL_SYNTH (1 << 0) /* Channel is synthesized */
#define XMP_CHANNEL_MUTE (1 << 1) /* Channel is muted */
#define XMP_CHANNEL_SPLIT (1 << 2) /* Split Amiga channel in bits 5-4 */
#define XMP_CHANNEL_SURROUND (1 << 4) /* Surround channel */
int flg; /* Channel flags */
};
struct xmp_pattern {
int rows; /* Number of rows */
int index[1]; /* Track index */
};
struct xmp_event {
unsigned char note; /* Note number (0 means no note) */
unsigned char ins; /* Patch number */
unsigned char vol; /* Volume (0 to basevol) */
unsigned char fxt; /* Effect type */
unsigned char fxp; /* Effect parameter */
unsigned char f2t; /* Secondary effect type */
unsigned char f2p; /* Secondary effect parameter */
unsigned char _flag; /* Internal (reserved) flags */
};
struct xmp_track {
int rows; /* Number of rows */
struct xmp_event event[1]; /* Event data */
};
struct xmp_envelope {
#define XMP_ENVELOPE_ON (1 << 0) /* Envelope is enabled */
#define XMP_ENVELOPE_SUS (1 << 1) /* Envelope has sustain point */
#define XMP_ENVELOPE_LOOP (1 << 2) /* Envelope has loop */
#define XMP_ENVELOPE_FLT (1 << 3) /* Envelope is used for filter */
#define XMP_ENVELOPE_SLOOP (1 << 4) /* Envelope has sustain loop */
#define XMP_ENVELOPE_CARRY (1 << 5) /* Don't reset envelope position */
int flg; /* Flags */
int npt; /* Number of envelope points */
int scl; /* Envelope scaling */
int sus; /* Sustain start point */
int sue; /* Sustain end point */
int lps; /* Loop start point */
int lpe; /* Loop end point */
short data[XMP_MAX_ENV_POINTS * 2];
};
struct xmp_instrument {
char name[32]; /* Instrument name */
int vol; /* Instrument volume */
int nsm; /* Number of samples */
int rls; /* Release (fadeout) */
struct xmp_envelope aei; /* Amplitude envelope info */
struct xmp_envelope pei; /* Pan envelope info */
struct xmp_envelope fei; /* Frequency envelope info */
struct {
unsigned char ins; /* Instrument number for each key */
signed char xpo; /* Instrument transpose for each key */
} map[XMP_MAX_KEYS];
struct xmp_subinstrument {
int vol; /* Default volume */
int gvl; /* Global volume */
int pan; /* Pan */
int xpo; /* Transpose */
int fin; /* Finetune */
int vwf; /* Vibrato waveform */
int vde; /* Vibrato depth */
int vra; /* Vibrato rate */
int vsw; /* Vibrato sweep */
int rvv; /* Random volume/pan variation (IT) */
int sid; /* Sample number */
#define XMP_INST_NNA_CUT 0x00
#define XMP_INST_NNA_CONT 0x01
#define XMP_INST_NNA_OFF 0x02
#define XMP_INST_NNA_FADE 0x03
int nna; /* New note action */
#define XMP_INST_DCT_OFF 0x00
#define XMP_INST_DCT_NOTE 0x01
#define XMP_INST_DCT_SMP 0x02
#define XMP_INST_DCT_INST 0x03
int dct; /* Duplicate check type */
#define XMP_INST_DCA_CUT XMP_INST_NNA_CUT
#define XMP_INST_DCA_OFF XMP_INST_NNA_OFF
#define XMP_INST_DCA_FADE XMP_INST_NNA_FADE
int dca; /* Duplicate check action */
int ifc; /* Initial filter cutoff */
int ifr; /* Initial filter resonance */
} *sub;
void *extra; /* Extra fields */
};
struct xmp_sample {
char name[32]; /* Sample name */
int len; /* Sample length */
int lps; /* Loop start */
int lpe; /* Loop end */
#define XMP_SAMPLE_16BIT (1 << 0) /* 16bit sample */
#define XMP_SAMPLE_LOOP (1 << 1) /* Sample is looped */
#define XMP_SAMPLE_LOOP_BIDIR (1 << 2) /* Bidirectional sample loop */
#define XMP_SAMPLE_LOOP_REVERSE (1 << 3) /* Backwards sample loop */
#define XMP_SAMPLE_LOOP_FULL (1 << 4) /* Play full sample before looping */
#define XMP_SAMPLE_SLOOP (1 << 5) /* Sample has sustain loop */
#define XMP_SAMPLE_SLOOP_BIDIR (1 << 6) /* Bidirectional sustain loop */
#define XMP_SAMPLE_SYNTH (1 << 15) /* Data contains synth patch */
int flg; /* Flags */
unsigned char *data; /* Sample data */
};
struct xmp_sequence {
int entry_point;
int duration;
};
struct xmp_module {
char name[XMP_NAME_SIZE]; /* Module title */
char type[XMP_NAME_SIZE]; /* Module format */
int pat; /* Number of patterns */
int trk; /* Number of tracks */
int chn; /* Tracks per pattern */
int ins; /* Number of instruments */
int smp; /* Number of samples */
int spd; /* Initial speed */
int bpm; /* Initial BPM */
int len; /* Module length in patterns */
int rst; /* Restart position */
int gvl; /* Global volume */
struct xmp_pattern **xxp; /* Patterns */
struct xmp_track **xxt; /* Tracks */
struct xmp_instrument *xxi; /* Instruments */
struct xmp_sample *xxs; /* Samples */
struct xmp_channel xxc[XMP_MAX_CHANNELS]; /* Channel info */
unsigned char xxo[XMP_MAX_MOD_LENGTH]; /* Orders */
};
struct xmp_test_info {
char name[XMP_NAME_SIZE]; /* Module title */
char type[XMP_NAME_SIZE]; /* Module format */
};
struct xmp_module_info {
unsigned char md5[16]; /* MD5 message digest */
int vol_base; /* Volume scale */
struct xmp_module *mod; /* Pointer to module data */
char *comment; /* Comment text, if any */
int num_sequences; /* Number of valid sequences */
struct xmp_sequence *seq_data; /* Pointer to sequence data */
};
struct xmp_frame_info { /* Current frame information */
int pos; /* Current position */
int pattern; /* Current pattern */
int row; /* Current row in pattern */
int num_rows; /* Number of rows in current pattern */
int frame; /* Current frame */
int speed; /* Current replay speed */
int bpm; /* Current bpm */
int time; /* Current module time in ms */
int total_time; /* Estimated replay time in ms*/
int frame_time; /* Frame replay time in us */
void *buffer; /* Pointer to sound buffer */
int buffer_size; /* Used buffer size */
int total_size; /* Total buffer size */
int volume; /* Current master volume */
int loop_count; /* Loop counter */
int virt_channels; /* Number of virtual channels */
int virt_used; /* Used virtual channels */
int sequence; /* Current sequence */
struct xmp_channel_info { /* Current channel information */
unsigned int period; /* Sample period (* 4096) */
unsigned int position; /* Sample position */
short pitchbend; /* Linear bend from base note*/
unsigned char note; /* Current base note number */
unsigned char instrument; /* Current instrument number */
unsigned char sample; /* Current sample number */
unsigned char volume; /* Current volume */
unsigned char pan; /* Current stereo pan */
unsigned char reserved; /* Reserved */
struct xmp_event event; /* Current track event */
} channel_info[XMP_MAX_CHANNELS];
};
typedef char *xmp_context;
EXPORT extern const char *xmp_version;
EXPORT extern const unsigned int xmp_vercode;
EXPORT xmp_context xmp_create_context (void);
EXPORT void xmp_free_context (xmp_context);
EXPORT int xmp_test_module (char *, struct xmp_test_info *);
EXPORT int xmp_load_module (xmp_context, char *);
EXPORT void xmp_scan_module (xmp_context);
EXPORT void xmp_release_module (xmp_context);
EXPORT int xmp_start_player (xmp_context, int, int);
EXPORT int xmp_play_frame (xmp_context);
EXPORT int xmp_play_buffer (xmp_context, void *, int, int);
EXPORT void xmp_get_frame_info (xmp_context, struct xmp_frame_info *);
EXPORT void xmp_end_player (xmp_context);
EXPORT void xmp_inject_event (xmp_context, int, struct xmp_event *);
EXPORT void xmp_get_module_info (xmp_context, struct xmp_module_info *);
EXPORT char **xmp_get_format_list (void);
EXPORT int xmp_next_position (xmp_context);
EXPORT int xmp_prev_position (xmp_context);
EXPORT int xmp_set_position (xmp_context, int);
EXPORT void xmp_stop_module (xmp_context);
EXPORT void xmp_restart_module (xmp_context);
EXPORT int xmp_seek_time (xmp_context, int);
EXPORT int xmp_channel_mute (xmp_context, int, int);
EXPORT int xmp_channel_vol (xmp_context, int, int);
EXPORT int xmp_set_player (xmp_context, int, int);
EXPORT int xmp_get_player (xmp_context, int);
EXPORT int xmp_set_instrument_path (xmp_context, char *);
EXPORT int xmp_load_module_from_memory (xmp_context, void *, long);
EXPORT int xmp_load_module_from_file (xmp_context, void *, long);
/* External sample mixer API */
EXPORT int xmp_start_smix (xmp_context, int, int);
EXPORT void xmp_end_smix (xmp_context);
EXPORT int xmp_smix_play_instrument(xmp_context, int, int, int, int);
EXPORT int xmp_smix_play_sample (xmp_context, int, int, int, int);
EXPORT int xmp_smix_channel_pan (xmp_context, int, int);
EXPORT int xmp_smix_load_sample (xmp_context, int, char *);
EXPORT int xmp_smix_release_sample (xmp_context, int);
#ifdef __cplusplus
}
#endif
#endif /* XMP_H */

View File

@ -138,7 +138,8 @@ int Audio_Init(const char *path) {
file_type = FILE_TYPE_OGG;
else if (!strncasecmp(FS_GetFileExt(path), "wav", 3))
file_type = FILE_TYPE_WAV;
else if (!strncasecmp(FS_GetFileExt(path), "xm", 2))
else if ((!strncasecmp(FS_GetFileExt(path), "it", 2)) || (!strncasecmp(FS_GetFileExt(path), "mod", 3)) || (!strncasecmp(FS_GetFileExt(path), "s3m", 3))
|| (!strncasecmp(FS_GetFileExt(path), "xm", 2)))
file_type = FILE_TYPE_XM;
switch(file_type) {

View File

@ -1,33 +1,23 @@
#include "audio.h"
#include "common.h"
#include "fs.h"
#define JAR_XM_IMPLEMENTATION
#include "jar_xm.h"
#include "xmp.h"
static jar_xm_context_t *xm;
static xmp_context xmp;
static struct xmp_frame_info frame_info;
static SceUInt64 samples_read = 0, total_samples = 0;
static char *data = NULL;
int XM_Init(const char *path) {
int ret = 0;
char *xm_data = NULL;
SceUInt64 xm_size_bytes = 0;
if (R_FAILED(ret = FS_GetFileSize(path, (SceOff *)&xm_size_bytes)))
return ret;
xm_data = malloc(xm_size_bytes);
if (R_FAILED(ret = FS_ReadFile(path, xm_data, xm_size_bytes)))
return ret;
jar_xm_create_context_safe(&xm, xm_data, (size_t)xm_size_bytes, (SceUInt32)48000);
total_samples = jar_xm_get_remaining_samples(xm);
xmp = xmp_create_context();
if (xmp_load_module(xmp, (char *)path) < 0)
return -1;
xmp_start_player(xmp, 44100, 0);
xmp_get_frame_info(xmp, &frame_info);
total_samples = (frame_info.total_time * 44.1);
return 0;
}
SceUInt32 XM_GetSampleRate(void) {
return 48000;
return 44100;
}
SceUInt8 XM_GetChannels(void) {
@ -35,8 +25,8 @@ SceUInt8 XM_GetChannels(void) {
}
void XM_Decode(void *buf, unsigned int length, void *userdata) {
jar_xm_generate_samples_16bit(xm, (short *)buf, (size_t)length);
jar_xm_get_position(xm, NULL, NULL, NULL, &samples_read);
xmp_play_buffer(xmp, buf, length * (sizeof(SceInt16) * 2), 0);
samples_read += length;
if (samples_read == total_samples)
playing = SCE_FALSE;
@ -47,11 +37,12 @@ SceUInt64 XM_GetPosition(void) {
}
SceUInt64 XM_GetLength(void) {
return total_samples;
return total_samples;
}
void XM_Term(void) {
samples_read = 0;
jar_xm_free_context(xm);
free(data);
samples_read = 0;
xmp_end_player(xmp);
xmp_release_module(xmp);
xmp_free_context(xmp);
}

View File

@ -116,8 +116,8 @@ void Dirbrowse_DisplayFiles(void) {
if (file->is_dir)
vita2d_draw_texture(icon_dir, 15, 117 + (72 * printed));
else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "mp3", 3)) || (!strncasecmp(file->ext, "ogg", 3))
|| (!strncasecmp(file->ext, "wav", 3)) || (!strncasecmp(file->ext, "xm", 2)))
else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "it", 2)) || (!strncasecmp(file->ext, "mod", 3)) || (!strncasecmp(file->ext, "mp3", 3))
|| (!strncasecmp(file->ext, "ogg", 3)) || (!strncasecmp(file->ext, "s3m", 3))|| (!strncasecmp(file->ext, "wav", 3)) || (!strncasecmp(file->ext, "xm", 2)))
vita2d_draw_texture(icon_audio, 15, 117 + (72 * printed));
else
vita2d_draw_texture(icon_file, 15, 117 + (72 * printed));
@ -161,8 +161,8 @@ void Dirbrowse_OpenFile(void) {
Dirbrowse_PopulateFiles(SCE_TRUE);
}
}
else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "mp3", 3)) || (!strncasecmp(file->ext, "ogg", 3))
|| (!strncasecmp(file->ext, "wav", 3)) || (!strncasecmp(file->ext, "xm", 2)))
else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "it", 2)) || (!strncasecmp(file->ext, "mod", 3)) || (!strncasecmp(file->ext, "mp3", 3))
|| (!strncasecmp(file->ext, "ogg", 3)) || (!strncasecmp(file->ext, "s3m", 3))|| (!strncasecmp(file->ext, "wav", 3)) || (!strncasecmp(file->ext, "xm", 2)))
Menu_PlayAudio(path);
}

View File

@ -40,8 +40,10 @@ static int Menu_GetMusicList(void) {
qsort(entries, entryCount, sizeof(SceIoDirent), Utils_Alphasort);
for (i = 0; i < entryCount; i++) {
if ((!strncasecmp(FS_GetFileExt(entries[i].d_name), "flac", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mp3", 3)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "ogg", 3))
|| (!strncasecmp(FS_GetFileExt(entries[i].d_name), "wav", 3)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "xm", 2))) {
if ((!strncasecmp(FS_GetFileExt(entries[i].d_name), "flac", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "it", 2)) ||
(!strncasecmp(FS_GetFileExt(entries[i].d_name), "mod", 3)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mp3", 3)) ||
(!strncasecmp(FS_GetFileExt(entries[i].d_name), "ogg", 3)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "s3m", 3)) ||
(!strncasecmp(FS_GetFileExt(entries[i].d_name), "wav", 3)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "xm", 2))) {
strcpy(playlist[count], cwd);
strcpy(playlist[count] + strlen(playlist[count]), entries[i].d_name);
count++;