Previous 15994 Revisions Next

r11145 Tuesday 12th April, 2011 at 01:58:50 UTC by Jonathan Gevaryahu
tms5220.c: updates to comments and nonstandard feature
defines. [Lord Nightmare]
[src/emu/sound]tms5220.c

src/emu/sound/tms5220.c
r11144r11145
5959    * If a command is still executing, /READY will be kept high until the command has
6060      finished if the next command is written.
6161    * tomcat has a 5220 which is not hooked up at all
62    * documentation is inconsistent in the patents about what data is returned for chirp rom addresses (base 0) 41 to 51; the patent says the 'rom returns zeroes for locations beyond 40', but at the same time the rom stores the complement of the actual chirp rom value, so are locations beyond 40 = 0x00(0) or = 0xFF(-1)? The patent text and images imply 0x00, but I'm (LN) not completely convinced yet.
6362    * Is the TS=0 forcing energy to 0 for next frame in the interpolator actually correct? I'm (LN) guessing no. The patent schematics state that TS=0 shuts off the output dac completely, though doesn't affect the I/O pin.
6463
6564Pedantic detail from observation of real chip:
r11144r11145
103102  3 = >>3 (/8)
104103  4 = >>2 (/4)
105104  5 = >>2 (/4)
106  6 = >>1 (/2) (NOTE: this value may actually be >>2 (/4), the patent has an error on it and is unclear)
105  6 = >>1 (/2) (NOTE: the patent has an error regarding this value on one table implying it should be /4, but circuit simulation of parts of the patent shows that the /2 value is correct.)
107106  7 = >>1 (/2)
108107  0 = >>0 (/1, forcing current values to equal target values)
109108    Every IP full count, a new frame is parsed, but ONLY on the 0->*
r11144r11145
251250
252251/* *****optional defines***** */
253252
254/* this define controls the interpolation shift logic. one of the following two lines should be used, and the other commented; the second line is more accurate mathematically but less accurate to hardware (Unless I (LN) misunderstand the way the shifter works, which is quite likely) */
253/* Hacky improvements which don't match patent: */
254/* Interpolation shift logic:
255 * One of the following two lines should be used, and the other commented
256 * The second line is more accurate mathematically but not accurate to the patent
257 */
255258#define INTERP_SHIFT >> tms->coeff->interp_coeff[tms->interp_period]
256259//#define INTERP_SHIFT / (1<<tms->coeff->interp_coeff[tms->interp_period])
257260
258/* if undefined, various hacky improvements are used, such as inverting excitation waveform, and increasing the magnitude of unvoiced speech excitation */
259#define NORMALMODE 1
261/* Excitation hacks */
262/* The real chip uses an 8-bit excitation (shifted up to the top 8 bits) for
263   both voiced and unvoiced speech.
264   According to the patent, the voiced speech comes from a 51 entry rom
265   And the unvoiced speech is ~0x3F(i.e. 0xC0) or 0x40 depending on an LFSR */
266/* HACK: if defined, change the unvoiced excitation to use ~0x7F and 0x80
267 * if not defined, acts as shown in patent */
268#undef UNVOICED_HACK
260269
270/* HACKS: VOICED waveform hacks;
271 * if none defined, acts as shown in patent
272 * if VOICED_INV_HACK defined, acts as shown in patent but the output is inverted
273 * if VOICED_ZERO_HACK defined, acts as shown in patent, but the first and >=51 samples are 0x80 (-128)
274 * if VOICED_PULSE_HACK defined, acts as a pulse waveform with a period of PWIDTH samples at PAMP, PWIDTH samples at ~PAMP, and the rest at 0
275 * if VOICED_PULSE_MONOPOLAR_HACK defined, acts as a pulse waveform with a period of PWIDTH samples at PAMP, and the rest at 0
276 * If you want this to sound like MGE, set VOICED_PULSE_MONOPOLAR_HACK to 1, PAMP to 0x3F and PWIDTH to 1
277 */
278#undef VOICED_INV_HACK
279#undef VOICED_ZERO_HACK
280#undef VOICED_PULSE_HACK
281#undef VOICED_PULSE_MONOPOLAR_HACK
282#undef PAMP
283#undef PWIDTH
284
285/* Other hacks */
286/* HACK: if defined, outputs the low 4 bits of the lattice filter to the i/o
287 * or clip logic, even though the real hardware doesn't do this */
288#undef ALLOW_4_LSB
289
290/* HACK: if defined, uses impossibly perfect 'straight line' interpolation */
291// TODO: as of around mame 0.141 this doesn't work right. please fix! - LN, to LN
292#undef PERFECT_INTERPOLATION_HACK
293
294
295/* *****configuration of chip connection stuff***** */
261296/* must be defined; if 0, output the waveform as if it was tapped on the speaker pin as usual, if 1, output the waveform as if it was tapped on the i/o pin (volume is much lower in the latter case) */
262297#define FORCE_DIGITAL 0
263298
264299/* must be defined; if 1, normal speech (one A cycle, one B cycle per interpolation step); if 0; speak as if SPKSLOW was used (two A cycles, one B cycle per interpolation step) */
265300#define FORCE_SUBC_RELOAD 1
266301
267/* if defined, outputs the low 4 bits of the lattice filter to the i/o or clip logic, even though the real hardware doesn't do this */
268#undef ALLOW_4_LSB
269302
270/* if defined, uses impossibly perfect 'straight line' interpolation */
271#undef PERFECT_INTERPOLATION_HACK
272
273303/* *****debugging defines***** */
274304#undef VERBOSE
275305// above is general, somewhat obsolete, catch all for debugs which don't fit elsewhere
r11144r11145
857887    int i, bitout, zpar;
858888    INT32 this_sample;
859889
890    /* the following gotos are probably safe to remove */
860891    /* if we're empty and still not speaking, fill with nothingness */
861   if (!tms->speaking_now)
862        goto empty;
892    if (!tms->speaking_now)
893           goto empty;
863894
864895    /* if speak external is set, but talk status is not (yet) set,
865896    wait for buffer low to clear */
866   if (!tms->talk_status && tms->speak_external && tms->buffer_low)
897    if (!tms->talk_status && tms->speak_external && tms->buffer_low)
867898           goto empty;
868899
869900    /* loop until the buffer is full or we've stopped speaking */
870901   while ((size > 0) && tms->speaking_now)
871902    {
872903        /* if it is the appropriate time to update the old energy/pitch idxes,
873         * i.e. when IP=7, PC=12, do so. */
874        if ((tms->interp_period == 7) && (tms->PC == 12))
904         * i.e. when IP=7, PC=12, T=17, do so. Since IP=7 PC=12 T=17 is JUST
905         * BEFORE the transition to IP=0 PC=0 T=0 (4 T-cycles later), we change
906         * on the latter.*/
907        if ((tms->interp_period == 0) && (tms->PC == 0))
875908      {
876909         tms->OLDE = (tms->new_frame_energy_idx == 0);
877910         tms->OLDP = (tms->new_frame_pitch_idx == 0);
878911      }
879912
880913        /* if we're ready for a new frame to be applied, i.e. when IP=0, PC=12, Sub=1 */
881      /* (In reality, the frame was really loaded incrementally during the entire IP=0 PC=x time period, but it doesn't affect anything until IP=0 PC=12 happens) */
914        /* (In reality, the frame was really loaded incrementally during the entire IP=0 PC=x time period, but it doesn't affect anything until IP=0 PC=12 happens) */
882915        if ((tms->interp_period == 0) && (tms->PC == 12) && (tms->subcycle == 1))
883916        {
884917         // HACK for regression testing, be sure to comment out before release!
r11144r11145
10101043      if (OLD_FRAME_UNVOICED_FLAG == 1)
10111044      {
10121045         /* generate unvoiced samples here */
1013#ifdef NORMALMODE
1046#ifndef UNVOICED_HACK
10141047         if (tms->RNG & 1)
10151048            tms->excitation_data = ~0x3F; /* according to the patent it is (either + or -) half of the maximum value in the chirp table, so either 01000000(0x40) or 11000000(0xC0)*/
10161049         else
r11144r11145
10221055            tms->excitation_data = 0x80;
10231056#endif
10241057        }
1025        else
1058        else /* (OLD_FRAME_UNVOICED_FLAG == 0) */
10261059        {
10271060            /* generate voiced samples here */
10281061            /* US patent 4331836 Figure 14B shows, and logic would hold, that a pitch based chirp
r11144r11145
10321065             * disabled, forcing all samples beyond 51d to be == 51d
10331066             * (address 51d holds zeroes, which may or may not be inverted to -1)
10341067             */
1035#ifdef NORMALMODE
10361068          if (tms->pitch_count >= 51)
10371069              tms->excitation_data = tms->coeff->chirptable[51];
10381070          else /*tms->pitch_count < 51*/
10391071              tms->excitation_data = tms->coeff->chirptable[tms->pitch_count];
1040#else // hack based sort of on the D68_10.ASM file from qboxpro, which has  0x580 and 0x3A80 at the end of its chirp table
1041          if ((tms->pitch_count >= 45) || tms->pitch_count == 0)
1072#ifdef VOICED_INV_HACK
1073          // invert waveform
1074          if (tms->pitch_count >= 51)
1075              tms->excitation_data = ~tms->coeff->chirptable[51];
1076          else /*tms->pitch_count < 51*/
1077              tms->excitation_data = ~tms->coeff->chirptable[tms->pitch_count];
1078#endif
1079#ifdef VOICED_ZERO_HACK
1080          // 0 and >=51 are -128, as implied by qboxpro tables
1081          if ((tms->pitch_count == 0) | (tms->pitch_count >= 51))
10421082              tms->excitation_data = -128;
1043          else /*tms->pitch_count < 45*/
1083          else /*tms->pitch_count < 51 && > 0*/
10441084              tms->excitation_data = tms->coeff->chirptable[tms->pitch_count];
10451085#endif
1086#ifdef VOICED_PULSE_HACK
1087          // if pitch is between 0 and PWIDTH, out = PAMP, if between PWIDTH and 2*PWIDTH, out ~PAMP, else out = 0
1088          if (tms->pitch_count < PWIDTH)
1089              tms->excitation_data = PAMP;
1090          else if (tms->pitch_count < PWIDTH*2)
1091              tms->excitation_data = ~PAMP;
1092          else
1093              tms->excitation_data = 0;
1094#endif
1095#ifdef VOICED_PULSE_MONOPOLAR_HACK
1096          // if pitch is between 0 and PWIDTH, out = PAMP, else out = 0
1097          if (tms->pitch_count < PWIDTH)
1098              tms->excitation_data = PAMP;
1099          else
1100              tms->excitation_data = 0;
1101#endif
10461102        }
10471103
10481104        /* Update LFSR *20* times every sample (once per T cycle), like patent shows */
r11144r11145
12071263      Kn = tms->current_k[n-1]
12081264      bn = tms->x[n-1]
12091265    */
1210        tms->u[10] = matrix_multiply(tms->previous_energy, (tms->excitation_data*64));  //Y(11)
1266        tms->u[10] = matrix_multiply(tms->previous_energy, (tms->excitation_data<<6));  //Y(11)
12111267        tms->u[9] = tms->u[10] - matrix_multiply(tms->current_k[9], tms->x[9]);
12121268        tms->u[8] = tms->u[9] - matrix_multiply(tms->current_k[8], tms->x[8]);
12131269        tms->u[7] = tms->u[8] - matrix_multiply(tms->current_k[7], tms->x[7]);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team