Browse Source

[v2] option to use the asm or C++ (with patches) backend

master
PoroCYon 2 years ago
parent
commit
7d5e1b9b49
4 changed files with 107 additions and 12 deletions
  1. +3
    -0
      .gitmodules
  2. +56
    -7
      v2/Makefile
  3. +47
    -5
      v2/src/lplayer.cpp
  4. +1
    -0
      v2/v2m-player

+ 3
- 0
.gitmodules View File

@ -4,3 +4,6 @@
[submodule "oidos/oidos"]
path = oidos/oidos
url = https://gitlab.com/PoroCYon/oidos.git
[submodule "v2/v2m-player"]
path = v2/v2m-player
url = https://github.com/jgilje/v2m-player

+ 56
- 7
v2/Makefile View File

@ -1,4 +1,9 @@
# C++ version is more stable, but might be larger
USE_CXX_VERSION ?= 1
# you most likely want this
USE_RONAN ?= 1
NASM ?= nasm
default: all
@ -6,21 +11,65 @@ default: all
%/:
mkdir -p "$@"
v2m-player/README.md:
@>&2 echo "\`v2m-player' submodule not initialized. Please run the following command:"
@>&2 echo " git submodule update --init --recursive"
@false
fr_public/README.md:
@>&2 echo "\`fr_public' submodule not initialized. Please run the following command:"
@>&2 echo " git submodule update --init --recursive"
@false
CFLAGS := -m32
ASFLAGS := -felf32
ifeq ($(USE_CXX_VERSION),0)
CFLAGS += -I libv2/
else
CFLAGS += -I v2m-player/src/ -DUSE_CXX_VERSION
endif
ifneq ($(USE_RONAN),0)
CFLAGS += -DRONAN
ASFLAGS += -DRONAN
endif
CFLAGS += -g -ffunction-sections -fdata-sections
ASFLAGS += -g
obj/lplayer.o: src/lplayer.cpp obj/
$(CXX) -g -m32 -o "$@" -c "$<" -I libv2
obj/v2mplayer.o: libv2/v2mplayer.cpp obj/
$(CXX) -g -m32 -o "$@" -c "$<" -I libv2
obj/synth.o: libv2/synth.asm obj/
$(NASM) -g -f elf32 -o "$@" "$<"
$(CXX) $(CFLAGS) -o "$@" -c "$<"
obj/v2mplayer.o: libv2/v2mplayer.cpp obj/ fr_public/README.md
$(CXX) $(CFLAGS) -o "$@" -c "$<"
obj/synth.o: libv2/synth.asm obj/ fr_public/README.md
$(NASM) $(ASFLAGS) -o "$@" "$<"
obj/pv2mconv.o: v2m-player/src/v2mconv.cpp obj/ v2m-player/README.md
$(CXX) $(CFLAGS) -o "$@" -c "$<"
obj/pv2mplayer.o: v2m-player/src/v2mplayer.cpp obj/ v2m-player/README.md
$(CXX) $(CFLAGS) -o "$@" -c "$<"
obj/pronan.o: v2m-player/src/ronan.cpp obj/ v2m-player/README.md
$(CXX) $(CFLAGS) -o "$@" -c "$<"
obj/psynth_core.o: v2m-player/src/synth_core.cpp obj/ v2m-player/README.md
$(CXX) $(CFLAGS) -o "$@" -c "$<"
obj/psounddef.o: v2m-player/src/sounddef.cpp obj/ v2m-player/README.md
$(CXX) $(CFLAGS) -o "$@" -c "$<"
obj/v2m-%.asm: mus/%.v2m obj/
printf "global theTune\ntheTune:\nincbin \"%s\"\n" "$<" > "$@"
printf "[section .data.theTune]\n" > "$@"
printf "global theTune\ntheTune:\n\tincbin \"%s\"\n" "$<" >> "$@"
printf "global theTune_size\ntheTune_size:\n\tdd \$$ - theTune\n" >> "$@"
obj/v2m-%.o: obj/v2m-%.asm
$(NASM) -g -f elf32 -o "$@" "$<"
ifeq ($(USE_CXX_VERSION),0)
bin/lplayer-%: obj/lplayer.o obj/synth.o obj/v2mplayer.o obj/v2m-%.o bin/
$(CXX) -g -m32 -o "$@" $(filter-out bin/,$^)
else
bin/lplayer-%: obj/lplayer.o obj/psynth_core.o obj/pv2mconv.o obj/pv2mplayer.o \
obj/pronan.o obj/psounddef.o obj/v2m-%.o bin/
endif
$(CXX) -Wl,--gc-sections $(CFLAGS) -o "$@" $(filter-out bin/,$^)
all: $(patsubst mus/%.v2m,bin/lplayer-%,$(wildcard mus/*.v2m))
echo $^


+ 47
- 5
v2/src/lplayer.cpp View File

@ -1,22 +1,63 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define AUTOCONVERT
#include "v2mplayer.h"
#include "synth.h"
/*#include "libv2.h"*/
#ifdef AUTOCONVERT
#include "v2mconv.h"
#endif
#ifdef USE_CXX_VERSION
#include "sounddef.h"
#endif
// automatically convert the module to the newest format version
extern "C" const uint8_t theTune[];
extern "C" const size_t theTune_size;
#define BUFFERLEN (8192) /* arbitrary */
static V2MPlayer player;
static sF32 output_buffer[BUFFERLEN*8];
static float output_buffer[BUFFERLEN*8];
#ifdef AUTOCONVERT
static uint8_t* check_and_convert(const uint8_t* tune, size_t len) {
if (tune[2] != 0 || tune[3] != 0) {
fprintf(stderr, "Invalid input file\n");
return NULL;
}
int v = CheckV2MVersion(tune, len);
if (v < 0) {
fprintf(stderr, "Invalid input file (version not recognised)\n");
return NULL;
}
uint8_t* theTune2;
int len2;
ConvertV2M(tune, len, &theTune2, &len2);
return theTune2;
}
#endif
int main() {
#ifdef USE_CXX_VERSION
sdInit();
#endif
#ifdef AUTOCONVERT
uint8_t* theTune2 = check_and_convert(theTune, theTune_size);
if (!theTune2) return 1;
#else
const uint8_t* theTune2 = theTune;
#endif
player.Init();
player.Open(theTune);
player.Open(theTune2);
player.Play();
@ -29,8 +70,9 @@ int main() {
* works around it. ¯\_()_/¯
* If you have a better fix, please tell me.
*/
player.Render(output_buffer, 64, sFALSE);
write(STDOUT_FILENO, output_buffer, 64*sizeof(sF32)*2/*stereo*/);
const size_t samples = 64;
player.Render(output_buffer, samples, false);
write(STDOUT_FILENO, output_buffer, samples*sizeof(float)*2/*stereo*/);
}
player.Close();


+ 1
- 0
v2/v2m-player

@ -0,0 +1 @@
Subproject commit 9be97c86de948a4cde313fdc178013f665af6326

Loading…
Cancel
Save