--- uae/src/od-dos/sound/sound.c 2018/04/24 16:40:30 1.1.1.1 +++ uae/src/od-dos/sound/sound.c 2018/04/24 16:59:05 1.1.1.3 @@ -3,9 +3,11 @@ * * Support for DOS * - * Copyright 1997 Gustavo Goedert + * Copyright 1997, 1998 Gustavo Goedert */ +/****** This file is broken. The sample handlers have to go. ******/ + #include "sysconfig.h" #include "sysdeps.h" @@ -23,7 +25,12 @@ #include #include "sound/sb.h" -#include "sound/gus.h" + +typedef uae_s8 sample8_t; +#define DO_CHANNEL_1(v, c) do { (v) *= audio_channel[c].vol; } while (0) +#define SBASEVAL8(logn) ((logn) == 1 ? SOUND8_BASE_VAL << 7 : SOUND8_BASE_VAL << 8) +#define SBASEVAL16(logn) ((logn) == 1 ? SOUND16_BASE_VAL >> 1 : SOUND16_BASE_VAL) +#define FINISH_DATA(b,logn) do { if (14 - (b) + (logn) > 0) data >>= 14 - (b) + (logn); else data <<= (b) - 14 - (logn); } while (0); uae_u16 sndbuffer[44100]; uae_u16 *sndbufpt; @@ -33,8 +40,8 @@ int dspbits; int sound_curfreq; -void (*SND_Write)(void *buf, unsigned long size); // Pointer to function that plays data on card -void (*SND_DirectWrite)(unsigned int size, int freq); // New function that plays data directly +void (*SND_DirectWrite)(unsigned int size, int freq); // Pointer to function that plays data on card +#define SND_DirectWrite SB_DirectWrite volatile int IsPlaying = 0; int CurrentBuffer = 0; unsigned int direct_buffers[2], direct_sndbufpt; @@ -43,11 +50,8 @@ void direct_mono_sample16_handler(void); void direct_mono_sample8_handler(void); void direct_stereo_sample16_handler(void); void direct_stereo_sample8_handler(void); -void normal_sample16_handler(void); -void normal_sample8_handler(void); void interpol_freq(int new_freq); void direct_check_sound_buffers(void); -void normal_check_sound_buffers(void); #define INTERPOL_SIZE 8 int freq_buf[INTERPOL_SIZE]; @@ -102,167 +106,136 @@ inline void direct_check_sound_buffers(v } } -inline void normal_check_sound_buffers(void) { - if ((char *)sndbufpt - (char *)sndbuffer >= sndbufsize) { - SND_Write(sndbuffer, sndbufsize); - sndbufpt = sndbuffer; - } -} - -/* Gustavo et al.: *please* don't duplicate code like this, but use the functions - * in audio.c */ void direct_mono_sample16_handler(void) { - int nr, adk; - uae_u32 data = SOUND16_BASE_VAL; + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + data0 &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + data0 += data1; + data0 += data2; + data0 += data3; + { + uae_u32 data = SBASEVAL16(2) + data0; + FINISH_DATA(16, 2); + _farnspokew(direct_sndbufpt, data); + direct_sndbufpt += 2; + } + + direct_check_sound_buffers(); eventtab[ev_sample].evtime = cycles + sample_evtime; eventtab[ev_sample].oldcycles = cycles; - - adk = adkcon; - - if (!(adk & 0x11)) - data += sound_table[audio_channel[0].current_sample][audio_channel[0].vol]; - if (!(adk & 0x22)) - data += sound_table[audio_channel[1].current_sample][audio_channel[1].vol]; - if (!(adk & 0x44)) - data += sound_table[audio_channel[2].current_sample][audio_channel[2].vol]; - if (!(adk & 0x88)) - data += sound_table[audio_channel[3].current_sample][audio_channel[3].vol]; - - _farnspokew(direct_sndbufpt, data); - direct_sndbufpt += 2; - direct_check_sound_buffers(); } void direct_mono_sample8_handler(void) { - int nr, adk, played_size; - uae_u32 data = SOUND8_BASE_VAL; - - eventtab[ev_sample].evtime = cycles + sample_evtime; - eventtab[ev_sample].oldcycles = cycles; - - adk = adkcon; - - if (!(adk & 0x11)) - data += sound_table[audio_channel[0].current_sample][audio_channel[0].vol]; - if (!(adk & 0x22)) - data += sound_table[audio_channel[1].current_sample][audio_channel[1].vol]; - if (!(adk & 0x44)) - data += sound_table[audio_channel[2].current_sample][audio_channel[2].vol]; - if (!(adk & 0x88)) - data += sound_table[audio_channel[3].current_sample][audio_channel[3].vol]; + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + data0 &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + data0 += data1; + data0 += data2; + data0 += data3; + { + uae_u32 data = SBASEVAL8(2) + data0; + FINISH_DATA(8, 2); + _farnspokeb(direct_sndbufpt++, data); + } - _farnspokeb(direct_sndbufpt++, data); direct_check_sound_buffers(); -} - -void direct_stereo_sample16_handler(void) -{ - int nr, adk; - uae_u32 ldata = SOUND16_BASE_VAL, rdata = SOUND16_BASE_VAL; eventtab[ev_sample].evtime = cycles + sample_evtime; eventtab[ev_sample].oldcycles = cycles; - - adk = adkcon; - - if (!(adk & 0x11)) - ldata += sound_table[audio_channel[0].current_sample][audio_channel[0].vol]; - if (!(adk & 0x22)) - rdata += sound_table[audio_channel[1].current_sample][audio_channel[1].vol]; - if (!(adk & 0x44)) - rdata += sound_table[audio_channel[2].current_sample][audio_channel[2].vol]; - if (!(adk & 0x88)) - ldata += sound_table[audio_channel[3].current_sample][audio_channel[3].vol]; - - _farnspokew(direct_sndbufpt, ldata); - direct_sndbufpt += 2; - _farnspokew(direct_sndbufpt, rdata); - direct_sndbufpt += 2; - direct_check_sound_buffers(); } -void direct_stereo_sample8_handler(void) +void direct_stereo_sample16_handler(void) { - int nr, adk, played_size; - uae_u32 ldata = SOUND8_BASE_VAL, rdata = SOUND8_BASE_VAL; - - eventtab[ev_sample].evtime = cycles + sample_evtime; - eventtab[ev_sample].oldcycles = cycles; - - adk = adkcon; + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + + data0 &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + + data0 += data3; + { + uae_u32 data = SBASEVAL16(1) + data0; + FINISH_DATA (16, 1); + _farnspokew(direct_sndbufpt, data); + direct_sndbufpt += 2; + } - if (!(adk & 0x11)) - ldata += sound_table[audio_channel[0].current_sample][audio_channel[0].vol]; - if (!(adk & 0x22)) - rdata += sound_table[audio_channel[1].current_sample][audio_channel[1].vol]; - if (!(adk & 0x44)) - rdata += sound_table[audio_channel[2].current_sample][audio_channel[2].vol]; - if (!(adk & 0x88)) - ldata += sound_table[audio_channel[3].current_sample][audio_channel[3].vol]; + data1 += data2; + { + uae_u32 data = SBASEVAL16(1) + data1; + FINISH_DATA (16, 1); + _farnspokew(direct_sndbufpt, data); + direct_sndbufpt += 2; + } - _farnspokeb(direct_sndbufpt++, ldata); - _farnspokeb(direct_sndbufpt++, rdata); direct_check_sound_buffers(); -} - - -void normal_sample16_handler(void) -{ - int nr, adk; - uae_u32 data = SOUND16_BASE_VAL; eventtab[ev_sample].evtime = cycles + sample_evtime; eventtab[ev_sample].oldcycles = cycles; - - adk = adkcon; - - if (!(adk & 0x11)) - data += sound_table[audio_channel[0].current_sample][audio_channel[0].vol]; - if (!(adk & 0x22)) - data += sound_table[audio_channel[1].current_sample][audio_channel[1].vol]; - if (!(adk & 0x44)) - data += sound_table[audio_channel[2].current_sample][audio_channel[2].vol]; - if (!(adk & 0x88)) - data += sound_table[audio_channel[3].current_sample][audio_channel[3].vol]; - - *(uae_u16 *)sndbufpt = data; - sndbufpt = (uae_u16 *)(((uae_u8 *)sndbufpt) + 2); - normal_check_sound_buffers(); } -void normal_sample8_handler(void) +void direct_stereo_sample8_handler(void) { - int nr, adk; - uae_u32 data = SOUND8_BASE_VAL; + uae_u32 data0 = audio_channel[0].current_sample; + uae_u32 data1 = audio_channel[1].current_sample; + uae_u32 data2 = audio_channel[2].current_sample; + uae_u32 data3 = audio_channel[3].current_sample; + DO_CHANNEL_1 (data0, 0); + DO_CHANNEL_1 (data1, 1); + DO_CHANNEL_1 (data2, 2); + DO_CHANNEL_1 (data3, 3); + + data0 &= audio_channel[0].adk_mask; + data1 &= audio_channel[1].adk_mask; + data2 &= audio_channel[2].adk_mask; + data3 &= audio_channel[3].adk_mask; + + data0 += data3; + { + uae_u32 data = SBASEVAL8(1) + data0; + FINISH_DATA (8, 1); + _farnspokeb(direct_sndbufpt++, data); + } + data1 += data2; + { + uae_u32 data = SBASEVAL8(1) + data1; + FINISH_DATA (8, 1); + _farnspokeb(direct_sndbufpt++, data); + } + + direct_check_sound_buffers(); eventtab[ev_sample].evtime = cycles + sample_evtime; eventtab[ev_sample].oldcycles = cycles; - - adk = adkcon; - - if (!(adk & 0x11)) - data += sound_table[audio_channel[0].current_sample][audio_channel[0].vol]; - if (!(adk & 0x22)) - data += sound_table[audio_channel[1].current_sample][audio_channel[1].vol]; - if (!(adk & 0x44)) - data += sound_table[audio_channel[2].current_sample][audio_channel[2].vol]; - if (!(adk & 0x88)) - data += sound_table[audio_channel[3].current_sample][audio_channel[3].vol]; - - *(uae_u8 *)sndbufpt = data; - sndbufpt = (uae_u16 *)(((uae_u8 *)sndbufpt) + 1); - normal_check_sound_buffers(); -} - -void close_sound(void) { -} - -int setup_sound(void) { - sound_available = 1; - return 1; } int init_sound (void) @@ -282,8 +255,7 @@ int init_sound (void) rate = currprefs.sound_freq; sndbufsize = currprefs.sound_maxbsiz; - if (GUS_Init(&dspbits, &rate, &sndbufsize, direct_buffers, &currprefs.stereo)); - else if (SB_DetectInitSound(&dspbits, &rate, &sndbufsize, direct_buffers, &currprefs.stereo)); + if (SB_DetectInitSound(&dspbits, &rate, &sndbufsize, direct_buffers, &currprefs.stereo)); else if (0/*OTHER_CARD_DETECT_ROUTINE*/); else return 0; @@ -292,31 +264,21 @@ int init_sound (void) currprefs.sound_minbsiz = (currprefs.sound_minbsiz>>2)<<2; currprefs.sound_maxbsiz = sndbufsize; - if (direct_buffers[0] == 0) - currprefs.sound_minbsiz = currprefs.sound_maxbsiz; - sample_evtime = (long)maxhpos * maxvpos * 50 / rate; if (dspbits == 16) { init_sound_table16 (); - if (direct_buffers[0] != 0) { - if (currprefs.stereo) - eventtab[ev_sample].handler = direct_stereo_sample16_handler; - else - eventtab[ev_sample].handler = direct_mono_sample16_handler; - } else - eventtab[ev_sample].handler = normal_sample16_handler; + if (currprefs.stereo) + eventtab[ev_sample].handler = direct_stereo_sample16_handler; + else + eventtab[ev_sample].handler = direct_mono_sample16_handler; } else { init_sound_table8 (); - if (direct_buffers[0] != 0) { - if (currprefs.stereo) - eventtab[ev_sample].handler = direct_stereo_sample8_handler; - else - eventtab[ev_sample].handler = direct_mono_sample8_handler; - } else - eventtab[ev_sample].handler = normal_sample8_handler; + if (currprefs.stereo) + eventtab[ev_sample].handler = direct_stereo_sample8_handler; + else + eventtab[ev_sample].handler = direct_mono_sample8_handler; } - sound_available = 1; printf ("Sound driver found and configured for %d bits at %d Hz, buffer is %d:%d bytes\n", dspbits, rate, currprefs.sound_minbsiz, currprefs.sound_maxbsiz); sndbufpt = sndbuffer; @@ -327,5 +289,19 @@ int init_sound (void) freq_buf[i] = sound_curfreq; buf_tot = sound_curfreq * INTERPOL_SIZE; +#ifdef FRAME_RATE_HACK + vsynctime = vsynctime * 9 / 10; +#endif + return 1; } + +int setup_sound (void) +{ + sound_available = 1; + return 1; +} + +void close_sound(void) +{ +}