Ejemplo n.º 1
0
        public static byte[] FromIDSP(byte[] idsp)
        {
            File.WriteAllBytes("temp.idsp", idsp);
            IntPtr vgm = VGMStreamNative.InitVGMStream("temp.idsp");

            if (vgm == IntPtr.Zero)
            {
                throw new Exception("Error loading idsp");
            }

            int channelCount = VGMStreamNative.GetVGMStreamChannelCount(vgm);
            int bitsPerFrame = VGMStreamNative.GetVGMStreamFrameSize(vgm);
            int size         = VGMStreamNative.GetVGMStreamTotalSamples(vgm);
            int samplerate   = VGMStreamNative.GetVGMStreamSampleRate(vgm);

            int total = (int)((samplerate * bitsPerFrame * channelCount * (size / 24576000f)) / 8 * 1024);

            short[] buffer = new short[total];
            VGMStreamNative.RenderVGMStream(buffer, buffer.Length / 2, vgm);

            FileOutput o = new FileOutput();

            o.endian = Endianness.Little;

            o.WriteString("RIFF");
            o.WriteInt(0);
            o.WriteString("WAVEfmt ");

            o.WriteInt(0x10);
            o.WriteShort(1);
            o.WriteShort(channelCount);
            o.WriteInt(samplerate);
            o.WriteInt(size);
            o.WriteShort(2);
            o.WriteShort(0x10);

            o.WriteString("data");
            o.WriteInt(buffer.Length);

            for (int i = 0; i < buffer.Length / 2; i++)
            {
                o.WriteShort(buffer[i]);
            }

            o.WriteIntAt(o.Size() - 8, 4);

            VGMStreamNative.CloseVGMStream(vgm);
            File.Delete("temp.idsp");
            return(o.GetBytes());
        }
Ejemplo n.º 2
0
                public void Play()
                {
                    // this cannot be very fast .-.
                    // if anyone know how to pass the file via a byte array then that would be great...
                    File.WriteAllBytes("temp.idsp", idsp);
                    Console.WriteLine("here");
                    IntPtr vgm = VGMStreamNative.InitVGMStream("temp.idsp");

                    if (vgm == IntPtr.Zero)
                    {
                        throw new Exception("Error loading idsp");
                    }

                    Console.WriteLine("here");
                    int channelCount = VGMStreamNative.GetVGMStreamChannelCount(vgm);
                    int bitsPerFrame = VGMStreamNative.GetVGMStreamFrameSize(vgm);
                    int size         = VGMStreamNative.GetVGMStreamTotalSamples(vgm);
                    int samplerate   = VGMStreamNative.GetVGMStreamSampleRate(vgm);

                    Console.WriteLine("here");

                    int total = (int)((samplerate * bitsPerFrame * channelCount * (size / 24576000f)) / 8 * 1024);

                    //Console.WriteLine(channelCount + " " + bitsPerFrame + " " + size + " " + samplerate + " " + total.ToString("x"));

                    short[] buffer = new short[total];

                    VGMStreamNative.RenderVGMStream(buffer, buffer.Length / 2, vgm);
                    Console.WriteLine("here");

                    FileOutput o = new FileOutput();

                    o.endian = Endianness.Little;
                    for (int i = 0; i < buffer.Length / 2; i++)
                    {
                        o.WriteShort(buffer[i]);
                    }
                    o.Save("test.wav");
                    Console.WriteLine("here");
                    WAVE.Play(o.GetBytes(), VGMStreamNative.GetVGMStreamChannelCount(vgm), VGMStreamNative.GetVGMStreamSamplesPerFrame(vgm), VGMStreamNative.GetVGMStreamSampleRate(vgm));

                    VGMStreamNative.CloseVGMStream(vgm);
                    File.Delete("temp.idsp");
                }