ref: 0b77c1f82cfa664537763b8d7745797fa42292ef
parent: 7882ac7043ed7f57cb8578ee9cd76ba681a8d0b7
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Dec 3 17:03:33 EST 2020
add plan 9 stuff
--- /dev/null
+++ b/ft2dec.c
@@ -1,0 +1,74 @@
+#include "common.h"
+#include "pmplay.h"
+#include "pmp_mix.h"
+
+static void
+usage(void)
+{
+ fprint(2, "usage: %s [-v volume] [-a amp] [-f freq] <file.(xm|mod|ft) >/dev/audio\n", argv0);
+ exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
+ int n, r, sz, frq, amp, vol;
+ s16int s[1024*2];
+ u8int *b;
+
+ frq = 44100;
+ amp = 10;
+ vol = 256;
+ ARGBEGIN{
+ case 'f':
+ frq = atoi(EARGF(usage()));
+ assert(frq >= 8000 && frq <= 96000);
+ break;
+ case 'a':
+ amp = atoi(EARGF(usage()));
+ assert(amp >= 1 && amp <= 32);
+ break;
+ case 'v':
+ vol = atoi(EARGF(usage()));
+ assert(vol >= 0 && vol <= 256);
+ break;
+ default:
+ usage();
+ }ARGEND
+
+ if(!initMusic(frq, nelem(s)/2, true, true))
+ sysfatal("initMusic");
+ setAmp(amp);
+ setMasterVol(vol);
+
+ sz = 32768;
+ b = nil;
+ for(n = 0;; n += r){
+ if(sz-n < 65536){
+ sz *= 2;
+ if((b = realloc(b, sz)) == nil)
+ sysfatal("memory");
+ }
+ if((r = read(0, b+n, sz-n)) < 0)
+ sysfatal("%r");
+ if(r == 0)
+ break;
+ }
+
+ if(!loadMusicFromData(b, n))
+ sysfatal("loadMusicFromData");
+ if(!startMusic())
+ sysfatal("startMusic");
+ startPlaying();
+ for(;;){
+ mix_UpdateBuffer(s, nelem(s)/2);
+ write(1, s, sizeof(s));
+ }
+
+/* EH?
+ stopMusic();
+ freeMusic();
+
+ exits(nil);
+*/
+}
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,24 @@
+</$objtype/mkfile
+
+BIN=/$objtype/bin/audio
+CFLAGS=$CFLAGS -p -D__plan9__
+TARG=ft2dec
+
+HFILES=\
+ pmp_main.h\
+ pmp_mix.h\
+ pmplay.h\
+ snd_masm.h\
+ tables.h\
+
+OFILES=\
+ ft2dec.$O\
+ pmp_main.$O\
+ pmp_mix.$O\
+ pmplay.$O\
+ snd_masm.$O\
+ tables.$O\
+
+default:V: all
+
+</sys/src/cmd/mkone
--- a/pmp_main.c
+++ b/pmp_main.c
@@ -1,8 +1,6 @@
// XM replayer
-#include <stdio.h>
-#include <stdint.h>
-#include <stdbool.h>
+#include "common.h"
#include "pmplay.h"
#include "pmp_mix.h"
#include "snd_masm.h"
@@ -189,10 +187,9 @@
static void dummy(stmTyp *ch, uint8_t param)
{
+ USED(ch);
+ USED(param);
return;
-
- (void)ch;
- (void)param;
}
static void finePortaUp(stmTyp *ch, uint8_t param)
@@ -305,7 +302,7 @@
if (song.pattDelTime2 == 0)
song.pattDelTime = param + 1;
- (void)ch;
+ USED(ch);
}
static const efxRoutine EJumpTab_TickZero[16] =
@@ -339,7 +336,7 @@
song.pBreakPos = 0;
song.posJumpFlag = true;
- (void)ch;
+ USED(ch);
}
static void pattBreak(stmTyp *ch, uint8_t param)
@@ -352,7 +349,7 @@
else
song.pBreakPos = 0;
- (void)ch;
+ USED(ch);
}
static void setSpeed(stmTyp *ch, uint8_t param)
@@ -367,7 +364,7 @@
song.timer = song.tempo = param;
}
- (void)ch;
+ USED(ch);
}
static void setGlobaVol(stmTyp *ch, uint8_t param)
@@ -381,7 +378,7 @@
for (int32_t i = 0; i < song.antChn; i++, c++) // 8bb: update all voice volumes
c->status |= IS_Vol;
- (void)ch;
+ USED(ch);
}
static void setEnvelopePos(stmTyp *ch, uint8_t param)
@@ -630,14 +627,14 @@
static void v_dummy(stmTyp *ch)
{
- (void)ch;
+ USED(ch);
return;
}
static void v_dummy2(stmTyp *ch, uint8_t *volKol)
{
- (void)ch;
- (void)volKol;
+ USED(ch);
+ USED(volKol);
return;
}
--- a/pmp_main.h
+++ b/pmp_main.h
@@ -1,7 +1,4 @@
#pragma once
-#include <stdint.h>
-#include <stdbool.h>
-
void mainPlayer(void);
uint32_t getFrequenceValue(uint16_t period);
--- a/pmp_mix.c
+++ b/pmp_mix.c
@@ -1,10 +1,6 @@
-#include <assert.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
+#include "common.h"
#include "pmplay.h"
+#include "pmp_mix.h"
#include "pmp_main.h"
#include "snd_masm.h"
#include "tables.h"
--- a/pmp_mix.h
+++ b/pmp_mix.h
@@ -1,9 +1,5 @@
#pragma once
-#include <stdint.h>
-#include <stdbool.h>
-#include "pmplay.h"
-
enum
{
Status_SetVol = 1,
--- a/pmplay.c
+++ b/pmplay.c
@@ -13,13 +13,7 @@
#define DEFAULT_AMP 4
#define DEFAULT_MASTER_VOL 256
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <math.h>
-#include <assert.h>
+#include "common.h"
#include "pmplay.h"
#include "pmp_mix.h"
#include "snd_masm.h"
@@ -31,6 +25,11 @@
(((uint16_t)((value) & 0xFF00)) >> 8) \
)
+
+#ifdef __plan9__
+#pragma pack on
+#endif
+
#ifdef _MSC_VER
#pragma pack(push)
#pragma pack(1)
@@ -45,6 +44,8 @@
}
#ifdef __GNUC__
__attribute__ ((packed))
+#elif defined(__plan9__)
+#pragma pack on
#endif
songHeaderTyp;
@@ -134,7 +135,11 @@
#ifdef _MSC_VER
#pragma pack(pop)
#endif
-
+
+#ifdef __plan9__
+#pragma pack off
+#endif
+
static int32_t soundBufferSize;
// globalized
--- a/pmplay.h
+++ b/pmplay.h
@@ -1,8 +1,5 @@
#pragma once
-#include <stdint.h>
-#include <stdbool.h>
-
// AUDIO DRIVERS
#if defined AUDIODRIVER_SDL
#include "audiodrivers/sdl/sdldriver.h"
@@ -107,7 +104,7 @@
bool loadMusic(const char *filename); // .XM/.MOD/.FT
void freeMusic(void);
bool startMusic(void);
-void stopMusic();
+void stopMusic(void);
void pauseMusic(void);
void resumeMusic(void);
void setMasterVol(int32_t v); // 0..256
--- a/snd_masm.c
+++ b/snd_masm.c
@@ -1,7 +1,7 @@
-#include <stdint.h>
-#include <stdbool.h>
-#include "snd_masm.h"
+#include "common.h"
#include "pmplay.h"
+#include "pmp_mix.h"
+#include "snd_masm.h"
/* 8bb: This is done in a slightly different way, but the result
** is the same (bit-accurate to FT2.08/FT2.09 w/ SB16, and WAV-writer).
--- a/snd_masm.h
+++ b/snd_masm.h
@@ -1,9 +1,5 @@
#pragma once
-#include <stdint.h>
-#include <stdbool.h>
-#include "pmp_mix.h"
-
#define GET_VOL \
const int32_t CDA_LVol = v->SLVol1; \
const int32_t CDA_RVol = v->SRVol1; \
@@ -32,12 +28,12 @@
#define SET_BASE8 \
const int8_t *CDA_LinearAdr = (int8_t *)v->SBase; \
const int8_t *CDA_LinAdrRev = (int8_t *)v->SRevBase; \
- const int8_t *smpPtr = CDA_LinearAdr + realPos; \
+ const int8_t *smpPtr = CDA_LinearAdr + realPos; USED(smpPtr); \
#define SET_BASE16 \
const int16_t *CDA_LinearAdr = (int16_t *)v->SBase; \
const int16_t *CDA_LinAdrRev = (int16_t *)v->SRevBase; \
- const int16_t *smpPtr = CDA_LinearAdr + realPos; \
+ const int16_t *smpPtr = CDA_LinearAdr + realPos; USED(smpPtr); \
#define INC_POS \
smpPtr += CDA_IPValH; \
--- a/tables.c
+++ b/tables.c
@@ -1,4 +1,4 @@
-#include <stdint.h>
+#include "common.h"
// 8bb: bit-accurate FT2 tables (FT2.08/FT2.09)
--- a/tables.h
+++ b/tables.h
@@ -1,7 +1,5 @@
#pragma once
-#include <stdint.h>
-
extern const uint32_t panningTab[257];
extern const uint16_t amigaPeriods[1936];
extern const uint16_t linearPeriods[1936];