Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jan 5, 2024
1 parent 14adab3 commit 31bb429
Show file tree
Hide file tree
Showing 37 changed files with 12,832 additions and 2 deletions.
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
##########################################
# m4p
##########################################

add_library(
m4p
it2drivers/sb16_m.c
it2drivers/sb16.c
it2drivers/zerovol.c
loaders/mmcmp/mmcmp.c
loaders/it.c
loaders/s3m.c
m4p.c
ft_tables.c
it_d_rm.c
it_m_eff.c
it_music.c
it_tables.c
pmp_main.c
pmp_mix.c
pmplay.c
snd_masm.c
)
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BSD 3-Clause License

Copyright (c) 2024, dashodanger
Copyright (c) 2023-2024, dashodanger
Copyright (c) 2020-2021, Olav Sørensen

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# mod4play
Lightweight embeddable replayer for IT/S3M/XM/MOD modules
This is a unified interface for the ft2play (https://github.com/8bitbubsy/ft2play) and it2play (https://github.com/8bitbubsy/it2play) libraries by Olav Sørensen for embedding in game engines or other applications. SDL and winmm dependencies have been removed; the library is intended to receive an in-memory IT, S3M, MOD, or XM format module and produce samples on demand. All mixing drivers other than SB16 have been removed for simplicity.

# Compilation
A simple example CMakeLists file has been included showing which files need to be compiled. Include `m4p.h` in the source file that you are using to handle IT/S3M/MOD/XM playback.

# Usage
- (Optional step, this will also be done internally when attempting to load the module) Call `m4p_TestFromData` with a pointer to a memory buffer containing the tracker module and its length as parameters to test if the module is a format that is compatible with mod4play. A result of zero indicates that it is an unknown format and should not be used.
- Load a supported module with the `m4p_LoadFromData` function, passing a pointer to a memory buffer containing the module, its length, the desired frequency/sample rate, and the desired mixing buffer size as parameters. The mixing buffer size should correspond to the size of the buffer you are planning on using as output for generated samples. This function will return `false` if a replayer was not successfully initialized.
- Once successfully loaded, the memory buffer that you passed to this function can be safely freed if you are not otherwise using it.
- Prepare the module for playback with the `m4p_PlaySong` function. This does not require any parameters and will not generate any audio yet.
- In an appropriate place in your program, call the `m4p_GenerateSamples` function, passing a pointer to an initialized buffer to store the generated samples and the number of desired samples to generate as parameters. The number of samples to generate should be no more than the size of the buffer divided by `sizeof(s16_t)`. Generated samples will be in the form of pairs of signed 16-bit integers.
- When finished with playback, call the `m4p_Close` function to reset the internal replayer, and the `m4p_FreeSong` function to free the internally allocated buffer containing the module. Neither function requires any parameters.
36 changes: 36 additions & 0 deletions cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <stdint.h>

#ifdef _WIN32

#ifdef _WIN64
#define CPU_32BIT 0
#define CPU_64BIT 1
#else
#define CPU_32BIT 1
#define CPU_64BIT 0
#endif

#else
#include <limits.h>

#if __WORDSIZE == 64
#define CPU_32BIT 0
#define CPU_64BIT 1
#else
#define CPU_32BIT 1
#define CPU_64BIT 0
#endif

#endif

#if CPU_64BIT
#define CPU_BITS 64
#define uintCPUWord_t uint64_t
#define intCPUWord_t int64_t
#else
#define CPU_BITS 32
#define uintCPUWord_t uint32_t
#define intCPUWord_t int32_t
#endif
453 changes: 453 additions & 0 deletions ft_tables.c

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions ft_tables.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <stdint.h>

extern const uint32_t panningTab[257];
extern const uint16_t amigaPeriods[1936];
extern const uint16_t linearPeriods[1936];
extern const int32_t logTab[768];
extern const char *MODSig[16];
extern const uint16_t amigaPeriod[96];
extern const uint8_t vibTab[32];
extern const int8_t vibSineTab[256];
extern const uint8_t arpTab[256];
Loading

0 comments on commit 31bb429

Please sign in to comment.