Skip to content

Commit

Permalink
Doom sound (#73)
Browse files Browse the repository at this point in the history
doom: add I2S sound driver
doom: do not set pins for I2S (it breaks select button)
doom: add buzzer sound driver
doom: add sound device menu on startup
sdk: fix multiboot not resetting firmware path
sdk: fix default Canvas size
sdk: cleanup code alignment
  • Loading branch information
and3rson authored Mar 28, 2024
1 parent f46678c commit 97dea0b
Show file tree
Hide file tree
Showing 17 changed files with 693 additions and 51 deletions.
8 changes: 8 additions & 0 deletions firmware/doom/lib/doomgeneric/src/d_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ void D_FreeBuffers() {
R_FreeThings();
R_FreeBSP();
}

// void* ps_malloc(size_t size) {
// void* ptr = heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
// if (ptr == NULL) {
// DG_printf("ps_malloc: failed to allocate %d bytes\n", size);
// }
// return ptr;
// }
39 changes: 37 additions & 2 deletions firmware/doom/lib/doomgeneric/src/d_alloc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
#ifndef D_ALLOC_H
#define D_ALLOC_H

#include <stdlib.h>
#include "d_log.h"

extern void D_AllocBuffers (void);
extern void D_FreeBuffers (void);
extern void D_AllocBuffers(void);
extern void D_FreeBuffers(void);

#ifndef MALLOC_CAP_EXEC

#define MALLOC_CAP_EXEC (1 << 0) ///< Memory must be able to run executable code
#define MALLOC_CAP_32BIT (1 << 1) ///< Memory must allow for aligned 32-bit data accesses
#define MALLOC_CAP_8BIT (1 << 2) ///< Memory must allow for 8/16/...-bit data accesses
#define MALLOC_CAP_DMA (1 << 3) ///< Memory must be able to accessed by DMA
#define MALLOC_CAP_PID2 (1 << 4) ///< Memory must be mapped to PID2 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID3 (1 << 5) ///< Memory must be mapped to PID3 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID4 (1 << 6) ///< Memory must be mapped to PID4 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID5 (1 << 7) ///< Memory must be mapped to PID5 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID6 (1 << 8) ///< Memory must be mapped to PID6 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID7 (1 << 9) ///< Memory must be mapped to PID7 memory space (PIDs are not currently used)
#define MALLOC_CAP_SPIRAM (1 << 10) ///< Memory must be in SPI RAM
#define MALLOC_CAP_INTERNAL \
(1 << 11) ///< Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off
#define MALLOC_CAP_DEFAULT \
(1 << 12) ///< Memory can be returned in a non-capability-specific memory allocation (e.g. malloc(), calloc()) call
#define MALLOC_CAP_IRAM_8BIT (1 << 13) ///< Memory must be in IRAM and allow unaligned access
#define MALLOC_CAP_RETENTION (1 << 14) ///< Memory must be able to accessed by retention DMA
#define MALLOC_CAP_RTCRAM (1 << 15) ///< Memory must be in RTC fast memory

#define MALLOC_CAP_INVALID (1 << 31) ///< Memory can't be used / list end marker

#endif

// Including <esp_heap_caps.h> breaks some literals (like "false")
extern void* heap_caps_malloc(size_t size, uint32_t caps);
extern void* ps_malloc(size_t size);

#endif // D_ALLOC_H
3 changes: 2 additions & 1 deletion firmware/doom/lib/doomgeneric/src/doomfeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

// Enables sound output

#undef FEATURE_SOUND
#define FEATURE_SOUND
// #undef FEATURE_SOUND

#endif /* #ifndef DOOM_FEATURES_H */

Expand Down
12 changes: 6 additions & 6 deletions firmware/doom/lib/doomgeneric/src/i_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int snd_mport = 0;

// Compiled-in sound modules:

static sound_module_t *sound_modules[] =
static sound_module_t *sound_modules[] =
{
#ifdef FEATURE_SOUND
&DG_sound_module,
Expand Down Expand Up @@ -129,7 +129,7 @@ static void InitSfxModule(boolean use_sfx_prefix)
// Is the sfx device in the list of devices supported by
// this module?

if (SndDeviceInList(snd_sfxdevice,
if (SndDeviceInList(snd_sfxdevice,
sound_modules[i]->sound_devices,
sound_modules[i]->num_sound_devices))
{
Expand Down Expand Up @@ -160,7 +160,7 @@ static void InitMusicModule(void)
//

void I_InitSound(boolean use_sfx_prefix)
{
{
boolean nosound, nosfx, nomusic;

//!
Expand All @@ -174,7 +174,7 @@ void I_InitSound(boolean use_sfx_prefix)
//!
// @vanilla
//
// Disable sound effects.
// Disable sound effects.
//

nosfx = M_CheckParm("-nosfx") > 0;
Expand Down Expand Up @@ -230,7 +230,7 @@ void I_ShutdownSound(void)

int I_GetSfxLumpNum(sfxinfo_t *sfxinfo)
{
if (sound_module != NULL)
if (sound_module != NULL)
{
return sound_module->GetSfxLumpNum(sfxinfo);
}
Expand Down Expand Up @@ -407,7 +407,7 @@ boolean I_MusicIsPlaying(void)
{
return false;
}

}

void I_BindSoundVariables(void)
Expand Down
27 changes: 6 additions & 21 deletions firmware/doom/lib/doomgeneric/src/i_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#ifndef __I_SWAP__
#define __I_SWAP__

#ifdef FEATURE_SOUND
// #ifdef FEATURE_SOUND

#include <SDL_endian.h>
// #include <SDL_endian.h>

// Endianess handling.
// WAD files are stored little endian.
Expand All @@ -32,37 +32,22 @@
// These are deliberately cast to signed values; this is the behaviour
// of the macros in the original source and some code relies on it.

#define SHORT(x) ((signed short) SDL_SwapLE16(x))
#define LONG(x) ((signed int) SDL_SwapLE32(x))
#define SHORT(x) ((signed short) x)
#define LONG(x) ((signed int) x)

// Defines for checking the endianness of the system.

#if SDL_BYTEORDER == SYS_LIL_ENDIAN
#define SYS_LITTLE_ENDIAN
#elif SDL_BYTEORDER == SYS_BIG_ENDIAN
#define SYS_BIG_ENDIAN
#endif

// cosmito from lsdldoom
#define doom_swap_s(x) \
((short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
(((unsigned short int)(x) & 0xff00) >> 8)))
(((unsigned short int)(x) & 0xff00) >> 8)))


#if ( SDL_BYTEORDER == SDL_BIG_ENDIAN )
#define doom_wtohs(x) doom_swap_s(x)
#else
#define doom_wtohs(x) (short int)(x)
#endif

#else

#define SHORT(x) ((signed short) (x))
#define LONG(x) ((signed int) (x))

#define SYS_LITTLE_ENDIAN

#endif /* FEATURE_SOUND */
// #endif /* FEATURE_SOUND */

#endif

15 changes: 8 additions & 7 deletions firmware/doom/lib/doomgeneric/src/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "i_sound.h"
#include "i_timer.h"
#include "i_video.h"
#include "d_alloc.h"

#include "i_system.h"

Expand All @@ -58,7 +59,6 @@
#define DEFAULT_RAM 6 /* MiB */
#define MIN_RAM 6 /* MiB */


typedef struct atexit_listentry_s atexit_listentry_t;

struct atexit_listentry_s
Expand Down Expand Up @@ -116,7 +116,8 @@ static byte *AutoAllocMemory(int *size, int default_ram, int min_ram)

*size = default_ram * 1024 * 1024;

zonemem = malloc(*size);
// zonemem = malloc(*size);
zonemem = ps_malloc(*size);

// Failed to allocate? Reduce zone size until we reach a size
// that is acceptable.
Expand Down Expand Up @@ -157,7 +158,7 @@ byte *I_ZoneBase (int *size)

zonemem = AutoAllocMemory(size, default_ram, min_ram);

DG_printf("zone memory: %p, %x allocated for zone\n",
DG_printf("zone memory: %p, %x allocated for zone\n",
zonemem, *size);

return zonemem;
Expand Down Expand Up @@ -191,7 +192,7 @@ void I_PrintStartupBanner(char *gamedescription)
I_PrintDivider();
I_PrintBanner(gamedescription);
I_PrintDivider();

DG_printf(
" " PACKAGE_NAME " is free software, covered by the GNU General Public\n"
" License. There is NO warranty; not even for MERCHANTABILITY or FITNESS\n"
Expand All @@ -201,7 +202,7 @@ void I_PrintStartupBanner(char *gamedescription)
I_PrintDivider();
}

//
//
// I_ConsoleStdout
//
// Returns true if stdout is a real console, false if it is a file
Expand Down Expand Up @@ -248,8 +249,8 @@ void I_Quit (void)
atexit_listentry_t *entry;

// Run through all exit functions
entry = exit_funcs;

entry = exit_funcs;

while (entry != NULL)
{
Expand Down
3 changes: 2 additions & 1 deletion firmware/doom/lib/doomgeneric/src/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "doomdef.h"
#include "d_loop.h"
#include "d_alloc.h"

#include "m_bbox.h"
#include "m_menu.h"
Expand Down Expand Up @@ -116,7 +117,7 @@ void (*spanfunc) (void);
int R_AllocMain (void)
{
int viewangletox_size = sizeof(int) * FINEANGLES/2;
viewangletox = malloc (viewangletox_size);
viewangletox = ps_malloc (viewangletox_size);
if (viewangletox == NULL)
{
return -1;
Expand Down
4 changes: 3 additions & 1 deletion firmware/doom/lib/doomgeneric/src/r_plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "i_system.h"
#include "z_zone.h"
#include "w_wad.h"
#include "d_alloc.h"

#include "doomdef.h"
#include "doomstat.h"
Expand Down Expand Up @@ -109,7 +110,8 @@ int R_AllocPlanes (void)
// return -1;
// }
int openings_size = sizeof(short) * MAXOPENINGS;
openings = malloc (openings_size);
// openings = malloc(openings_size);
openings = ps_malloc(openings_size);
if (openings == NULL)
{
// free (visplanes);
Expand Down
3 changes: 2 additions & 1 deletion firmware/doom/lib/doomgeneric/src/r_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "i_system.h"
#include "z_zone.h"
#include "w_wad.h"
#include "d_alloc.h"

#include "r_local.h"

Expand Down Expand Up @@ -93,7 +94,7 @@ char* spritename;
int R_AllocThings (void)
{
int vissprites_size = MAXVISSPRITES * sizeof(vissprite_t);
vissprites = malloc (vissprites_size);
vissprites = ps_malloc (vissprites_size);
if (vissprites == NULL)
{
return -1;
Expand Down
Loading

0 comments on commit 97dea0b

Please sign in to comment.