| 1 | /* |
| 2 | * This source code is public domain. |
| 3 | * |
| 4 | * Authors: Kenton Varda <[email protected]> (C interface wrapper) |
| 5 | */ |
| 6 | |
| 7 | #ifndef PSMPLUG_H |
| 8 | #define PSMPLUG_H |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | struct _ModPlugFile; |
| 15 | typedef struct _ModPlugFile ModPlugFile; |
| 16 | |
| 17 | struct _ModPlugNote { |
| 18 | unsigned char Note; |
| 19 | unsigned char Instrument; |
| 20 | unsigned char VolumeEffect; |
| 21 | unsigned char Effect; |
| 22 | unsigned char Volume; |
| 23 | unsigned char Parameter; |
| 24 | }; |
| 25 | typedef struct _ModPlugNote ModPlugNote; |
| 26 | |
| 27 | typedef void (*ModPlugMixerProc)(int*, unsigned long, unsigned long); |
| 28 | |
| 29 | /* Load a mod file. [data] should point to a block of memory containing the complete |
| 30 | * file, and [size] should be the size of that block. |
| 31 | * Return the loaded mod file on success, or NULL on failure. */ |
| 32 | ModPlugFile* ModPlug_Load(const void* data, int size); |
| 33 | /* Unload a mod file. */ |
| 34 | void ModPlug_Unload(ModPlugFile* file); |
| 35 | |
| 36 | /* Read sample data into the buffer. Returns the number of bytes read. If the end |
| 37 | * of the mod has been reached, zero is returned. */ |
| 38 | int ModPlug_Read(ModPlugFile* file, void* buffer, int size); |
| 39 | |
| 40 | /* Get the name of the mod. The returned buffer is stored within the ModPlugFile |
| 41 | * structure and will remain valid until you unload the file. */ |
| 42 | const char* ModPlug_GetName(ModPlugFile* file); |
| 43 | |
| 44 | /* Get the length of the mod, in milliseconds. Note that this result is not always |
| 45 | * accurate, especially in the case of mods with loops. */ |
| 46 | int ModPlug_GetLength(ModPlugFile* file); |
| 47 | |
| 48 | /* Seek to a particular position in the song. Note that seeking and MODs don't mix very |
| 49 | * well. Some mods will be missing instruments for a short time after a seek, as ModPlug |
| 50 | * does not scan the sequence backwards to find out which instruments were supposed to be |
| 51 | * playing at that time. (Doing so would be difficult and not very reliable.) Also, |
| 52 | * note that seeking is not very exact in some mods -- especially those for which |
| 53 | * ModPlug_GetLength() does not report the full length. */ |
| 54 | void ModPlug_Seek(ModPlugFile* file, int millisecond); |
| 55 | |
| 56 | /* Get the absolute playing position in song, in milliseconds. */ |
| 57 | int ModPlug_Tell(ModPlugFile* file); |
| 58 | |
| 59 | enum _ModPlug_Flags |
| 60 | { |
| 61 | MODPLUG_ENABLE_OVERSAMPLING = 1 << 0, /* Enable oversampling (*highly* recommended) */ |
| 62 | MODPLUG_ENABLE_NOISE_REDUCTION = 1 << 1, /* Enable noise reduction */ |
| 63 | MODPLUG_ENABLE_REVERB = 1 << 2, /* Enable reverb */ |
| 64 | MODPLUG_ENABLE_MEGABASS = 1 << 3, /* Enable megabass */ |
| 65 | MODPLUG_ENABLE_SURROUND = 1 << 4 /* Enable surround sound. */ |
| 66 | }; |
| 67 | |
| 68 | enum _ModPlug_ResamplingMode |
| 69 | { |
| 70 | MODPLUG_RESAMPLE_NEAREST = 0, /* No interpolation (very fast, extremely bad sound quality) */ |
| 71 | MODPLUG_RESAMPLE_LINEAR = 1, /* Linear interpolation (fast, good quality) */ |
| 72 | MODPLUG_RESAMPLE_SPLINE = 2, /* Cubic spline interpolation (high quality) */ |
| 73 | MODPLUG_RESAMPLE_FIR = 3 /* 8-tap fir filter (extremely high quality) */ |
| 74 | }; |
| 75 | |
| 76 | typedef struct _ModPlug_Settings |
| 77 | { |
| 78 | int mFlags; /* One or more of the MODPLUG_ENABLE_* flags above, bitwise-OR'ed */ |
| 79 | |
| 80 | /* Note that ModPlug always decodes sound at 44100kHz, 32 bit, stereo and then |
| 81 | * down-mixes to the settings you choose. */ |
| 82 | int mChannels; /* Number of channels - 1 for mono or 2 for stereo */ |
| 83 | int mBits; /* Bits per sample - 8, 16, or 32 */ |
| 84 | int mFrequency; /* Sampling rate - 11025, 22050, or 44100 */ |
| 85 | int mResamplingMode; /* One of MODPLUG_RESAMPLE_*, above */ |
| 86 | |
| 87 | int mStereoSeparation; /* Stereo separation, 1 - 256 */ |
| 88 | int mMaxMixChannels; /* Maximum number of mixing channels (polyphony), 32 - 256 */ |
| 89 | |
| 90 | int mReverbDepth; /* Reverb level 0(quiet)-100(loud) */ |
| 91 | int mReverbDelay; /* Reverb delay in ms, usually 40-200ms */ |
| 92 | int mBassAmount; /* XBass level 0(quiet)-100(loud) */ |
| 93 | int mBassRange; /* XBass cutoff in Hz 10-100 */ |
| 94 | int mSurroundDepth; /* Surround level 0(quiet)-100(heavy) */ |
| 95 | int mSurroundDelay; /* Surround delay in ms, usually 5-40ms */ |
| 96 | int mLoopCount; /* Number of times to loop. Zero prevents looping. |
| 97 | * -1 loops forever. */ |
| 98 | } ModPlug_Settings; |
| 99 | |
| 100 | /* Get and set the mod decoder settings. All options, except for channels, bits-per-sample, |
| 101 | * sampling rate, and loop count, will take effect immediately. Those options which don't |
| 102 | * take effect immediately will take effect the next time you load a mod. */ |
| 103 | void ModPlug_GetSettings(ModPlug_Settings* settings); |
| 104 | void ModPlug_SetSettings(const ModPlug_Settings* settings); |
| 105 | |
| 106 | /* New ModPlug API Functions */ |
| 107 | /* NOTE: Master Volume (1-512) */ |
| 108 | unsigned int ModPlug_GetMasterVolume(ModPlugFile* file); |
| 109 | void ModPlug_SetMasterVolume(ModPlugFile* file, unsigned int cvol); |
| 110 | |
| 111 | /* PSMPlug additions */ |
| 112 | /* NOTE: Tempo Factor (1-256) */ |
| 113 | unsigned int ModPlug_GetMusicTempoFactor(ModPlugFile* file); |
| 114 | void ModPlug_SetMusicTempoFactor(ModPlugFile* file, unsigned int ctemp); |
| 115 | |
| 116 | int ModPlug_GetCurrentSpeed(ModPlugFile* file); |
| 117 | int ModPlug_GetCurrentTempo(ModPlugFile* file); |
| 118 | int ModPlug_GetCurrentOrder(ModPlugFile* file); |
| 119 | int ModPlug_GetCurrentPattern(ModPlugFile* file); |
| 120 | int ModPlug_GetCurrentRow(ModPlugFile* file); |
| 121 | int ModPlug_GetPlayingChannels(ModPlugFile* file); |
| 122 | |
| 123 | void ModPlug_SeekOrder(ModPlugFile* file,int order); |
| 124 | int ModPlug_GetModuleType(ModPlugFile* file); |
| 125 | char* ModPlug_GetMessage(ModPlugFile* file); |
| 126 | |
| 127 | unsigned int ModPlug_NumInstruments(ModPlugFile* file); |
| 128 | unsigned int ModPlug_NumSamples(ModPlugFile* file); |
| 129 | unsigned int ModPlug_NumPatterns(ModPlugFile* file); |
| 130 | unsigned int ModPlug_NumChannels(ModPlugFile* file); |
| 131 | unsigned int ModPlug_SampleName(ModPlugFile* file, unsigned int qual, char* buff); |
| 132 | unsigned int ModPlug_InstrumentName(ModPlugFile* file, unsigned int qual, char* buff); |
| 133 | |
| 134 | /* |
| 135 | * Retrieve pattern note-data |
| 136 | */ |
| 137 | ModPlugNote* ModPlug_GetPattern(ModPlugFile* file, int pattern, unsigned int* numrows); |
| 138 | |
| 139 | /* |
| 140 | * ================= |
| 141 | * Mixer callback |
| 142 | * ================= |
| 143 | * |
| 144 | * Use this callback if you want to 'modify' the mixed data of LibModPlug. |
| 145 | * |
| 146 | * void proc(int* buffer,unsigned long channels,unsigned long nsamples) ; |
| 147 | * |
| 148 | * 'buffer': A buffer of mixed samples |
| 149 | * 'channels': N. of channels in the buffer |
| 150 | * 'nsamples': N. of samples in the buffeer (without taking care of n.channels) |
| 151 | * |
| 152 | * (Samples are signed 32-bit integers) |
| 153 | */ |
| 154 | void ModPlug_InitMixerCallback(ModPlugFile* file,ModPlugMixerProc proc) ; |
| 155 | void ModPlug_UnloadMixerCallback(ModPlugFile* file) ; |
| 156 | |
| 157 | #ifdef __cplusplus |
| 158 | } /* extern "C" */ |
| 159 | #endif |
| 160 | |
| 161 | #endif |