示例#1
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;
    }
示例#2
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;
    }
示例#3
0
    protected override void GetSampleAsync(MediaStreamType mediaStreamType)
    {
        byte[] buffer = new byte[8192];
        int    blocksPlayed;
        int    buffer_len;

        lock (asap) {
            blocksPlayed = asap.GetBlocksPlayed();
            buffer_len   = asap.Generate(buffer, BitsPerSample == 8 ? ASAP_SampleFormat.U8 : ASAP_SampleFormat.S16LE);
        }
        Stream            s   = new MemoryStream(buffer);
        MediaStreamSample mss = new MediaStreamSample(this.mediaStreamDescription, s, 0, buffer_len,
                                                      blocksPlayed * 10000000 / ASAP.SampleRate, SampleAttributes);

        ReportGetSampleCompleted(mss);
    }
示例#4
0
    uint Read(IBuffer buffer, uint offset, uint count)
    {
        if (this.needSeek)
        {
            if (this.position < 44)
            {
                asap.Seek(0);
            }
            else
            {
                ulong bytes = this.position - 44 & ~(BufferSize - 1UL);
                asap.SeekSample((int)(bytes / wavHeader[32]));
            }
            this.needSeek = false;
        }

        ulong left = this.size - this.position;

        if (count > left)
        {
            count = (uint)left;
        }
        if (this.position < 44UL)
        {
            uint n = Math.Min(44 - (uint)this.position, count);
            this.wavHeader.CopyTo((int)this.position, buffer, offset, (int)n);
            this.position += n;
            offset        += n;
            count         -= n;
        }
        while (count > 0)
        {
            int i = (int)this.position - 44 & BufferSize - 1;
            if (i == 0)
            {
                asap.Generate(this.samples, BufferSize, ASAPSampleFormat.S16LE);
            }
            uint n = Math.Min((uint)BufferSize - (uint)i, count);
            this.samples.CopyTo(i, buffer, offset, (int)n);
            this.position += n;
            offset        += n;
            count         -= n;
        }
        return(offset);
    }
示例#5
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);
    }
示例#6
0
    public override int Read(byte[] outputBuffer, int offset, int count)
    {
        int i = BufferPos;

        if (i >= BufferLen)
        {
            BufferLen = Asap.Generate(Buffer, Buffer.Length, ASAPSampleFormat.S16LE);
            if (BufferLen == 0)
            {
                return(0);
            }
            i = 0;
        }
        if (count > BufferLen - i)
        {
            count = BufferLen - i;
        }
        Array.Copy(Buffer, i, outputBuffer, offset, count);
        BufferPos = i + count;
        return(count);
    }
示例#7
0
    public override int Read(byte[] outputBuffer, int offset, int count)
    {
        int i = buffer_pos;

        if (i >= buffer_len)
        {
            buffer_len = asap.Generate(buffer, ASAP_SampleFormat.S16LE);
            if (buffer_len == 0)
            {
                return(0);
            }
            i = 0;
        }
        if (count > buffer_len - i)
        {
            count = buffer_len - i;
        }
        Array.Copy(buffer, i, outputBuffer, offset, count);
        buffer_pos = i + count;
        return(count);
    }
示例#8
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;
	}
示例#9
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;
	}
示例#10
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;
 }