[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
using System; using System.Runtime.InteropServices; class AudioSource { [DllImport("OpenAL32.dll")] static extern void alGenSources(int resultSize, int[] result); [DllImport("OpenAL32.dll")] static extern void alDeleteSources(int nameCount, int[] sourceNames); [DllImport("OpenAL32.dll")] static extern void alSourcei(int sourceName, int propertyType, int value); const int AL_BUFFER = 0x1009; [DllImport("OpenAL32.dll")] static extern void alSourcePlay(int sourceName); private int name; public AudioSource() { int[] names = new int[1]; alGenSources(names.Length, names); this.name = names[0]; } ~AudioSource() { alDeleteSources(1, new int[] { this.name }); } public int Buffer { set { alSourcei(this.name, AL_BUFFER, value); } } public void Play() { alSourcePlay(this.name); } } class AudioBuffer { [DllImport("alut.dll")] static extern int alutCreateBufferFromFileImage(byte[] data, int dataLength); [DllImport("OpenAL32.dll")] static extern void alDeleteBuffers(int nameCount, int[] bufferNames); private int name; public int Name { get { return this.name; } } public AudioBuffer(byte[] fileImage) { this.name = alutCreateBufferFromFileImage(fileImage, fileImage.Length); } ~AudioBuffer() { alDeleteBuffers(1, new int[] { name }); } } class Program { [DllImport("alut.dll")] static extern void alutInit(IntPtr argcp, string[] argv); [DllImport("alut.dll")] static extern void alutExit(); static void Main() { alutInit(IntPtr.Zero, null); AudioBuffer buffer = new AudioBuffer( System.IO.File.ReadAllBytes("damage1.wav") ); AudioSource source = new AudioSource(); source.Buffer = buffer.Name; source.Play(); System.Threading.Thread.Sleep(2000); alutExit(); } }