-
Notifications
You must be signed in to change notification settings - Fork 0
/
DuneMusic.cs
156 lines (129 loc) · 6.51 KB
/
DuneMusic.cs
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Runtime.InteropServices;
namespace DuneMusic
{
public class DuneMusic
{
public enum DuneMusicOplEmu
{
kOplEmuWoody,
kOplEmuDosbox,
kOplEmuNuked,
};
public static void Init(int sampleRate, string dataDirectory, DuneMusicOplEmu oplEmu)
{
DuneMusic_Init(sampleRate, UTF8_ToNative(dataDirectory), oplEmu);
}
public static void Quit()
{
DuneMusic_Quit();
}
public static void GetSamples(Int16[] buf)
{
DuneMusic_GetSamples(buf, (uint)(buf.Length / 2));
}
public static void InsertMemoryFile(string filename, byte[] data)
{
DuneMusic_InsertMemoryFile(UTF8_ToNative(filename), data, (UIntPtr)data.Length);
}
public enum DuneMusicType {
kMusicAttack = 0, /*!< Played when at least one of player's units was hit. */
kMusicPeace, /*!< Played most of the time when the enemy is not attacking. */
kMusicIntro, /*!< Background music for intro. */
kMusicMenu, /*!< The menu background music. */
kMusicBriefingH, /*!< Harkonnen briefing background music. */
kMusicBriefingA, /*!< Atreides briefing background music. */
kMusicBriefingO, /*!< Ordos briefing background music. */
kMusicWinH, /*!< Harkonnen victory screen background music.. */
kMusicWinA, /*!< Atreides victory screen background music.. */
kMusicWinO, /*!< Ordos victory screen background music.. */
kMusicLoseH, /*!< Harkonnen failure screen background music.. */
kMusicLoseA, /*!< Atreides failure screen background music.. */
kMusicLoseO, /*!< Ordos failure screen background music.. */
kMusicGameStat, /*!< Game statistics background music. */
kMusicMapChoice, /*!< The map choice background music. */
kMusicMeanwhile, /*!< Meanwhile cutscene background music. */
kMusicFinaleH, /*!< Harkonnen finale cutscene background music. */
kMusicFinaleA, /*!< Atreides finale cutscene background music. */
kMusicFinaleO, /*!< Ordos finale cutscene background music. */
kMusicNumTypes,
kMusicRandom = 0xFF /*!< Random music (attack music or peace music) */
};
public static void ChangeMusic(DuneMusicType musicType)
{
DuneMusic_ChangeMusic(musicType);
}
public static void ChangeMusicEx(DuneMusicType musicType, string filename, int musicNum)
{
DuneMusic_ChangeMusicEx(musicType, UTF8_ToNative(filename), musicNum);
}
public static Int16[] SynthesizeAudio(string filename, int musicNum, int volume)
{
UIntPtr numFrames;
Int16[] cBuffer = DuneMusic_SynthesizeAudio(UTF8_ToNative(filename), musicNum, volume, out numFrames);
Int16[] buffer = cBuffer.Clone() as Int16[];
DuneMusic_FreeAudio(cBuffer);
return buffer;
}
public static bool IsMusicEnabled()
{
return DuneMusic_IsMusicEnabled() != 0;
}
public static void SetMusicEnabled(bool enabled)
{
DuneMusic_SetMusicEnabled(enabled ? 1 : 0);
}
public static bool IsMusicPlaying()
{
return DuneMusic_IsMusicPlaying() != 0;
}
public static void SetMusicVolume(int volume)
{
DuneMusic_SetMusicVolume(volume);
}
public static uint GetKnownMusicCount()
{
return DuneMusic_GetKnownMusicCount();
}
public static void SetKnownMusicIndex(uint index)
{
DuneMusic_SetKnownMusicIndex(index);
}
private const string nativeLibName = "dunemusic";
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_Init(int sampleRate, byte[] dataDirectory, DuneMusicOplEmu oplEmu);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_Quit();
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_GetSamples(Int16[] buf, uint numFrames);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_InsertMemoryFile(byte[] filename, byte[] data, UIntPtr length);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_ChangeMusic(DuneMusicType musicType);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_ChangeMusicEx(DuneMusicType musicType, byte[] filename, int musicNum);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I2, SizeParamIndex = 3)]
private static extern Int16[] DuneMusic_SynthesizeAudio(byte[] filename, int musicNum, int volume, out UIntPtr numFramesReturned);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_FreeAudio(Int16[] audioBuffer);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern int DuneMusic_IsMusicEnabled();
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_SetMusicEnabled(int enabled);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern int DuneMusic_IsMusicPlaying();
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_SetMusicVolume(int volume);
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern uint DuneMusic_GetKnownMusicCount();
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void DuneMusic_SetKnownMusicIndex(uint index);
private static byte[] UTF8_ToNative(string s)
{
if (s == null)
return null;
return System.Text.Encoding.UTF8.GetBytes(s + '\0');
}
}
}