Пример #1
0
	public ASAPRandomAccessStream(ASAP asap, int duration)
	{
		this.asap = asap;
		asap.GetWavHeader(this.wavHeader, ASAPSampleFormat.S16LE, false);
		this.size = 8 + BitConverter.ToUInt32(wavHeader, 4);
		this.position = 0;
	}
Пример #2
0
 public ASAPRandomAccessStream(ASAP asap, int duration)
 {
     this.asap = asap;
     asap.GetWavHeader(this.wavHeader, ASAPSampleFormat.S16LE, false);
     this.size     = 8 + BitConverter.ToUInt32(wavHeader, 4);
     this.position = 0;
 }
Пример #3
0
    void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        this.WebClient = null;
        if (e.Cancelled || e.Error != null)
        {
            return;
        }
        byte[] module    = new byte[e.Result.Length];
        int    moduleLen = e.Result.Read(module, 0, module.Length);

        ASAP asap = new ASAP();

        asap.Load(this.Filename, module, moduleLen);
        this.Info = asap.GetInfo();
        if (this.Song < 0)
        {
            this.Song = this.Info.GetDefaultSong();
        }
        int duration = this.Info.GetLoop(this.Song) ? -1 : this.Info.GetDuration(this.Song);

        asap.PlaySong(this.Song, duration);

        Stop();
        CallJS("onLoad");
        this.MediaElement.SetSource(new ASAPMediaStreamSource(asap, duration));
    }
Пример #4
0
    public static void Main()
    {
        ASAP asap = new ASAP();

        asap.Load("foo.sap", new byte[1] {
            (byte)'S'
        }, 1);
    }
Пример #5
0
	static void Check(ASAP asap, int[] n, int periodCycles, int audc)
	{
		if (periodCycles > 112)
			return;
		if ((audc & 0xf) == 0)
			return;
		audc >>= 4;
		if (audc != 10 && audc != 14)
			return;
		n[periodCycles / 10]++;
	}
Пример #6
0
    static void ProcessFile(string inputFilename)
    {
        Stream s = File.OpenRead(inputFilename);

        byte[] module     = new byte[ASAP.ModuleMax];
        int    module_len = s.Read(module, 0, module.Length);

        s.Close();
        ASAP asap = new ASAP();

        asap.Load(inputFilename, module, module_len);
        ASAP_ModuleInfo module_info = asap.GetModuleInfo();

        if (song < 0)
        {
            song = module_info.default_song;
        }
        if (duration < 0)
        {
            duration = module_info.durations[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");
        }
        s = File.Create(outputFilename);
        byte[] buffer = new byte[8192];
        if (outputHeader)
        {
            asap.GetWavHeader(buffer, format);
            s.Write(buffer, 0, ASAP.WavHeaderBytes);
        }
        int n_bytes;

        do
        {
            n_bytes = asap.Generate(buffer, format);
            s.Write(buffer, 0, n_bytes);
        } while (n_bytes == buffer.Length);
        s.Close();
        outputFilename = null;
        song           = -1;
        duration       = -1;
    }
Пример #7
0
    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;
    }
Пример #8
0
 static void Check(ASAP asap, int[] n, int periodCycles, int audc)
 {
     if (periodCycles > 112)
     {
         return;
     }
     if ((audc & 0xf) == 0)
     {
         return;
     }
     audc >>= 4;
     if (audc != 10 && audc != 14)
     {
         return;
     }
     n[periodCycles / 10]++;
 }
Пример #9
0
    public static int Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("Usage: ultrasap path/to/ASMA");
            return(1);
        }
        string asma = args[0];
        ASAP   asap = new ASAP();

        byte[] buffer = new byte[885];
        foreach (string file in Files)
        {
            byte[] module = File.ReadAllBytes(Path.Combine(asma, file));
            asap.Load(file, module, module.Length);
            ASAPInfo info = asap.GetInfo();
            for (int song = 0; song < info.GetSongs(); song++)
            {
                int duration = info.GetDuration(song);
                asap.PlaySong(song, duration);
                int[] n = new int[12];
                while (asap.Generate(buffer, buffer.Length, ASAPSampleFormat.U8) == buffer.Length)
                {
                    Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles1, asap.Pokeys.BasePokey.Audc1);
                    Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles2, asap.Pokeys.BasePokey.Audc2);
                    Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles3, asap.Pokeys.BasePokey.Audc3);
                    Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles4, asap.Pokeys.BasePokey.Audc4);
                }
                foreach (int i in n)
                {
                    if (i > 0)
                    {
                        Console.Write(info.GetSongs() == 1 ? file : file + "#" + (song + 1));
                        foreach (int j in n)
                        {
                            Console.Write("\t{0}", j);
                        }
                        Console.WriteLine();
                        break;
                    }
                }
            }
        }
        return(0);
    }
Пример #10
0
	static void Check(string path)
	{
		if (Directory.Exists(path)) {
			foreach (string child in Directory.GetFileSystemEntries(path))
				Check(child);
		}
		else if (ASAPInfo.IsOurFile(path)) {
			byte[] module = File.ReadAllBytes(path);
			try {
				ASAP asap = new ASAP();
				asap.Load(path, module, module.Length);
				asap.PlaySong(asap.GetInfo().GetDefaultSong(), -1);
			}
			catch (Exception ex) {
				Console.WriteLine("{0}: {1}", path, ex.Message);
			}
		}
	}
Пример #11
0
    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;
    }
Пример #12
0
	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;
	}
Пример #13
0
 static void Check(string path)
 {
     if (Directory.Exists(path))
     {
         foreach (string child in Directory.GetFileSystemEntries(path))
         {
             Check(child);
         }
     }
     else if (ASAPInfo.IsOurFile(path))
     {
         byte[] module = File.ReadAllBytes(path);
         try {
             ASAP asap = new ASAP();
             asap.Load(path, module, module.Length);
             asap.PlaySong(asap.GetInfo().GetDefaultSong(), -1);
         }
         catch (Exception ex) {
             Console.WriteLine("{0}: {1}", path, ex.Message);
         }
     }
 }
Пример #14
0
    void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        this.webClient = null;
        if (e.Cancelled || e.Error != null)
        {
            return;
        }
        byte[] module     = new byte[e.Result.Length];
        int    module_len = e.Result.Read(module, 0, module.Length);

        ASAP asap = new ASAP();

        asap.Load(this.filename, module, module_len);
        ASAP_ModuleInfo module_info = asap.GetModuleInfo();

        if (this.song < 0)
        {
            this.song = module_info.default_song;
        }
        int duration = module_info.durations[this.song];

        if (duration < 0)
        {
            duration = this.defaultPlaybackTime;
        }
        else if (module_info.loops[this.song] && this.loopPlaybackTime != Once)
        {
            duration = this.loopPlaybackTime;
        }
        asap.PlaySong(this.song, duration);

        Stop();
        this.mediaElement          = new MediaElement();
        this.mediaElement.Volume   = 1;
        this.mediaElement.AutoPlay = true;
        this.mediaElement.SetSource(new ASAPMediaStreamSource(asap, duration));
    }
Пример #15
0
	public static int Main(string[] args)
	{
		if (args.Length == 0) {
			Console.WriteLine("Usage: ultrasap path/to/ASMA");
			return 1;
		}
		string asma = args[0];
		ASAP asap = new ASAP();
		byte[] buffer = new byte[885];
		foreach (string file in Files) {
			byte[] module = File.ReadAllBytes(Path.Combine(asma, file));
			asap.Load(file, module, module.Length);
			ASAPInfo info = asap.GetInfo();
			for (int song = 0; song < info.GetSongs(); song++) {
				int duration = info.GetDuration(song);
				asap.PlaySong(song, duration);
				int[] n = new int[12];
				while (asap.Generate(buffer, buffer.Length, ASAPSampleFormat.U8) == buffer.Length) {
					Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles1, asap.Pokeys.BasePokey.Audc1);
					Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles2, asap.Pokeys.BasePokey.Audc2);
					Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles3, asap.Pokeys.BasePokey.Audc3);
					Check(asap, n, asap.Pokeys.BasePokey.PeriodCycles4, asap.Pokeys.BasePokey.Audc4);
				}
				foreach (int i in n) {
					if (i > 0) {
						Console.Write(info.GetSongs() == 1 ? file : file + "#" + (song + 1));
						foreach (int j in n)
							Console.Write("\t{0}", j);
						Console.WriteLine();
						break;
					}
				}
			}
		}
		return 0;
	}
Пример #16
0
	void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
	{
		this.WebClient = null;
		if (e.Cancelled || e.Error != null)
			return;
		byte[] module = new byte[e.Result.Length];
		int moduleLen = e.Result.Read(module, 0, module.Length);

		ASAP asap = new ASAP();
		asap.Load(this.Filename, module, moduleLen);
		this.Info = asap.GetInfo();
		if (this.Song < 0)
			this.Song = this.Info.GetDefaultSong();
		int duration = this.Info.GetLoop(this.Song) ? -1 : this.Info.GetDuration(this.Song);
		asap.PlaySong(this.Song, duration);

		Stop();
		CallJS("onLoad");
		this.MediaElement.SetSource(new ASAPMediaStreamSource(asap, duration));
	}
Пример #17
0
	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;
	}
Пример #18
0
    void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        this.webClient = null;
        if (e.Cancelled || e.Error != null)
            return;
        byte[] module = new byte[e.Result.Length];
        int module_len = e.Result.Read(module, 0, module.Length);

        ASAP asap = new ASAP();
        asap.Load(this.filename, module, module_len);
        ASAP_ModuleInfo module_info = asap.GetModuleInfo();
        if (this.song < 0)
            this.song = module_info.default_song;
        int duration = module_info.durations[this.song];
        if (duration < 0)
            duration = this.defaultPlaybackTime;
        else if (module_info.loops[this.song] && this.loopPlaybackTime != Once)
            duration = this.loopPlaybackTime;
        asap.PlaySong(this.song, duration);

        Stop();
        this.mediaElement = new MediaElement();
        this.mediaElement.Volume = 1;
        this.mediaElement.AutoPlay = true;
        this.mediaElement.SetSource(new ASAPMediaStreamSource(asap, duration));
    }
Пример #19
0
 static void ProcessFile(string inputFilename)
 {
     Stream s = File.OpenRead(inputFilename);
     byte[] module = new byte[ASAP.ModuleMax];
     int module_len = s.Read(module, 0, module.Length);
     s.Close();
     ASAP asap = new ASAP();
     asap.Load(inputFilename, module, module_len);
     ASAP_ModuleInfo module_info = asap.GetModuleInfo();
     if (song < 0)
         song = module_info.default_song;
     if (duration < 0) {
         duration = module_info.durations[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");
     }
     s = File.Create(outputFilename);
     byte[] buffer = new byte[8192];
     if (outputHeader) {
         asap.GetWavHeader(buffer, format);
         s.Write(buffer, 0, ASAP.WavHeaderBytes);
     }
     int n_bytes;
     do {
         n_bytes = asap.Generate(buffer, format);
         s.Write(buffer, 0, n_bytes);
     } while (n_bytes == buffer.Length);
     s.Close();
     outputFilename = null;
     song = -1;
     duration = -1;
 }
Пример #20
0
    void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        WebClient = null;
        if (e.Cancelled || e.Error != null)
            return;
        byte[] module = new byte[e.Result.Length];
        int moduleLen = e.Result.Read(module, 0, module.Length);

        ASAP asap = new ASAP();
        asap.Load(Filename, module, moduleLen);
        ASAPInfo info = asap.GetInfo();
        if (Song < 0)
            Song = info.GetDefaultSong();
        int duration = info.GetLoop(Song) ? -1 : info.GetDuration(Song);
        asap.PlaySong(Song, duration);

        Stop();
        MediaElement = new MediaElement();
        MediaElement.Volume = 1;
        MediaElement.AutoPlay = true;
        MediaElement.SetSource(new ASAPMediaStreamSource(asap, duration));
    }
Пример #21
0
 public ASAPMediaStreamSource(ASAP asap, int duration)
 {
     Asap = asap;
     Duration = duration;
 }
Пример #22
0
 static void SetTime(string s)
 {
     duration = ASAP.ParseDuration(s);
 }
Пример #23
0
	public static void Main()
	{
		ASAP asap = new ASAP();
		asap.Load("foo.sap", new byte[1] { (byte) 'S' }, 1);
	}
Пример #24
0
 public ASAPMediaStreamSource(ASAP asap, int duration)
 {
     this.Asap     = asap;
     this.Duration = duration;
 }
Пример #25
0
	public ASAPMediaStreamSource(ASAP asap, int duration)
	{
		this.Asap = asap;
		this.Duration = duration;
	}