[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
| 名前 | 値 | |
| ALUT_WAVEFORM_SINE | 0x100 | |
| ALUT_WAVEFORM_SQUARE | 0x101 | |
| ALUT_WAVEFORM_SAWTOOTH | 0x102 | |
| ALUT_WAVEFORM_WHITENOISE | 0x103 | |
| ALUT_WAVEFORM_IMPULSE | 0x104 |
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 alutCreateBufferWaveform(
WaveForm waveShape,
float frequency,
float phase,
float duration
);
[DllImport("OpenAL32.dll")]
static extern void alDeleteBuffers(int nameCount, int[] bufferNames);
private int name;
public int Name { get { return this.name; } }
public AudioBuffer(WaveForm waveShape, float frequency, float phase, float duration)
{
this.name = alutCreateBufferWaveform(waveShape, frequency, phase, duration);
}
~AudioBuffer()
{
alDeleteBuffers(1, new int[] { name });
}
}
enum WaveForm
{
//ALUT_WAVEFORM_SINE
Sine = 0x100,
//ALUT_WAVEFORM_SQUARE
Square,
//ALUT_WAVEFORM_SAWTOOTH
SawTooth,
//ALUT_WAVEFORM_WHITENOISE
WhiteNoize,
//ALUT_WAVEFORM_IMPULSE
Impulse
}
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);
foreach (WaveForm waveShape in Enum.GetValues(typeof(WaveForm)))
{
System.Console.WriteLine(waveShape);
AudioBuffer buffer = new AudioBuffer(waveShape, 440, 0, 1);
AudioSource source = new AudioSource();
source.Buffer = buffer.Name;
source.Play();
System.Threading.Thread.Sleep(2000);
}
alutExit();
}
}