public static void SL_Exit(SAMPLOAD s) { if (sl_rlength > 0) { s.reader.Seek(sl_rlength, SeekOrigin.Current); } if (sl_buffer != null) { sl_buffer = null; } }
public static SAMPLOAD SL_RegisterSample(SAMPLE s, int type, ModuleReader reader) { SAMPLOAD news; SAMPLOAD cruise = null; if (type == (int)SharpMikCommon.MDTypes.MD_MUSIC) { cruise = musiclist; } else if (type == (int)SharpMikCommon.MDTypes.MD_SNDFX) { cruise = sndfxlist; } else { return(null); } /* Allocate and add structure to the END of the list */ news = new SAMPLOAD(); if (cruise != null) { while (cruise.next != null) { cruise = cruise.next; } cruise.next = news; } else { if (type == (int)SharpMikCommon.MDTypes.MD_MUSIC) { musiclist = news; } else if (type == (int)SharpMikCommon.MDTypes.MD_SNDFX) { sndfxlist = news; } } news.infmt = (uint)(s.flags & SharpMikCommon.SF_FORMATMASK); news.outfmt = news.infmt; news.reader = reader; news.sample = s; news.length = s.length; news.loopstart = s.loopstart; news.loopend = s.loopend; return(news); }
public static bool SL_Init(SAMPLOAD s) { if (sl_buffer == null) { sl_buffer = new short[SLBUFSIZE]; } sl_rlength = (int)s.length; if ((s.infmt & SharpMikCommon.SF_16BITS) == SharpMikCommon.SF_16BITS) { sl_rlength >>= 1; } sl_old = 0; return(true); }
public static bool SL_LoadSamples() { bool ok = true; //_mm_critical = 0; if ((musiclist == null) && (sndfxlist == null)) { return(false); } ok = DitherSamples(musiclist, (int)SharpMikCommon.MDTypes.MD_MUSIC) || DitherSamples(sndfxlist, (int)SharpMikCommon.MDTypes.MD_SNDFX); musiclist = null; sndfxlist = null; return(ok); }
internal static short MD_SampleLoad(SAMPLOAD s, int type) { short result = -1; if (m_Driver != null) { if (type == (int)SharpMikCommon.MDTypes.MD_MUSIC) { type = (int)((md_mode & SharpMikCommon.DMODE_SOFT_MUSIC) == SharpMikCommon.DMODE_SOFT_MUSIC ? SharpMikCommon.MDDecodeTypes.MD_SOFTWARE : SharpMikCommon.MDDecodeTypes.MD_HARDWARE); } else if (type == (int)SharpMikCommon.MDTypes.MD_SNDFX) { type = (int)((md_mode & SharpMikCommon.DMODE_SOFT_SNDFX) == SharpMikCommon.DMODE_SOFT_SNDFX ? SharpMikCommon.MDDecodeTypes.MD_SOFTWARE : SharpMikCommon.MDDecodeTypes.MD_HARDWARE); } SampleLoader.SL_Init(s); result = m_Driver.SampleLoad(s, type); SampleLoader.SL_Exit(s); } return(result); }
public override short SampleLoad(SAMPLOAD sload, int type) { SAMPLE s = sload.sample; int handle; uint t, length, loopstart, loopend; if (type == (int)SharpMikCommon.MDDecodeTypes.MD_HARDWARE) { return(0); } /* Find empty slot to put sample address in */ for (handle = 0; handle < SharpMikCommon.MAXSAMPLEHANDLES; handle++) { if (m_Samples[handle] == null) { break; } } if (handle == SharpMikCommon.MAXSAMPLEHANDLES) { // Throw an exception so it reaches all the way up to the loader to show the load failed. throw new Exception("Out of handles"); } /* Reality check for loop settings */ if (s.loopend > s.length) { s.loopend = s.length; } if (s.loopstart >= s.loopend) { int flags = s.flags; flags &= ~SharpMikCommon.SF_LOOP; s.flags = (ushort)flags; } length = s.length; loopstart = s.loopstart; loopend = s.loopend; SampleLoader.SL_SampleSigned(sload); SampleLoader.SL_Sample8to16(sload); uint len = ((length + 20) << 1); m_Samples[handle] = new short[len]; /* read sample into buffer */ if (SampleLoader.SL_Load(m_Samples[handle], sload, length)) { return(-1); } /* Unclick sample */ if ((s.flags & SharpMikCommon.SF_LOOP) == SharpMikCommon.SF_LOOP) { if ((s.flags & SharpMikCommon.SF_BIDI) == SharpMikCommon.SF_BIDI) { for (t = 0; t < 16; t++) { m_Samples[handle][loopend + t] = m_Samples[handle][(loopend - t) - 1]; } } else { for (t = 0; t < 16; t++) { m_Samples[handle][loopend + t] = m_Samples[handle][t + loopstart]; } } } else { for (t = 0; t < 16; t++) { m_Samples[handle][t + length] = 0; } } return((short)handle); }
public abstract short SampleLoad(SAMPLOAD sample, int type);
static void FreeSampleList(SAMPLOAD s) { }
public static bool SL_Load(short[] buffer, SAMPLOAD smp, uint length) { return(SL_LoadInternal(buffer, smp.infmt, smp.outfmt, smp.scalefactor, length, smp.reader, false)); }
static bool DitherSamples(SAMPLOAD samplist, int type) { SAMPLOAD s; if (samplist == null) { return(false); } #if DITHERSAMPLES // Not sure if we really ever do this on the software render. SAMPLOAD c2smp = null; uint maxsize, speed; if ((maxsize = MD_SampleSpace(type) * 1024)) { while (SampleTotal(samplist, type) > maxsize) { /* First Pass - check for any 16 bit samples */ s = samplist; while (s) { if (s->outfmt & SF_16BITS) { SL_Sample16to8(s); break; } s = s->next; } /* Second pass (if no 16bits found above) is to take the sample with * the highest speed and dither it by half. */ if (!s) { s = samplist; speed = 0; while (s) { if ((s->sample->length) && (RealSpeed(s) > speed)) { speed = RealSpeed(s); c2smp = s; } s = s->next; } if (c2smp) { SL_HalveSample(c2smp, 2); } } } } #endif s = samplist; while (s != null) { /* sample has to be loaded ? -> increase number of samples, allocate * memory and load sample. */ if (s.sample.length != 0) { if (s.sample.seekpos != 0) { s.reader.Seek((int)s.sample.seekpos, SeekOrigin.Begin); } /* Call the sample load routine of the driver module. It has to * return a 'handle' (>=0) that identifies the sample. */ s.sample.handle = ModDriver.MD_SampleLoad(s, type); s.sample.flags = (ushort)((ushort)(s.sample.flags & ~SharpMikCommon.SF_FORMATMASK) | s.outfmt); if (s.sample.handle < 0) { FreeSampleList(samplist); return(false); } } s = s.next; } return(true); }
public static void SL_Sample8to16(SAMPLOAD s) { s.outfmt |= SharpMikCommon.SF_16BITS; s.sample.flags = (ushort)(((ushort)(s.sample.flags & ~SharpMikCommon.SF_FORMATMASK)) | s.outfmt); }
public static void SL_SampleSigned(SAMPLOAD s) { s.outfmt |= SharpMikCommon.SF_SIGNED; s.sample.flags = (ushort)(((ushort)(s.sample.flags & ~SharpMikCommon.SF_FORMATMASK)) | s.outfmt); }
public override short SampleLoad(SAMPLOAD sample, int type) { return(m_SoftwareMixer.SampleLoad(sample, type)); }
public short SampleLoad(SAMPLOAD sload, int type) { SAMPLE s = sload.sample; int handle; uint t, length, loopstart, loopend; if (type == (int)SharpMikCommon.MDDecodeTypes.MD_HARDWARE) { return(0); } /* Find empty slot to put sample address in */ for (handle = 0; handle < m_Samples.Count; handle++) { if (m_Samples[handle] == null) { break; } } if (handle == m_Samples.Count) { m_Samples.Add(null); } /* Reality check for loop settings */ if (s.loopend > s.length) { s.loopend = s.length; } if (s.loopstart >= s.loopend) { int flags = s.flags; flags &= ~SharpMikCommon.SF_LOOP; s.flags = (ushort)flags; } length = s.length; loopstart = s.loopstart; loopend = s.loopend; SampleLoader.SL_SampleSigned(sload); SampleLoader.SL_Sample8to16(sload); uint len = ((length + 20) << 1); m_Samples[handle] = new short[len]; /* read sample into buffer */ if (SampleLoader.SL_Load(m_Samples[handle], sload, length)) { return(-1); } /* Unclick sample */ if ((s.flags & SharpMikCommon.SF_LOOP) == SharpMikCommon.SF_LOOP) { if ((s.flags & SharpMikCommon.SF_BIDI) == SharpMikCommon.SF_BIDI) { for (t = 0; t < 16; t++) { m_Samples[handle][loopend + t] = m_Samples[handle][(loopend - t) - 1]; } } else { for (t = 0; t < 16; t++) { m_Samples[handle][loopend + t] = m_Samples[handle][t + loopstart]; } } } else { for (t = 0; t < 16; t++) { m_Samples[handle][t + length] = 0; } } return((short)handle); }