forked from overtools/revorbstd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRevorb.cs
More file actions
87 lines (74 loc) · 2.43 KB
/
Revorb.cs
File metadata and controls
87 lines (74 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using System.Runtime.InteropServices;
using static RevorbStd.Native;
namespace RevorbStd
{
public class Revorb
{
public static RevorbStream Jiggle(Stream fi)
{
byte[] raw = new byte[fi.Length];
long pos = fi.Position;
fi.Position = 0;
fi.Read(raw, 0, raw.Length);
fi.Position = pos;
IntPtr rawPtr = Marshal.AllocHGlobal(raw.Length);
Marshal.Copy(raw, 0, rawPtr, raw.Length);
REVORB_FILE input = new REVORB_FILE {
start = rawPtr,
size = raw.Length
};
input.cursor = input.start;
IntPtr ptr = Marshal.AllocHGlobal(4096);
REVORB_FILE output = new REVORB_FILE
{
start = ptr,
size = 4096
};
output.cursor = output.start;
int result = revorb(ref input, ref output);
Marshal.FreeHGlobal(rawPtr);
if (result != REVORB_ERR_SUCCESS)
{
Marshal.FreeHGlobal(output.start);
throw new Exception($"Expected success, got {result} -- refer to RevorbStd.Native");
}
return new RevorbStream(output);
}
public unsafe class RevorbStream : UnmanagedMemoryStream
{
private REVORB_FILE revorbFile;
public RevorbStream(REVORB_FILE revorbFile) : base((byte*)revorbFile.start.ToPointer(), revorbFile.size)
{
this.revorbFile = revorbFile;
}
public new void Dispose()
{
base.Dispose();
Marshal.FreeHGlobal(revorbFile.start);
}
}
public static void Main(string[] args)
{
try
{
using (Stream file = File.OpenRead(args[0]))
{
using (Stream data = Jiggle(file))
{
using (Stream outp = File.OpenWrite(args[1]))
{
data.Position = 0;
data.CopyTo(outp);
}
}
}
}
catch (Exception e)
{
Console.Error.WriteLine(e.ToString());
}
}
}
}