Updated Game_Music_Emu with changes that don't currently affect playback.

CQTexperiment
Chris Moeller 2016-03-17 17:15:45 -07:00
parent 87ea9f3428
commit f10fa14668
11 changed files with 1394 additions and 11 deletions

View File

@ -28,6 +28,7 @@ Vgm_Core::Vgm_Core()
Vgm_Core::~Vgm_Core()
{
StopVGM(vgmp);
CloseVGMFile(vgmp);
VGMPlay_Deinit(vgmp);
}
@ -160,10 +161,47 @@ blargg_err_t Vgm_Core::load_mem_( byte const data [], int size )
vgmp->VGMMaxLoop = 1;
set_tempo( 1 );
return blargg_ok;
}
int Vgm_Core::get_channel_count()
{
// XXX may support more than this, but 32 bit masks and all...
unsigned i;
UINT32 j;
for (i = 0; i < 32; i++)
{
if (!GetAccurateChipNameByChannel(vgmp, i, &j))
break;
}
return i;
}
char* Vgm_Core::get_voice_name(int channel)
{
UINT32 realChannel;
const char * name = GetAccurateChipNameByChannel(vgmp, channel, &realChannel);
size_t length = strlen(name) + 16;
char * finalName = (char *) malloc(length);
if (finalName)
sprintf(finalName, "%s #%u", name, realChannel);
return finalName;
}
void Vgm_Core::free_voice_name(char *name)
{
free(name);
}
void Vgm_Core::set_mute(int mask)
{
for (int i = 0; i < 32; i++)
{
SetChannelMute(vgmp, i, (mask >> i) & 1);
}
}
void Vgm_Core::start_track()
{
PlayVGM(vgmp);
@ -184,4 +222,4 @@ int Vgm_Core::play_( int sample_count, short out [] )
void Vgm_Core::skip_( int count )
{
SeekVGM( vgmp, true, count / 2 );
}
}

View File

@ -38,6 +38,13 @@ public:
// Skips the specified number of samples
void skip_( int count );
int get_channel_count();
char* get_voice_name(int channel);
void free_voice_name(char *);
void set_mute(int mask);
// Implementation
public:

View File

@ -31,7 +31,21 @@ Vgm_Emu::Vgm_Emu()
set_silence_lookahead( 1 ); // tracks should already be trimmed
}
Vgm_Emu::~Vgm_Emu() { }
Vgm_Emu::~Vgm_Emu()
{
// XXX ugly use of deprecated functions to free allocated voice names
const char ** voice_names_ = voice_names();
if (voice_names_)
{
for (int i = 0; i < 32; ++i)
{
if (voice_names_[i])
core.free_voice_name((char*)voice_names_[i]);
else break;
}
free((void *)voice_names_);
}
}
void Vgm_Emu::unload()
{
@ -431,6 +445,7 @@ blargg_err_t Vgm_Emu::set_sample_rate_( int sample_rate )
void Vgm_Emu::mute_voices_( int mask )
{
muted_voices = mask;
core.set_mute(mask);
}
// Emulation
@ -474,6 +489,33 @@ blargg_err_t Vgm_Emu::hash_( Hash_Function& out ) const
blargg_err_t Vgm_Emu::load_mem_( const byte* in, int file_size )
{
RETURN_ERR( core.load_mem(in, file_size) );
int voice_count = core.get_channel_count();
set_voice_count( voice_count );
char ** voice_names = (char **) calloc( sizeof(char *), voice_count + 1 );
if (voice_names)
{
int i;
for (i = 0; i < voice_count; i++)
{
voice_names[i] = core.get_voice_name(i);
if (!voice_names[i])
break;
}
if (i == voice_count)
set_voice_names(voice_names);
else
{
for (i = 0; i < voice_count; i++)
{
if (voice_names[i])
free(voice_names[i]);
}
free(voice_names);
}
}
get_vgm_length( header(), &metadata );

File diff suppressed because it is too large Load Diff

View File

@ -49,6 +49,10 @@ UINT32 CalcSampleMSecExt(void* vgmp, UINT64 Value, UINT8 Mode, VGM_HEADER* FileH
const char* GetChipName(UINT8 ChipID);
const char* GetAccurateChipName(UINT8 ChipID, UINT8 SubType);
UINT32 GetChipClock(void* vgmp, UINT8 ChipID, UINT8* RetSubType);
const char* GetAccurateChipNameByChannel(void* vgmp, UINT32 channel, UINT32 *realChannel);
void SetChannelMute(void* vgmp, UINT32 channel, UINT8 mute);
#ifndef NO_WCHAR_FILENAMES
UINT32 GetGZFileLengthW(const wchar_t* FileName);

View File

@ -72,6 +72,8 @@ struct _okim6258_state
UINT8 Iternal10Bit;
UINT8 DCRemoval;
UINT8 mute;
};
/* step size index shift table */
@ -171,6 +173,7 @@ void okim6258_update(void *param, stream_sample_t **outputs, int samples)
//stream_sample_t *buffer = outputs[0];
stream_sample_t *bufL = outputs[0];
stream_sample_t *bufR = outputs[1];
int mute = chip->mute;
//memset(outputs[0], 0, samples * sizeof(*outputs[0]));
@ -231,8 +234,16 @@ void okim6258_update(void *param, stream_sample_t **outputs, int samples)
nibble_shift ^= 4;
//*buffer++ = sample;
*bufL++ = (chip->pan & 0x02) ? 0x00 : sample;
*bufR++ = (chip->pan & 0x01) ? 0x00 : sample;
if (mute)
{
*bufL++ = 0;
*bufR++ = 0;
}
else
{
*bufL++ = (chip->pan & 0x02) ? 0x00 : sample;
*bufR++ = (chip->pan & 0x01) ? 0x00 : sample;
}
samples--;
}
@ -252,6 +263,12 @@ void okim6258_update(void *param, stream_sample_t **outputs, int samples)
}
void okim6258_mute(void *ptr, int mute)
{
okim6258_state *chip = (okim6258_state *)ptr;
chip->mute = mute;
}
/**********************************************************************************************

View File

@ -36,6 +36,8 @@ void okim6258_set_divider(void *chip, int val);
void okim6258_set_clock(void *chip, int val);
int okim6258_get_vclk(void *chip);
void okim6258_mute(void *chip, int mute);
//READ8_DEVICE_HANDLER( okim6258_status_r );
//WRITE8_DEVICE_HANDLER( okim6258_data_w );
//WRITE8_DEVICE_HANDLER( okim6258_ctrl_w );

View File

@ -87,6 +87,8 @@ typedef struct _pwm_chip
#endif
int clock;
unsigned char Mute;
} pwm_chip;
#if CHILLY_WILLY_SCALE
// TODO: Fix Chilly Willy's new scaling algorithm.
@ -327,6 +329,9 @@ void PWM_Update(pwm_chip* chip, int **buf, int length)
tmpOutL = PWM_Update_Scale(chip, (int)chip->PWM_Out_L);
tmpOutR = PWM_Update_Scale(chip, (int)chip->PWM_Out_R);
tmpOutL = chip->Mute ? 0 : tmpOutL;
tmpOutR = chip->Mute ? 0 : tmpOutR;
for (i = 0; i < length; i ++)
{
buf[0][i] = tmpOutL;
@ -342,6 +347,12 @@ void pwm_update(void *_info, stream_sample_t **outputs, int samples)
PWM_Update(chip, outputs, samples);
}
void pwm_mute(void *_info, UINT8 Mute)
{
pwm_chip *chip = (pwm_chip *)_info;
chip->Mute = Mute;
}
int device_start_pwm(void **_info, int clock, int CHIP_SAMPLING_MODE, int CHIP_SAMPLE_RATE)
{
/* allocate memory for the chip */

View File

@ -58,4 +58,6 @@ int device_start_pwm(void **chip, int clock, int CHIP_SAMPLING_MODE, int CHIP_SA
void device_stop_pwm(void *chip);
void device_reset_pwm(void *chip);
void pwm_mute(void *chip, UINT8 Mute);
void pwm_chn_w(void *chip, UINT8 Channel, UINT16 data);

View File

@ -204,6 +204,8 @@ struct _upd7759_state
UINT8 data_buf[0x40];
UINT8 dbuf_pos_read;
UINT8 dbuf_pos_write;
UINT8 mute;
};
@ -511,14 +513,23 @@ void upd7759_update(void *param, stream_sample_t **outputs, int samples)
UINT32 pos = chip->pos;
stream_sample_t *buffer = outputs[0];
stream_sample_t *buffer2 = outputs[1];
int mute = chip->mute;
/* loop until done */
if (chip->state != STATE_IDLE)
while (samples != 0)
{
/* store the current sample */
*buffer++ = sample << 7;
*buffer2++ = sample << 7;
if (mute)
{
*buffer++ = 0;
*buffer2++ = 0;
}
else
{
*buffer++ = sample << 7;
*buffer2++ = sample << 7;
}
samples--;
/* advance by the number of clocks/output sample */
@ -586,6 +597,11 @@ void upd7759_update(void *param, stream_sample_t **outputs, int samples)
chip->pos = pos;
}
void upd7759_mute(void *ptr, int mute)
{
upd7759_state *chip = (upd7759_state *)ptr;
chip->mute = mute;
}
/************************************************************

View File

@ -21,6 +21,8 @@ void device_reset_upd7759(void *chip);
int device_start_upd7759(void **chip, int clock);
void device_stop_upd7759(void *chip);
void upd7759_mute(void *chip, int mute);
//void upd7759_set_bank_base(running_device *device, offs_t base);
//void upd7759_reset_w(running_device *device, UINT8 data);