///<summary> ///</summary> ///<param name="module"></param> public ModulePlayer(SongModule module) { _uniTrk = new UniTrk(); _uniTrk.UniInit(); CurrentModule = module; WaveTableInstance = new WaveTable(); PlayerInstance = new SharpModPlayer(_uniTrk); MixCfg = new MixConfig { Is16Bits = true, Style = RenderingStyle.Stereo, Rate = 48000 }; ChannelsMixer = new ChannelsMixer(MixCfg /* DMode.DMODE_16BITS | DMode.DMODE_STEREO*/); //this.ChannelsMixer.MixFreq = 48000; ChannelsMixer.ChannelsCount = module.ChannelsCount; ChannelsMixer.OnTickHandler += PlayerInstance.MP_HandleTick; ChannelsMixer.OnBPMRequest += delegate { return(PlayerInstance.mp_bpm); }; ChannelsMixer.WaveTable = WaveTableInstance; PlayerInstance.MP_Init(CurrentModule); PlayerInstance._mixer = ChannelsMixer; PlayerInstance.SpeedConstant = 1.0f; PlayerInstance.mp_volume = 100; PlayerInstance.mp_bpm = 125; PlayerInstance.OnUpdateUI += PlayerInstance_OnUpdateUI; PlayerInstance.OnCurrentModEnd += new CurrentModEndHandler(PlayerInstance_OnCurrentModEnd); InitWaveTable(); }
private void btnOpen_Click(object sender, RoutedEventArgs e) { System.Windows.Controls.OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == true) { if (_player != null) { _player.Stop(); } myMod = ModuleLoader.Instance.LoadModule(ofd.File.OpenRead()); _player = new ModulePlayer(myMod); SharpMod.SoundRenderer.SilverlightDriver drv = new SharpMod.SoundRenderer.SilverlightDriver(MyMediaElement); _player.RegisterRenderer(drv); _player.DspAudioProcessor = new AudioProcessor(1024, 50); _player.DspAudioProcessor.OnCurrentSampleChanged += new AudioProcessor.CurrentSampleChangedHandler(DspAudioProcessor_OnCurrentSampleChanged); _player.OnGetPlayerInfos += new GetPlayerInfosHandler(_player_OnGetPlayerInfos); _player.PlayerInstance.SpeedConstant = (float)this.BpmSlide.Value; LblTrackNfo0.Value = String.Format("Mod Name: {0}", myMod.SongName); LblTrackNfo1.Value = String.Format("Channels: {0:00}", myMod.ChannelsCount); LblTrackNfo2.Value = String.Format("Base BPM: {0:000}", myMod.InitialTempo); LblTrackNfo3.Value = String.Format("Mod Type: {0}", myMod.ModType); } }
/// <summary> /// Load Module from stream /// </summary> /// <param name="inputStream">stream to load from</param> /// <returns>SongModule</returns> public SongModule LoadModule(Stream inputStream) { var toReturn = new SongModule(); Init(); _reader = new ModBinaryReader(inputStream); // init panning array for (var t = 0; t < 32; t++) { toReturn.Panning[t] = (short)((((t + 1) & 2) != 0) ? 255 : 0); } if (!LoadHeader(toReturn)) { toReturn = null; throw new SharpModException(SharpModExceptionResources.ERROR_LOADING_HEADER); } if (!LoadSamples(toReturn)) { toReturn = null; throw new SharpModException(SharpModExceptionResources.ERROR_LOADING_SAMPLEINFO); } return(toReturn); }
/// <summary> /// Load samples of the module /// </summary> /// <param name="module">Module to fill</param> /// <returns>True if success</returns> private bool LoadSamples(SongModule module) { foreach (var t1 in module.Instruments) { for (var u = 0; u < t1.NumSmp; u++) { // sample has to be loaded ? -> increase // number of samples and allocate memory and // load sample if (t1.Samples[u].Length != 0) { if (t1.Samples[u].SeekPos != 0) { _reader.Seek(t1.Samples[u].SeekPos, SeekOrigin.Begin); } // Call the sample load routine of the driver module. // It has to return a 'handle' (>=0) that identifies // the sample var smp = t1.Samples[u]; int handle = SampleLoad(smp.Length, smp.LoopStart, smp.LoopEnd, smp.Flags); t1.Samples[u].Handle = handle; if (t1.Samples[u].Handle < 0) { return(false); } t1.Samples[u].SampleBytes = _samples[handle]; } } } return(true); }
public Chiptune(string ModFilename) { mod = ModuleLoader.Instance.LoadModule(ModFilename); player = new ModulePlayer(mod); XnaSoundRenderer drv = new XnaSoundRenderer(new DynamicSoundEffectInstance(48000, AudioChannels.Stereo)); player.RegisterRenderer(drv); }
public bool Init(SongModule module) { _module = module; patbuf = null; mh = new MODULEHEADER(); mh.songlength = (short)(mh.magic1 = 0); /*for (i = 0; i < 20; i++) * mh.songname[i] = 0;*/ mh.positions.Initialize(); /*for (i = 0; i < 128; i++) * mh.positions[i] = 0;*/ mh.magic2.Initialize(); /*for (i = 0; i < 4; i++) * mh.magic2[i] = 0;*/ for (int i = 0; i < 31; i++) { mh.samples[i].length = mh.samples[i].reppos = mh.samples[i].replen = 0; mh.samples[i].finetune = (short)(mh.samples[i].volume = 0); /*for (j = 0; j < 22; j++) * mh.samples[i].samplename[j] = 0;*/ } return(true); }
public bool Init(SongModule module) { this._module = module; int i; s3mbuf = null; paraptr = null; //if(!(s3mbuf=(S3MNOTE *)m_.MLoader.MyMalloc(16*64*sizeof(S3MNOTE)))) return 0; s3mbuf = new S3MNOTE[16 * 64]; for (i = 0; i < 16 * 64; i++) { s3mbuf[i] = new S3MNOTE(); } //if(!(mh=(S3MHEADER *)m_.MLoader.MyCalloc(1,sizeof(S3MHEADER)))) return 0; mh = new S3MHEADER(); mh.t1a = 0; mh.type = 0; mh.unused1[0] = 0; mh.unused1[1] = 0; mh.ordnum = 0; mh.insnum = 0; mh.patnum = 0; mh.flags = 0; mh.tracker = 0; mh.fileformat = 0; mh.special = 0; mh.mastervol = 0; mh.initspeed = 0; mh.inittempo = 0; mh.mastermult = 0; mh.ultraclick = 0; mh.pantable = 0; /*for (i = 0; i < 28; i++) * mh.songname[i] = 0;*/ /*for (i = 0; i < 4; i++) * mh.scrm[i] = 0; * * for (i = 0; i < 8; i++) * mh.unused2[i] = 0; * * for (i = 0; i < 32; i++) * mh.channels[i] = 0;*/ mh.unused2.Initialize(); mh.channels.Initialize(); return(true); }
/// <summary> /// Allocate Instruments /// </summary> /// <param name="module"></param> /// <param name="nbInstruments"></param> /// <returns></returns> public bool AllocInstruments(SongModule module, int nbInstruments) { module.Instruments = new List <Instrument>(nbInstruments); for (var i = 0; i < nbInstruments; i++) { module.Instruments.Add(new Instrument()); } for (var i = 0; i < nbInstruments; i++) { module.Instruments[i].NumSmp = 0; module.Instruments[i].VolFlg = 0; module.Instruments[i].VolPts = 0; module.Instruments[i].VolSus = 0; module.Instruments[i].VolBeg = 0; module.Instruments[i].VolEnd = 0; module.Instruments[i].PanFlg = 0; module.Instruments[i].PanSus = 0; module.Instruments[i].PanEnd = 0; module.Instruments[i].VibType = 0; module.Instruments[i].VibSweep = 0; module.Instruments[i].VibDepth = 0; module.Instruments[i].VibRate = 0; module.Instruments[i].VolFade = 0; module.Instruments[i].InsName = null; module.Instruments[i].Samples = new List <Sample>(); for (var j = 0; j < 96; j++) { module.Instruments[i].SampleNumber[j] = 0; } for (var j = 0; j < 12; j++) { module.Instruments[i].VolEnv[j].Pos = 0; module.Instruments[i].VolEnv[j].Val = 0; module.Instruments[i].PanEnv[j].Pos = 0; module.Instruments[i].PanEnv[j].Val = 0; } } return(true); }
/// <summary> /// Load header of the module with the best loader /// </summary> /// <param name="module">Module to fill</param> /// <returns>true if success</returns> private bool LoadHeader(SongModule module) { var toReturn = false; _currentLoader = null; foreach (var loader in Loaders) { //Reset the reader _reader.Rewind(); loader.Reader = _reader; if (loader.Test()) { _currentLoader = loader; break; } } // Loader not found... if (null == _currentLoader) { throw new SharpModException(SharpModExceptionResources.ERROR_NOT_A_MODULE); } if (!_uniTrack.UniInit()) { return(false); } _currentLoader.UniTrack = _uniTrack; // init module loader if (_currentLoader.Init(module)) { _reader.Rewind(); toReturn = _currentLoader.Load(); } // free unitrk allocations _uniTrack.UniCleanup(); return(toReturn); }
///<summary> ///</summary> ///<param name="module"></param> ///<param name="numPat"></param> ///<param name="rowsCount"></param> ///<returns></returns> public bool AllocPatterns(SongModule module, int numPat, int rowsCount) { // Allocate track sequencing array //module.Patterns = new List<Pattern>(numPat); if (module.Patterns == null) { module.Patterns = new List <Pattern>(); } if (module.Patterns.Count <= numPat) { module.Patterns.Add(new Pattern(rowsCount)); } else { module.Patterns[numPat] = new Pattern(rowsCount); } //for (int t = 0; t < numPat; t++) return(true); }
public bool Init(SongModule module) { this._module = module; mh = null; //if(!(mh=(XMHEADER *)m_.MLoader.MyCalloc(1,sizeof(XMHEADER)))) return 0; mh = new XMHEADER(); mh.version = mh.headersize = mh.restart = mh.tempo = mh.bpm = 0; mh.songlength = (short)(mh.numchn = (short)(mh.numpat = (short)(mh.numins = (short)(mh.flags = (short)0)))); /* for (i = 0; i < 17; i++) * mh.id[i] = 0; * for (i = 0; i < 21; i++) * mh.songname[i] = 0; * for (i = 0; i < 20; i++) * mh.trackername[i] = 0; * for (i = 0; i < 256; i++) * mh.orders[i] = 0;*/ mh.orders.Initialize(); return(true); }
public bool Init(SharpMod.Song.SongModule module) { this._module = module; int i; patbuf = null; mh = new M15_MODULEHEADER(); mh.songlength = (short)(mh.magic1 = 0); for (i = 0; i < 128; i++) { mh.positions[i] = 0; } for (i = 0; i < 15; i++) { mh.samples[i].length = mh.samples[i].reppos = mh.samples[i].replen = 0; mh.samples[i].finetune = (short)(mh.samples[i].volume = (short)0); } return(true); }