📄 sasound.c
字号:
/******************************************************************************//* *//* SAMPLE SUPPORT FOR RAINE *//* *//* modified by Hiromitsu Shioya *//* Allegro support : Emmanuel Anne. *//* *//******************************************************************************/#include <time.h>#include "raine.h"#include "sasound.h"#include "games.h"#include "debug.h"#define UINT unsigned int#define DWORD int/* Avoid to uncomment USE_8BITS unless you finish 8bit support... which is pretty useless nowdays ! *///#define USE_8BITS 1// uncomment USE_MODE if you want to choose streaming mode.// I advice against it since mode 0 is old and does not work well !!!//#define USE_MODE 1#ifdef USE_MODE//int sound_stream_mode = SOUND_STREAM_NORMAL; // SOUND_STREAM_WAIT;int sound_stream_mode = SOUND_STREAM_WAIT;#endif/*dump channels (debug)*///#define DUMP_CHANNELS#ifdef DUMP_CHANNELSFILE *stream_out[NUMVOICES];#endif// fine MAME_SOUND/* * Volume Section */#define VOLUME_MIN (0) // Minimum volume#define VOLUME_MAX (255) // Maximum volume/* * Panning Section */#define PAN_LEFT (0) // Left panning#define PAN_CENTRE (128) // Central panning#define PAN_RIGHT (255) // Right panning/* * Sample Control Section */#define CPU_FPS (60) // Frames per second of emulated hardware/* * Other stuff */#define UPDATE_60_FPS // Turn off the counting stuff. Emulation // speed stays more constant this way.UINT8 No_FM; // fm.c controlstatic int samp_modeb_timer;SoundRec *SndMachine = NULL, snd_entry;/* audio related stuff */static SAMPLE *lpWave[NUMVOICES];static int hVoice[NUMVOICES];// The "normal" version of PlayStream does not use samples nor voicexs.// It just uses "streams" ! What a mess !static int playing[NUMVOICES];static int ventry[NUMVOICES];static int vbover_err, vbunder_err;static UINT16 *vout[NUMVOICES],*vend[NUMVOICES];int SampleRate;int audio_sample_rate;int sound_emu_count;static int reserved_channel = 0;static int stream_buffer_max;static int pause_sound;void saCheckPlayStream( void );/*******************************************************************************************//**** osd_??? functions ****//*******************************************************************************************/int get_play_channels( int request ){ return saGetPlayChannels( request );}void reset_play_channels(void){ saResetPlayChannels();}#ifdef USE_8BITSvoid osd_play_streamed_sample(int channel,signed char *data,int len,int freq,int volume, int pan){ fprintf(stderr,"Play 8 bits\n");#if USE_MODE if( !sound_stream_mode ) saPlayStreamedSampleBase( channel, (signed char *)data, len, freq, volume, 8, pan ); else#endif saPlayBufferedStreamedSampleBase( channel, (signed char *)data, len, freq, volume, 8, pan );}#endifvoid osd_play_streamed_sample_16(int channel,signed short *data,int len,int freq,int volume, int pan){#if USE_MODE if( !sound_stream_mode ) saPlayStreamedSampleBase( channel, (signed char *)data, len, freq, volume, 16, pan ); else#endif saPlayBufferedStreamedSampleBase( channel, (signed char *)data, len, freq, volume, 16, pan );}void osd_ym2203_update(void){}/*******************************************************************************************//* streams v35x *//*******************************************************************************************/#include "streams.c"/*******************************************************************************************//* sa???Sound *//*******************************************************************************************//******************************************//* update sound *//******************************************/void saUpdateSound( int nowclock ){ if( ! GameSound ) return; if( ! RaineSoundCard ) return; if( ! audio_sample_rate ) return; if( ! SndMachine ) return; if( nowclock ){ //int i; // This part is called for each frame, which *should* be 60 // times/sec, but it can be less (if the game slows down) streams_sh_update(); } else{ // This part is called by profile.c, normally exactly 60 times / sec.#if USE_MODE if( sound_stream_mode ) saCheckPlayStream();#endif }}struct SOUND_CHIP sound_chip_list[] ={#if HAS_YM2203 { "ym2203", YM2203_sh_stop, },#endif#if HAS_YM2151 { "ym2151", YM2151_sh_stop, }, { "ym2151", YM2151_sh_stop, },#endif#if HAS_YM2610 { "ym2610", YM2610_sh_stop, },#endif#if HAS_YM2610B { "ym2610b", YM2610_sh_stop, },#endif#if HAS_MSM5205 { "msm5205", MSM5205buffer_sh_stop, },#endif#if HAS_ADPCM { "m6295", OKIM6295_sh_stop, },#endif#if HAS_AY8910 { "ay9810", NULL, },#endif#if HAS_YM3812 { "ym3812", YM3812_sh_stop, },#endif { "sn76496", NULL, }, { "ym2413", NULL, },#if HAS_SMP16 { "smp16bit", SMP16buffer_sh_stop, },#endif#if HAS_M6585 { "m6585", M6585buffer_sh_stop, },#endif#if HAS_YMZ280B { "ymz280b", YMZ280B_sh_stop, },#endif#if HAS_ES5505 { "es5505", ES5505_sh_stop, }, { "es5506", ES5506_sh_stop, },#endif#if HAS_QSOUND { "qsound", qsound_sh_stop, },#endif { NULL, NULL, },};char *get_sound_chip_name(UINT32 id){ return sound_chip_list[id].name;}int init_sound_emulators(void){ int i,j; if(change_sample_rate) saStopSoundEmulators(); change_sample_rate = 0; if( SndMachine ){ if( !SndMachine->first ){ saInitVolPan(); /* moved. (hiro-shi) */ SndMachine->first = 1; /* first flag clear */ streams_sh_start(); /* streaming system initialize & start */ pause_sound = 0; /* pause flag off */ vbover_err = vbunder_err = 0; /* error initial */ No_FM = 1; /* FM DAC mode */ for( j = 0; j < SndMachine->control_max; j++ ){ switch( SndMachine->init[j] ){#if HAS_YM2203 case SOUND_YM2203: i = YM2203_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_YM2151 case SOUND_YM2151S: i = YM2151_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_YM2151_ALT case SOUND_YM2151J: i = YM2151_ALT_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_YM2610 case SOUND_YM2610: i = YM2610_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_YM2610B case SOUND_YM2610B: i = YM2610B_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_MSM5205 case SOUND_MSM5205: i = MSM5205buffer_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_ADPCM case SOUND_M6295: i = OKIM6295_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_AY8910 case SOUND_PSG: i = AY8910_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_YM3812 case SOUND_YM3812: i = YM3812_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_SMP16 case SOUND_SMP16: i = SMP16buffer_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_M6585 case SOUND_M6585: i = M6585buffer_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_YMZ280B case SOUND_YMZ280B: i = YMZ280B_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_ES5505 case SOUND_ES5505: i = ES5505_sh_start( SndMachine->intf[j] ); break; case SOUND_ES5506: i = ES5506_sh_start( SndMachine->intf[j] ); break;#endif#if HAS_QSOUND case SOUND_QSOUND: i = qsound_sh_start( SndMachine->intf[j] ); break;#endif default: i = 1; break; } if( i ){ audio_sample_rate = 0; SndMachine = NULL; return 1; } } } } return 0;}int sound_card_id( int i );/******************************************//* setup sound *//******************************************/BOOL saInitSoundCard( int soundcard, int buffer_mode, int sample_rate ){ int i,id; //char s[40]; /* install a digital sound driver */ // if (!soundcard) { // id = 0; // Normally, soundcard =0 means no sound in raine. // I will try not to break this to keep compatibility with the other // sources... // } else { id = sound_card_id(soundcard); // } #ifdef RAINE_DOS set_volume_per_voice(0);#endif if (install_sound(id, MIDI_NONE, NULL) != 0) { //set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error initialising sound system\n%s\n", allegro_error); RaineSoundCard = 0; return 0; }#ifdef RAINE_DOS set_volume(255,255);#endif streams_init_timers(); for( i = 0; i < NUMVOICES; i++ ){ lpWave[i] = 0; playing[i] = 0; voice_stop(hVoice[i]);#ifdef DUMP_CHANNELS sprintf(s,"stream%02d.raw",i); stream_out[i] = fopen(s,"wb");#endif } // sound_stream_mode = buffer_mode;#if USE_MODE if( !sound_stream_mode ) stream_buffer_max = STREAM_BUFFER_MAXA; else#endif stream_buffer_max = STREAM_BUFFER_MAXB; samp_modeb_timer = 0; //reserved_channel = 0; if(!init_sound_emulators()) { return FALSE; // Everything fine } return TRUE;}/*********************************************************************//* stop sound emulators: this is needed for when sample rate changes *//*********************************************************************/void saStopSoundEmulators(void){ int i;#ifdef RAINE_DEBUG print_debug("saStopSoundEmulators(): Removing Sound Emulators\n");#endif saResetPlayChannels(); if( SndMachine == NULL ){ SndMachine = &snd_entry; } else{ if(SndMachine->first!=0){ // YM3812 fix crashes streams_sh_stop(); for( i = 0; i < SndMachine->control_max; i++ ){ if( sound_chip_list[SndMachine->init[i]].shutdown ) sound_chip_list[SndMachine->init[i]].shutdown(); } SndMachine->first = 0; } }#ifdef RAINE_DEBUG print_debug("saStopSoundEmulators(): OK\n");#endif}/******************************************//* setup sound *//******************************************/void init_sound_list(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -