[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();
}
}
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 alutCreateBufferFromFile(string fileName);
[DllImport("OpenAL32.dll")]
static extern void alDeleteBuffers(int nameCount, int[] bufferNames);
private int name;
public int Name { get { return this.name; } }
public AudioBuffer(string fileName)
{
this.name = alutCreateBufferFromFile(fileName);
}
~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("damage1.wav");
AudioSource source = new AudioSource();
source.Buffer = buffer.Name;
source.Play();
System.Threading.Thread.Sleep(2000);
alutExit();
}
}
| 定数名 | 説明 | 値 |
| ALUT_ERROR_NO_ERROR | エラーはありません。 | 0 |
| ALUT_ERROR_OUT_OF_MEMORY | メモリが足りません。 | 0x200 |
| ALUT_ERROR_INVALID_ENUM | Alutの関数に不正な定数が与えられました。 | 0x201 |
| ALUT_ERROR_INVALID_VALUE | Alutの関数に不正な値が与えられました。 | 0x202 |
| ALUT_ERROR_INVALID_OPERATION | 行った操作は現在のALUTの状態では不正です。 | 0x203 |
| ALUT_ERROR_NO_CURRENT_CONTEXT | 現在のコンテキストがセットされていません。(alutInitを呼べば自動的にコンテキストはセットされるのでこれはあまり気にしなくていいでしょう) | 0x204 |
| ALUT_ERROR_AL_ERROR_ON_ENTRY | ALUT関数へのエントリーにすでにALエラーがあります。 (なんのこっちゃ) |
0x205 |
| ALUT_ERROR_ALC_ERROR_ON_ENTRY | ALUT関数へのエントリーにすでにALCえらーがあります。 | 0x206 |
| ALUT_ERROR_OPEN_DEVICE | ALCデバイスを開く上でエラーがありました。 | 0x207 |
| ALUT_ERROR_CLOSE_DEVICE | ALCデバイスを閉じる上でエラーがありました。 | 0x208 |
| ALUT_ERROR_CREATE_CONTEXT | Contextを生成する上でエラーがありました。 | 0x209 |
| ALUT_ERROR_MAKE_CONTEXT_CURRENT | 現在のContextを変更できませんでした。 | 0x20A |
| ALUT_ERROR_DESTROY_CONTEXT | Contextを破壊する上でエラーがありました。 | 0x20B |
| ALUT_ERROR_GEN_BUFFERS | AL Bufferを生成するのにエラーがありました。 | 0x20C |
| ALUT_ERROR_BUFFER_DATA | バッファ・データをALに送る途中でエラーがありました。 | 0x20D |
| ALUT_ERROR_IO_ERROR | I/Oエラー。より詳しくはerrnoを。 | 0x20E |
| ALUT_ERROR_UNSUPPORTED_FILE_TYPE | サポートされていないファイルタイプです。 | 0x20F |
| ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE | ファイルタイプは大丈夫ですが、サポートされていないモードです。 | 0x210 |
| ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA | サウンドデータに間違いがあるか、欠けています | 0x211 |
using System.Runtime.InteropServices;
enum AlutError
{
ALUT_ERROR_NO_ERROR = 0,
ALUT_ERROR_OUT_OF_MEMORY = 0x200,
ALUT_ERROR_INVALID_ENUM,
ALUT_ERROR_INVALID_VALUE,
ALUT_ERROR_INVALID_OPERATION,
ALUT_ERROR_NO_CURRENT_CONTEXT,
ALUT_ERROR_AL_ERROR_ON_ENTRY,
ALUT_ERROR_ALC_ERROR_ON_ENTRY,
ALUT_ERROR_OPEN_DEVICE,
ALUT_ERROR_CLOSE_DEVICE,
ALUT_ERROR_CREATE_CONTEXT,
ALUT_ERROR_MAKE_CONTEXT_CURRENT,
ALUT_ERROR_DESTROY_CONTEXT,
ALUT_ERROR_GEN_BUFFERS,
ALUT_ERROR_BUFFER_DATA,
ALUT_ERROR_IO_ERROR,
ALUT_ERROR_UNSUPPORTED_FILE_TYPE,
ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE,
ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA
}
class Program
{
[DllImport("alut")]
static extern string alutGetErrorString(AlutError error);
static void Main()
{
foreach (AlutError error in System.Enum.GetValues(typeof(AlutError)))
{
System.Console.WriteLine(error + " : " + alutGetErrorString(error));
}
System.Console.ReadLine();
}
}
using System;
using System.Runtime.InteropServices;
using System.Threading;
class Program
{
//OpenAL Utility Toolkit (Alut)の関数をインポート
[DllImport("alut.dll")]
static extern bool alutInit(IntPtr argcp, string[] argv);
[DllImport("alut.dll")]
static extern bool alutExit();
[DllImport("alut.dll")]
static extern int alutCreateBufferHelloWorld();
//OpenALの関数をインポート
[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);
[DllImport("OpenAL32.dll")]
static extern void alSource3f(
int sourceName, int propertyType,
float v1, float v2, float v3
);
const int AL_POSITION = 0x1004;
static void Main()
{
alutInit(IntPtr.Zero, null);
int[] sources = new int[1];
alGenSources(sources.Length, sources);
alSourcei(sources[0], AL_BUFFER, alutCreateBufferHelloWorld());
for (int i = 0; i < 4; i++)
{
alSource3f(sources[0], AL_POSITION, 0, 0, -i);
alSourcePlay(sources[0]);
Thread.Sleep(1500);
}
alDeleteSources(sources.Length, sources);
alutExit();
}
}
using System;
using System.Runtime.InteropServices;
using System.Threading;
class Program
{
//OpenAL Utility Toolkit (Alut)の関数をインポート
[DllImport("alut.dll")]
static extern bool alutInit(IntPtr argcp, string[] argv);
[DllImport("alut.dll")]
static extern bool alutExit();
[DllImport("alut.dll")]
static extern int alutCreateBufferHelloWorld();
//OpenALの関数をインポート
[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);
const int AL_POSITION = 0x1004;
[DllImport("OpenAL32.dll")]
static extern void alListener3f(int propertyType, float x, float y, float z);
static void Main()
{
alutInit(IntPtr.Zero, null);
int[] sources = new int[1];
alGenSources(sources.Length, sources);
alSourcei(sources[0], AL_BUFFER, alutCreateBufferHelloWorld());
for (int i = 0; i < 4; i++)
{
alListener3f(AL_POSITION, 0, 0, i);
alSourcePlay(sources[0]);
Thread.Sleep(1500);
}
alDeleteSources(sources.Length, sources);
alutExit();
}
}