- uint32 jerry_i2s_int_freq = (26591000 / 64) / (jerry_i2s_interrupt_divide + 1);
- jerry_i2s_interrupt_cycles_per_scanline = 13300000 / jerry_i2s_int_freq;
- jerry_i2s_interrupt_timer = jerry_i2s_interrupt_cycles_per_scanline;
- //WriteLog("jerry: i2s interrupt rate set to %i hz (every %i cpu clock cycles) jerry_i2s_interrupt_divide=%i\n",jerry_i2s_int_freq,jerry_i2s_interrupt_cycles_per_scanline,jerry_i2s_interrupt_divide);
- pcm_set_sample_rate(jerry_i2s_int_freq);
+
+ // Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP???
+//Yes, it should. !!! FIX !!!
+ jerry_i2s_interrupt_divide &= 0xFF;
+
+ if (jerry_i2s_interrupt_timer == -1)
+ {
+ // We don't have to divide the RISC clock rate by this--the reason is a bit
+ // convoluted. Will put explanation here later...
+// What's needed here is to find the ratio of the frequency to the number of clock cycles
+// in one second. For example, if the sample rate is 44100, we divide the clock rate by
+// this: 26590906 / 44100 = 602 cycles.
+// Which means, every 602 cycles that go by we have to generate an interrupt.
+ jerryI2SCycles = 32 * (2 * (jerry_i2s_interrupt_divide + 1));
+ }
+
+ jerry_i2s_interrupt_timer -= cycles;
+ if (jerry_i2s_interrupt_timer <= 0)
+ {
+//This is probably wrong as well (i.e., need to check enable lines)... !!! FIX !!!
+ DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE);
+ jerry_i2s_interrupt_timer += jerryI2SCycles;
+#ifdef JERRY_DEBUG
+ if (jerry_i2s_interrupt_timer < 0)
+ WriteLog("JERRY: Missed generating an interrupt (missed %u)!\n", (-jerry_i2s_interrupt_timer / jerryI2SCycles) + 1);
+#endif
+ }