Skip to content

Commit

Permalink
Shoring up issues with sound in various places. Starting NDS sound.
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoparadox committed Aug 13, 2024
1 parent d1bfa08 commit 833837a
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 116 deletions.
11 changes: 8 additions & 3 deletions api/dosbios/retapid.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,21 @@ struct RETROFLAT_PLATFORM {

#ifndef NO_RETROSND

# define RETROSND_MPU_FLAG_OUTPUT 0x40
# define RETROSND_MPU_TIMEOUT 30
#define RETROSND_PC_BIOS_SPKR 0x01
#define RETROSND_PC_BIOS_MPU 0x02
#define RETROSND_PC_BIOS_GUS 0x04
#define RETROSND_PC_BIOS_ADLIB 0x08

#define RETROSND_MPU_FLAG_OUTPUT 0x40
#define RETROSND_MPU_TIMEOUT 30

struct RETROFLAT_SOUND {
uint8_t flags;
uint16_t io_base;
uint8_t io_timeout;
uint8_t driver;
struct RETROSND_ADLIB_VOICE* adlib_voices;
char sf_bank_filename[SF_BANK_FILENAME_SZ_MAX + 1];
char sf_bank_filename[RETROFLAT_PATH_MAX + 1];
};

#endif /* !NO_RETROSND */
Expand Down
2 changes: 1 addition & 1 deletion api/dosbios/retapif.h
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args ) {

cleanup:

return retval;'
return retval;
}

/* === */
Expand Down
1 change: 1 addition & 0 deletions api/nds/retapid.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ uint8_t retroflat_viewport_focus(

struct RETROFLAT_SOUND {
uint8_t flags;
uint8_t channels[RETROSND_CHANNEL_CT];
};

#endif /* !NO_RETROSND */
Expand Down
15 changes: 11 additions & 4 deletions api/nds/retapif.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,9 @@ MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args ) {

assert( 2 <= sizeof( MERROR_RETVAL ) );

# pragma message( "warning: init not implemented" )
soundEnable();

g_retroflat_state->sound.flags |= RETROSND_FLAG_INIT;

return retval;
}
Expand Down Expand Up @@ -826,7 +828,11 @@ void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel ) {
return;
}

# pragma message( "warning: note_on not implemented" )
g_retroflat_state->sound.channels[channel] =
soundPlayPSG( 100, 2620, 32, 64 );

debug_printf( 1, "playing channel %u on DS channel: %u",
channel, g_retroflat_state->sound.channels[channel] );

}

Expand All @@ -841,7 +847,7 @@ void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel ) {
return;
}

# pragma message( "warning: note_off not implemented" )
soundKill( g_retroflat_state->sound.channels[channel] );

}

Expand Down Expand Up @@ -873,7 +879,8 @@ void retrosnd_shutdown() {
return;
}

# pragma message( "warning: shutdown not implemented" )
soundDisable();

}

#endif /* !NO_RETROSND */
Expand Down
2 changes: 1 addition & 1 deletion make/Makece.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OBJDIR_CECL_WINCE_MIPS := obj/cecl-wince-mips

OBJDIR_CECL_WINCE_X86 := obj/cecl-wince-x86

CFLAGS_CECL_WINCE += /nologo /GX- /D "_WIN32_WCE" /D "UNICODE" /I "$(WCE20DEV)/INCLUDE" /I "$(MAUG_ROOT)/api/win" /D "RETROFLAT_OS_WIN" /D "RETROFLAT_API_WINCE" /D "MAUG_ANCIENT_C" /D "RETROFLAT_NO_CLI" /D "RETROFLAT_NO_STRING" /D "MAUG_NO_STDLIB" /D "MAUG_WCHAR" $(INCLUDES_VS)
CFLAGS_CECL_WINCE += /nologo /GX- /D "_WIN32_WCE" /D "UNICODE" /I "$(WCE20DEV)/INCLUDE" /I "$(MAUG_ROOT)/api/win" /D "RETROFLAT_OS_WIN" /D "RETROFLAT_API_WINCE" /D "MAUG_ANCIENT_C" /D "RETROFLAT_NO_CLI" /D "RETROFLAT_NO_STRING" /D "MAUG_NO_STDLIB" /D "MAUG_WCHAR" /D "NO_RETROSND" $(INCLUDES_VS)

LDFLAGS_CECL_WINCE += commctrl.lib coredll.lib /nologo /subsystem:windowsce

Expand Down
214 changes: 107 additions & 107 deletions src/retroflt.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,113 @@ struct RETROFLAT_GLTEX {
};
#endif /* RETROFLAT_OPENGL */

struct RETROFLAT_ARGS;

#ifndef NO_RETROSND

/**
* \addtogroup maug_retrosnd RetroSound API
* \brief Abstraction layer header for sound on retro systems.
* \{
*
* \file retrosnd.h
* \brief Abstraction layer header for sound on retro systems.
*
* RetroSound is a compatibility layer for making sound
* on various platforms, including Windows, MS-DOS or Linux.
*
* To use, define RETROSND_C before including this header from your main.c.
*
* You may include this header in other .c files, as well, but RETROSND_C
* should \b ONLY be declared \b ONCE in the entire program.
*
* It is *highly* advised to use this in conjunction with retroflt.h.
*
* maug.h should also be included before this header.
*
* Special thanks to: "Programming the Adlib/Sound Blaster FM Music Chips"
* by Jeffrey S. Lee (https://bochs.sourceforge.io/techspec/adlib_sb.txt)
* and "The Gravis Ultrasound" by neuraldk
* (http://neuraldk.org/document.php?gus) for DOS platform-specific stuff.
*
* And the MPU-401 interface for being so darn simple!
*/

#ifndef RETROSND_TRACE_LVL
# define RETROSND_TRACE_LVL 0
#endif /* !RETROSND_TRACE_LVL */

#ifndef RETROSND_REG_TRACE_LVL
# define RETROSND_REG_TRACE_LVL 0
#endif /* !RETROSND_REG_TRACE_LVL */

/**
* \addtogroup maug_retrosnd_flags RetroSound State Flags
* \brief Flags indicating global state for the RETROSND_STATE::flags field.
* \{
*/

/**
* \brief Flag in RETROSND_STATE::flags indicating initialization was
* successful.
*/
#define RETROSND_FLAG_INIT 0x01

/*! \} */ /* maug_retrosnd_flags */

#define RETROSND_VOICE_BREATH 122

#define RETROSND_VOICE_SEASHORE 123

#define RETROSND_VOICE_BIRD_TWEET 124

#define RETROSND_VOICE_PHONE_RING 125

#define RETROSND_VOICE_HELICOPTER 126

#define RETROSND_VOICE_APPLAUSE 127

/**
* \brief Parameter for retrosnd_midi_set_voice() indicating a gunshot
* sound effect.
*/
#define RETROSND_VOICE_GUNSHOT 128

#define RETROSND_CHANNEL_CT 8

/**
* \brief Initialize retrosnd engine.
* \param args A pointer to the RETROSND_ARGS struct initialized by
* the calling program.
*
* The RETROSND_ARGS::snd_io_base field must be initialized with the address
* or other platform-specific indicator of the MIDI device to use.
*/
MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args );

/**
* \brief Set the name of the voice bank filename to use.
*/
void retrosnd_set_sf_bank( const char* filename_in );

void retrosnd_midi_set_voice( uint8_t channel, uint8_t voice );

void retrosnd_midi_set_control( uint8_t channel, uint8_t key, uint8_t val );

void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel );

void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel );

MERROR_RETVAL retrosnd_midi_play_smf( const char* filename );

uint8_t retrosnd_midi_is_playing_smf();

void retrosnd_shutdown();

/*! \} */ /* maug_retrosnd */

#endif /* !NO_RETROSND */

/* === OS-Specific Includes and Defines === */

#if defined( RETROFLAT_OS_WIN ) && !defined( MAUG_WINDOWS_H )
Expand Down Expand Up @@ -1523,112 +1630,6 @@ RETROFLAT_IN_KEY retroflat_poll_input( struct RETROFLAT_INPUT* input );

/*! \} */ /* maug_retroflt_input */

/**
* \addtogroup maug_retrosnd RetroSound API
* \brief Abstraction layer header for sound on retro systems.
* \{
*
* \file retrosnd.h
* \brief Abstraction layer header for sound on retro systems.
*
* RetroSound is a compatibility layer for making sound
* on various platforms, including Windows, MS-DOS or Linux.
*
* To use, define RETROSND_C before including this header from your main.c.
*
* You may include this header in other .c files, as well, but RETROSND_C
* should \b ONLY be declared \b ONCE in the entire program.
*
* It is *highly* advised to use this in conjunction with retroflt.h.
*
* maug.h should also be included before this header.
*
* Special thanks to: "Programming the Adlib/Sound Blaster FM Music Chips"
* by Jeffrey S. Lee (https://bochs.sourceforge.io/techspec/adlib_sb.txt)
* and "The Gravis Ultrasound" by neuraldk
* (http://neuraldk.org/document.php?gus) for DOS platform-specific stuff.
*
* And the MPU-401 interface for being so darn simple!
*/

#ifndef RETROSND_TRACE_LVL
# define RETROSND_TRACE_LVL 0
#endif /* !RETROSND_TRACE_LVL */

#ifndef RETROSND_REG_TRACE_LVL
# define RETROSND_REG_TRACE_LVL 0
#endif /* !RETROSND_REG_TRACE_LVL */

#define SF_BANK_FILENAME_SZ_MAX 30

/**
* \addtogroup maug_retrosnd_flags RetroSound State Flags
* \brief Flags indicating global state for the RETROSND_STATE::flags field.
* \{
*/

/**
* \brief Flag in RETROSND_STATE::flags indicating initialization was
* successful.
*/
#define RETROSND_FLAG_INIT 0x01

/*! \} */ /* maug_retrosnd_flags */

#define RETROSND_VOICE_BREATH 122

#define RETROSND_VOICE_SEASHORE 123

#define RETROSND_VOICE_BIRD_TWEET 124

#define RETROSND_VOICE_PHONE_RING 125

#define RETROSND_VOICE_HELICOPTER 126

#define RETROSND_VOICE_APPLAUSE 127

#define RETROSND_PC_BIOS_SPKR 0x01
#define RETROSND_PC_BIOS_MPU 0x02
#define RETROSND_PC_BIOS_GUS 0x04
#define RETROSND_PC_BIOS_ADLIB 0x08

/**
* \brief Parameter for retrosnd_midi_set_voice() indicating a gunshot
* sound effect.
*/
#define RETROSND_VOICE_GUNSHOT 128

/**
* \brief Initialize retrosnd engine.
* \param args A pointer to the RETROSND_ARGS struct initialized by
* the calling program.
*
* The RETROSND_ARGS::snd_io_base field must be initialized with the address
* or other platform-specific indicator of the MIDI device to use.
*/
MERROR_RETVAL retrosnd_init( struct RETROFLAT_ARGS* args );

/**
* \brief Set the name of the voice bank filename to use.
*/
void retrosnd_set_sf_bank( const char* filename_in );

void retrosnd_midi_set_voice( uint8_t channel, uint8_t voice );

void retrosnd_midi_set_control( uint8_t channel, uint8_t key, uint8_t val );

void retrosnd_midi_note_on( uint8_t channel, uint8_t pitch, uint8_t vel );

void retrosnd_midi_note_off( uint8_t channel, uint8_t pitch, uint8_t vel );

MERROR_RETVAL retrosnd_midi_play_smf( const char* filename );

uint8_t retrosnd_midi_is_playing_smf();

void retrosnd_shutdown();

/*! \} */ /* maug_retrosnd */

#ifdef RETROFLT_C

MAUG_CONST int16_t SEG_MCONST gc_retroflat_offsets8_x[8] =
Expand Down Expand Up @@ -2404,7 +2405,6 @@ void retroflat_shutdown( int retval ) {
maug_mfree( g_retroflat_state->viewport.refresh_grid_h );
}


# if defined( RETROFLAT_VDP )
if( NULL != g_retroflat_state->vdp_exe ) {
retroflat_vdp_call( "retroflat_vdp_shutdown" );
Expand Down

0 comments on commit 833837a

Please sign in to comment.