Skip to content

Commit

Permalink
fixed build issues with devkitarm updates. adjusted incorrect music p…
Browse files Browse the repository at this point in the history
…layback rate.
  • Loading branch information
elhobbs committed Apr 29, 2017
1 parent fd234d3 commit 194b7ef
Show file tree
Hide file tree
Showing 12 changed files with 937 additions and 758 deletions.
2 changes: 1 addition & 1 deletion 3ds/3ds_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ void S_UpdateSounds(mobj_t *listener)
I_UpdateChannels();
S_Update();
//mus_stats();
mus_dsp_submit();
//mus_dsp_submit();
}

#ifdef _WIN32
Expand Down
39 changes: 35 additions & 4 deletions 3ds/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "ST_START.H"

#ifdef _3DS
u32 __stacksize__ = 1024 * 1024;
u32 __stacksize__ = 512 * 1024;
#endif

int DisplayTicker = 0;
Expand Down Expand Up @@ -114,7 +114,7 @@ void I_InitNetwork(void)
//
// single player game
//
doomcom = malloc(sizeof(*doomcom));
doomcom = hmalloc(sizeof(*doomcom));
memset(doomcom, 0, sizeof(*doomcom));
netgame = false;
doomcom->id = DOOMCOM_ID;
Expand Down Expand Up @@ -267,7 +267,7 @@ void I_Quit(void)
byte *I_ZoneBase(int *size)
{
int heap = 24*1024*1024;
byte *ptr = malloc(heap);;
byte *ptr = hmalloc(heap);;

*size = heap;
return ptr;
Expand All @@ -283,7 +283,12 @@ byte *I_ZoneBase(int *size)

byte *I_AllocLow(int length)
{
byte *mem = (byte *)malloc(length);
byte *mem = (byte *)hmalloc(length);
printf("alloc_low: %p\n", mem);

if (mem == 0) {
while (1);
}

memset(mem, 0, length);
return mem;
Expand Down Expand Up @@ -868,3 +873,29 @@ fixed_t FixedDiv(fixed_t a, fixed_t b)
}

#endif

static FILE *_log = 0;

void* __hmalloc(size_t s, char *_file, int _line) {
void *p = malloc(s);
#if 0
if (_log == 0) {
_log = fopen("hmalloc.txt", "w");
}
printf("malloc: %p %d %s %d\n", p, s, _file, _line);
fprintf(_log,"malloc: %p %d %s %d\r\n", p, s, _file, _line);
fflush(_log);
#endif
return p;
}

void __hfree(void *p, char *_file, int _line) {
#if 0
if (_log == 0) {
_log = fopen("hmalloc.txt", "w");
}
printf("free: %p %s %d\n", p, _file, _line);
fprintf(_log,"free: %p %s %d\r\n", p, _file, _line);
#endif
free(p);
}
39 changes: 25 additions & 14 deletions 3ds/musplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "opl.h"

#include "H2DEF.H"
#define MUS_MIX_CHANNEL 1
#define MUS_PLAYBACK_RATE 11025

void mixer_update(short *pAudioData, int count);
int mixer_pos();
Expand Down Expand Up @@ -927,7 +929,7 @@ void mus_frame() {
if (adlib_mus - nxt <= 0) {
//printf("mus: %5d %5.6f\n", adlib_mus - nxt,nxt/32767.0f);
mus_play_timer();
adlib_mus += 233;
adlib_mus += (MUS_PLAYBACK_RATE/140);
}
if (adlib_pos < nxt) {
adlib_pos = nxt;
Expand Down Expand Up @@ -956,7 +958,7 @@ void mus_frame() {
svcSleepThread(500000);
}
}

void mus_dsp_submit(void);
static void adlibThreadMain(void* arg) {
//make sure the mus thread starts
svcWaitSynchronization(musRequest, U64_MAX);
Expand All @@ -981,7 +983,8 @@ static void adlibThreadMain(void* arg) {
//printf("\n at %08x...", mixer_pos());
//gfxFlushBuffers();
mus_frame();
svcSleepThread(50000);
svcSleepThread(500);
mus_dsp_submit();
} while (musState == MUS_PLAYING);

//svcSleepThread(5000000000LL);
Expand Down Expand Up @@ -1014,7 +1017,7 @@ int mus_setup_timer() {
adlib_mus = adlib_pos = mixer_pos();

printf("starting music thread...");
ret = svcCreateThread(&adlibHandle, adlibThreadMain, 0x0, (u32*)((char*)adlibStack + sizeof(adlibStack)), 0x24, -2);
ret = svcCreateThread(&adlibHandle, adlibThreadMain, 0x0, (u32*)((char*)adlibStack + sizeof(adlibStack)), 0x18, -2);
if (ret != 0) {
printf(" failed %d\n", ret);
gfxFlushBuffers();
Expand All @@ -1026,8 +1029,8 @@ int mus_setup_timer() {
svcClearEvent(musResponse);
printf(" done\n");
gfxFlushBuffers();
svcSleepThread(3000000000LL);
return 0;
//svcSleepThread(3000000000LL);
}
extern int audio_initialized;

Expand All @@ -1036,7 +1039,7 @@ void mus_init() {
// return;
//}

if (!OPL_Init(32728))
if (!OPL_Init(MUS_PLAYBACK_RATE))
{
//printf("Dude. The Adlib isn't responding.\n");
return;
Expand Down Expand Up @@ -1101,7 +1104,7 @@ void mus_exit() {

static int snd_channels = 2;
static int snd_samplebits = 16;
static int snd_speed = 11025;
static int snd_speed = MUS_PLAYBACK_RATE;
static int snd_samples;
static int snd_samplepos;
static byte* snd_buffer;
Expand All @@ -1116,7 +1119,7 @@ static volatile int snd_sent, snd_completed;

static int gSndBufSize = 0;
#ifdef _3DS
static ndspWaveBuf gWavebuf[WAV_BUFFERS];
static volatile ndspWaveBuf gWavebuf[WAV_BUFFERS];
#endif
static float gMix[12];

Expand Down Expand Up @@ -1144,9 +1147,9 @@ static void dsp_init() {
memset(lpData, 0, gSndBufSize);
#ifdef _3DS
//ndspInit();
ndspChnSetInterp(1, NDSP_INTERP_NONE);
ndspChnSetRate(1, (float)snd_speed);
ndspChnSetFormat(1, NDSP_FORMAT_STEREO_PCM16);
ndspChnSetInterp(MUS_MIX_CHANNEL, NDSP_INTERP_NONE);
ndspChnSetRate(MUS_MIX_CHANNEL, (float)snd_speed);
ndspChnSetFormat(MUS_MIX_CHANNEL, NDSP_FORMAT_STEREO_PCM16);
memset(gWavebuf, 0, sizeof(ndspWaveBuf)*WAV_BUFFERS);
memset(gMix, 0, sizeof(gMix));
DSP_FlushDataCache(lpData, gSndBufSize);
Expand All @@ -1169,7 +1172,7 @@ static void dsp_init() {

static void dsp_shutdown() {
#ifdef _3DS
ndspChnWaveBufClear(1);
ndspChnWaveBufClear(MUS_MIX_CHANNEL);
svcSleepThread(20000);
//ndspExit();
#endif
Expand Down Expand Up @@ -1222,7 +1225,7 @@ void mus_dsp_submit(void)
{
#ifdef _3DS
//h = lpWaveHdr + (snd_sent&WAV_MASK);
ndspChnWaveBufAdd(1, gWavebuf + (snd_sent&WAV_MASK));
ndspChnWaveBufAdd(MUS_MIX_CHANNEL, gWavebuf + (snd_sent&WAV_MASK));
#endif
snd_sent++;
/*
Expand Down Expand Up @@ -1344,5 +1347,13 @@ void mixer_exit() {
}

void mixer_clear() {
ndspChnWaveBufClear(1);
int i;
ndspChnWaveBufClear(MUS_MIX_CHANNEL);
svcSleepThread(20000);
snd_sent = 0;
snd_completed = 0;
for (i = 0; i<WAV_BUFFERS; i++)
{
gWavebuf[i].status = NDSP_WBUF_FREE;
}
}
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ CFLAGS := -g -Wall -O3 -mword-relocations \
-fomit-frame-pointer -ffunction-sections \
$(ARCH)

CFLAGS += $(INCLUDE) -DARM11 -D_3DS \
-DARM -DUSE_DL_PREFIX -DHAVE_MORECORE=0 -DHAVE_MMAP=0 \
-DONLY_MSPACES -DMSPACES -Dmalloc_getpagesize=128 \
-DNO_MALLINFO
CFLAGS += $(INCLUDE) -DARM11 -D_3DS

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11

Expand Down
9 changes: 9 additions & 0 deletions hexen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,31 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hexen", "hexen.vcxproj", "{
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Debug-x86|ARM = Debug-x86|ARM
Debug-x86|x64 = Debug-x86|x64
Debug-x86|x86 = Debug-x86|x86
Release|ARM = Release|ARM
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug|ARM.ActiveCfg = Debug|ARM
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug|ARM.Build.0 = Debug|ARM
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug|x64.ActiveCfg = Debug|x64
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug|x64.Build.0 = Debug|x64
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug|x86.ActiveCfg = Debug|Win32
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug|x86.Build.0 = Debug|Win32
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug-x86|ARM.ActiveCfg = Debug-x86|ARM
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug-x86|ARM.Build.0 = Debug-x86|ARM
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug-x86|x64.ActiveCfg = Debug-x86|x64
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug-x86|x64.Build.0 = Debug-x86|x64
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug-x86|x86.ActiveCfg = Debug-x86|Win32
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Debug-x86|x86.Build.0 = Debug-x86|Win32
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Release|ARM.ActiveCfg = Release|ARM
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Release|ARM.Build.0 = Release|ARM
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Release|x64.ActiveCfg = Release|x64
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Release|x64.Build.0 = Release|x64
{0DD9E115-E85A-4CF8-B0D8-25B81A45EF27}.Release|x86.ActiveCfg = Release|Win32
Expand Down
Loading

0 comments on commit 194b7ef

Please sign in to comment.