5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups by James L. Hammons
13 #define sample_rate 44100
14 #define sample_bits 16
16 #define buffer_modulo (sample_rate * buffer_size)
18 static int16 * pcm_left;
19 static int16 * pcm_right;
20 static uint32 pcm_left_pos;
21 static uint32 pcm_right_pos;
22 static uint32 pcm_left_playback_pos;
23 static uint32 pcm_right_playback_pos;
24 static uint32 pcm_sample_rate = sample_rate;
25 static uint32 pcm_inc = (pcm_sample_rate << 8) / sample_rate;
27 static FILE * fp_left;
28 static FILE * fp_right;
32 void pcm_set_sample_rate(int rate)
34 pcm_sample_rate = rate;
35 pcm_inc = (pcm_sample_rate << 8) / sample_rate;
36 // 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);
39 void pcm_updateOne(int channel, int16 * data, uint32 length)
45 *data++ = pcm_left[(pcm_left_playback_pos >> 8) % buffer_modulo];
46 pcm_left_playback_pos += pcm_inc;
54 *data++ = pcm_right[(pcm_right_playback_pos >> 8) % buffer_modulo];
55 pcm_right_playback_pos += pcm_inc;
63 memory_malloc_secure((void **)&pcm_left, buffer_modulo * sizeof(int16), "Left DAC buffer");
64 memory_malloc_secure((void **)&pcm_right, buffer_modulo * sizeof(int16), "Right DAC buffer");
67 fp_left = fopen("leftdac.raw", "wb");
68 fp_right = fopen("rightdac.raw", "wb");
76 pcm_left_playback_pos = 0;
77 pcm_right_playback_pos = 0;
86 fprintf(log_get(), "PCM: Done.\n");
93 void pcm_render_left_dac(void)
96 fwrite(pcm_left, 1, sample_rate * 2, fp_left);
100 void pcm_render_right_dac(void)
103 fwrite(pcm_right, 1, sample_rate * 2, fp_right);
107 void pcm_byte_write(uint32 offset, uint8 data)
109 // fprintf(log_get(),"pcm: writing 0x%.2x at 0x%.8x\n",data,offset);
112 void pcm_word_write(uint32 offset, uint16 data)
116 pcm_left[pcm_left_pos % buffer_modulo] = data;
118 if ((pcm_left_pos % buffer_modulo) == 0)
119 pcm_render_left_dac();
124 pcm_right[pcm_right_pos % buffer_modulo] = data;
126 if ((pcm_right_pos % buffer_modulo) == 0)
127 pcm_render_right_dac();
131 uint8 pcm_byte_read(uint32 offset)
133 // fprintf(log_get(),"pcm: reading byte from 0x%.8x\n",offset);
137 uint16 pcm_word_read(uint32 offset)
139 // fprintf(log_get(),"pcm: reading word from 0x%.8x\n",offset);