unsigned int get_freq_from_period(int period, int linear) { if (period <= 0) return INT_MAX; else if (linear) return period; else return _muldiv(8363, 1712L << 8, (period << 8)); }
BOOL CSoundFile::CanPackSample(LPSTR pSample, UINT nLen, UINT nPacking, BYTE *result) //----------------------------------------------------------------------------------- { int pos, old, oldpos, besttable = 0; DWORD dwErr, dwTotal, dwResult; int i,j; if (result) *result = 0; if ((!pSample) || (nLen < 1024)) return FALSE; // Try packing with different tables dwResult = 0; for (j=1; j<MAX_PACK_TABLES; j++) { memcpy(CompressionTable, UnpackTable[j], 16); dwErr = 0; dwTotal = 1; old = pos = oldpos = 0; for (i=0; i<(int)nLen; i++) { int s = (int)pSample[i]; PackSample(pos, s); dwErr += abs(pos - oldpos); dwTotal += abs(s - old); old = s; oldpos = pos; } dwErr = _muldiv(dwErr, 100, dwTotal); if (dwErr >= dwResult) { dwResult = dwErr; besttable = j; } } memcpy(CompressionTable, UnpackTable[besttable], 16); if (result) { if (dwResult > 100) *result = 100; else *result = (BYTE)dwResult; } return (dwResult >= nPacking) ? TRUE : FALSE; }
static inline int rn_vibrato(song_t *csf, song_voice_t *chan, int period) { unsigned int vibpos = chan->vibrato_position & 0xFF; int vdelta; unsigned int vdepth; switch (chan->vib_type) { case VIB_SINE: default: vdelta = sine_table[vibpos]; break; case VIB_RAMP_DOWN: vdelta = ramp_down_table[vibpos]; break; case VIB_SQUARE: vdelta = square_table[vibpos]; break; case VIB_RANDOM: vdelta = 128 * ((double) rand() / RAND_MAX) - 64; break; } if (csf->flags & SONG_ITOLDEFFECTS) { vdepth = 5; vdelta = -vdelta; // yes, IT does vibrato backwards in old-effects mode. try it. } else { vdepth = 6; } vdelta = (vdelta * (int)chan->vibrato_depth) >> vdepth; if (csf->flags & SONG_LINEARSLIDES) { int l = abs(vdelta); if (vdelta < 0) { vdelta = _muldiv(period, linear_slide_up_table[l >> 2], 0x10000) - period; if (l & 0x03) vdelta += _muldiv(period, fine_linear_slide_up_table[l & 0x03], 0x10000) - period; } else {