X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpcm.cpp;h=846dfc94ff84893c2a7f4ba67250f696bb0e3550;hb=79c9a3cd4285f26c07260fb4c6484549a366a496;hp=596d8465aaa1b63e603704d911d587ef5ae7a0aa;hpb=86bd0f2592c3cd674239532247276bd2d579a857;p=virtualjaguar diff --git a/src/pcm.cpp b/src/pcm.cpp index 596d846..846dfc9 100644 --- a/src/pcm.cpp +++ b/src/pcm.cpp @@ -1,6 +1,14 @@ -#include "include/pcm.h" +// +// PCM Handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + +#include "pcm.h" -#define PCM_DUMP +//#define PCM_DUMP #define sample_rate 44100 #define sample_bits 16 @@ -13,45 +21,29 @@ static uint32 pcm_left_pos; static uint32 pcm_right_pos; static uint32 pcm_left_playback_pos; static uint32 pcm_right_playback_pos; -static FILE * fp_left; -static FILE * fp_right; static uint32 pcm_sample_rate = sample_rate; static uint32 pcm_inc = (pcm_sample_rate << 8) / sample_rate; +#ifdef PCM_DUMP +static FILE * fp_left; +static FILE * fp_right; +#endif + -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void pcm_set_sample_rate(int rate) { pcm_sample_rate = rate; pcm_inc = (pcm_sample_rate << 8) / sample_rate; // fprintf(log_get(),"pcm: sample rate is %i hz, sample increment is %i (%f)\n",pcm_sample_rate,pcm_inc,((float)pcm_inc)/256.0f); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void pcm_updateOne(int channel, int16 *data, uint32 length) + +void pcm_updateOne(int channel, int16 * data, uint32 length) { - if (channel==0) + if (channel == 0) { while (length) { - *data++=pcm_left[(pcm_left_playback_pos>>8)%buffer_modulo]; - pcm_left_playback_pos+=pcm_inc; + *data++ = pcm_left[(pcm_left_playback_pos >> 8) % buffer_modulo]; + pcm_left_playback_pos += pcm_inc; length--; } } @@ -59,177 +51,91 @@ void pcm_updateOne(int channel, int16 *data, uint32 length) { while (length) { - *data++=pcm_right[(pcm_right_playback_pos>>8)%buffer_modulo]; - pcm_right_playback_pos+=pcm_inc; + *data++ = pcm_right[(pcm_right_playback_pos >> 8) % buffer_modulo]; + pcm_right_playback_pos += pcm_inc; length--; } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_init(void) { - memory_malloc_secure((void**)&pcm_left,buffer_modulo*sizeof(int16),"Left dac buffer"); - memory_malloc_secure((void**)&pcm_right,buffer_modulo*sizeof(int16),"Right dac buffer"); + memory_malloc_secure((void **)&pcm_left, buffer_modulo * sizeof(int16), "Left DAC buffer"); + memory_malloc_secure((void **)&pcm_right, buffer_modulo * sizeof(int16), "Right DAC buffer"); pcm_reset(); - fp_left=fopen("leftdac.raw","wb"); - fp_right=fopen("rightdac.raw","wb"); - +#ifdef PCM_DUMP + fp_left = fopen("leftdac.raw", "wb"); + fp_right = fopen("rightdac.raw", "wb"); +#endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_reset(void) { - pcm_left_pos=0; - pcm_right_pos=0; - pcm_left_playback_pos=0; - pcm_right_playback_pos=0; + pcm_left_pos = 0; + pcm_right_pos = 0; + pcm_left_playback_pos = 0; + pcm_right_playback_pos = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_done(void) { +#ifdef PCM_DUMP fclose(fp_left); fclose(fp_right); +#endif + fprintf(log_get(), "PCM: Done.\n"); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_update(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_render_left_dac(void) { #ifdef PCM_DUMP - fwrite(pcm_left,1,sample_rate*2,fp_left); + fwrite(pcm_left, 1, sample_rate * 2, fp_left); #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_render_right_dac(void) { #ifdef PCM_DUMP - fwrite(pcm_right,1,sample_rate*2,fp_right); + fwrite(pcm_right, 1, sample_rate * 2, fp_right); #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_byte_write(uint32 offset, uint8 data) { // fprintf(log_get(),"pcm: writing 0x%.2x at 0x%.8x\n",data,offset); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_word_write(uint32 offset, uint16 data) { - if (offset==2) + if (offset == 2) { - pcm_left[pcm_left_pos%buffer_modulo]=data; + pcm_left[pcm_left_pos % buffer_modulo] = data; pcm_left_pos++; - if ((pcm_left_pos%buffer_modulo)==0) + if ((pcm_left_pos % buffer_modulo) == 0) pcm_render_left_dac(); } else - if (offset==6) + if (offset == 6) { - pcm_right[pcm_right_pos%buffer_modulo]=data; + pcm_right[pcm_right_pos % buffer_modulo] = data; pcm_right_pos++; - if ((pcm_right_pos%buffer_modulo)==0) + if ((pcm_right_pos % buffer_modulo) == 0) pcm_render_right_dac(); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 pcm_byte_read(uint32 offset) { // fprintf(log_get(),"pcm: reading byte from 0x%.8x\n",offset); - return(0xff); + return 0xFF; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 pcm_word_read(uint32 offset) { // fprintf(log_get(),"pcm: reading word from 0x%.8x\n",offset); - return(0xffff); + return 0xFFFF; }