public ASAPWavStream(string inputFilename, int song, int duration) { byte[] module = new byte[ASAPInfo.MaxModuleLength]; int moduleLen; using (Stream s = File.OpenRead(inputFilename)) { moduleLen = s.Read(module, 0, module.Length); } Asap.Load(inputFilename, module, moduleLen); ASAPInfo info = Asap.GetInfo(); if (song < 0) { song = info.GetDefaultSong(); } if (duration < 0) { duration = info.GetDuration(song); if (duration < 0) { duration = 180 * 1000; } } Asap.PlaySong(song, duration); BufferLen = Asap.GetWavHeader(Buffer, ASAPSampleFormat.S16LE, false); }
static void ProcessFile(string inputFilename) { byte[] module = new byte[ASAPInfo.MaxModuleLength]; int moduleLen; using (Stream s = File.OpenRead(inputFilename)) { moduleLen = s.Read(module, 0, module.Length); } ASAP asap = new ASAP(); asap.Load(inputFilename, module, moduleLen); ASAPInfo info = asap.GetInfo(); if (Song < 0) { Song = info.GetDefaultSong(); } if (Duration < 0) { Duration = info.GetDuration(Song); if (Duration < 0) { Duration = 180 * 1000; } } asap.PlaySong(Song, Duration); asap.MutePokeyChannels(MuteMask); if (OutputFilename == null) { int i = inputFilename.LastIndexOf('.'); OutputFilename = inputFilename.Substring(0, i + 1) + (OutputHeader ? "wav" : "raw"); } using (Stream s = File.Create(OutputFilename)) { byte[] buffer = new byte[8192]; int nBytes; if (OutputHeader) { nBytes = asap.GetWavHeader(buffer, Format, false); s.Write(buffer, 0, nBytes); } do { nBytes = asap.Generate(buffer, buffer.Length, Format); s.Write(buffer, 0, nBytes); } while (nBytes == buffer.Length); } OutputFilename = null; Song = -1; Duration = -1; }
async Task PlayFile(StorageFile sf) { if (sf == null) { Exit(); return; } byte[] module = new byte[ASAPInfo.MaxModuleLength]; int moduleLen; using (IInputStream iis = await sf.OpenSequentialReadAsync()) { IBuffer buf = await iis.ReadAsync(module.AsBuffer(), (uint)ASAPInfo.MaxModuleLength, InputStreamOptions.None); moduleLen = (int)buf.Length; } ASAP asap = new ASAP(); asap.Load(sf.Name, module, moduleLen); ASAPInfo info = asap.GetInfo(); int song = info.GetDefaultSong(); int duration = info.GetLoop(song) ? -1 : info.GetDuration(song); asap.PlaySong(song, duration); this.MyMedia = new MediaElement { AudioCategory = AudioCategory.BackgroundCapableMedia, Volume = 1, AutoPlay = true }; Window.Current.Content = this.MyMedia; await Task.Yield(); this.MyMedia.SetSource(new ASAPRandomAccessStream(asap, duration), "audio/x-wav"); MediaControl.TrackName = info.GetTitleOrFilename(); MediaControl.ArtistName = info.GetAuthor(); MediaControl.PlayPressed += MediaControl_PlayPressed; MediaControl.PausePressed += MediaControl_PausePressed; MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed; MediaControl.StopPressed += MediaControl_StopPressed; MediaControl.IsPlaying = true; }