Exemplo n.º 1
0
    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);
    }
Exemplo n.º 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;
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
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;
    }