FreeBASIC ExtLibal
目次 →その他→ライブラリ・ヘッダー索引 →OpenAL ←オリジナル・サイト
目次 →FreeBASIC のハッキング→FreeBASIC でのハッキングのための情報 →外部ライブラリ索引 →OpenAL ←オリジナル・サイト
OpenAL
OpenAL は、クロスプラットフォーム 3D オーディオ API で、ゲーム・アプリケーションや、他の多くの種類の音声アプリケーションの用途に適しています。
ALUT は、OpenAL ユーティリティ・ツールキットで、OpenALで使う、追加の関数を提供するライブラリです。
ウエブ・サイト: http://www.openal.org ∞
利用できる環境: Win32, Linux
include するヘッダー: AL/al.bi, AL/alut.bi
ヘッダー・バージョン: openal-soft-1.16.0, freealut 1.1.0
使用例: examples/sound/OpenAL/
注意 :下記のエラーでコンパイルできない場合:
\FreeBASIC\bin\win32\ld.exe: cannot find -lOpenAL32
cspdevpack-0.6.2-installer.zip を下記からダウンロードします。
https://sourceforge.net/projects/csp/files/CSP-Devpack/0.6.2_32bit/cspdevpack-0.6.2-installer.zip/download
解凍すると、csp-devpack-0.6.0-installer.exe が抽出されます。
この exe を実行(インストール)せずに、Universal Extractor か 7-Zip を使って解凍します。
bin フォルダの openAL32.dll を FreeBASIC/lib/win32 にコピーします。
もし、FreeBASIC/lib/win32 フォルダに openAL32.dll.a が有れば、削除するか名前変更します。
また、bin フォルダの alut.dll を、Win 64-bit では SysWOW64 フォルダに、Win 32-bit では System32 フォルダにコピーします。
例1:
examples/sound/OpenAL/wav-player.bas
'' OpenAL による .wav 再生の例
#include "AL/al.bi"
#include "AL/alut.bi"
'' OpenAL を初期化
alutInit(0, 0)
''
'' .wav を OpenAL バッファにロードする
''
dim as string sound_file = exepath ( ) + "/../data/prodigy.wav"
Dim As ALuint buffer
buffer = alutCreateBufferFromFile( SOUND_FILE )
If( alutGetError( ) <> ALUT_ERROR_NO_ERROR ) Then
Print "エラー:.wavの読み込みに失敗しました!" : Sleep : End 1
End If
''
'' 音源を設定します - それぞれ 3Dの位置と速さを持つことができます。
''
Dim As ALuint source
alGenSources(1, @source)
Dim As ALfloat SourcePos(0 To 2) = {0.0, 0.0, 0.0}
Dim As ALfloat SourceVel(0 To 2) = {0.0, 0.0, 0.0}
alSourcei(source, AL_BUFFER, buffer)
alSourcef(source, AL_PITCH, 1.0)
alSourcef(source, AL_GAIN, 1.0)
alSourcefv(source, AL_POSITION, @SourcePos(0))
alSourcefv(source, AL_VELOCITY, @SourceVel(0))
''
'' 聴取者の 3D 位置などを設定する
''
Dim As ALfloat listener_position(0 To 2) = {0.0, 0.0, 0.0}
Dim As ALfloat listener_velocity(0 To 2) = {0.0, 0.0, 0.0}
Dim As ALfloat listener_orientation(0 To 5) = {0.0, 0.0, -1.0, _ '' look at
0.0, 0.0, 1.0} '' up vector
alListenerfv(AL_POSITION, @listener_position(0))
alListenerfv(AL_VELOCITY, @listener_velocity(0))
alListenerfv(AL_ORIENTATION, @listener_orientation(0))
''
'' 音声を再生(AL_FALSE にするとループは無効になる)
''
alSourcei(source, AL_LOOPING, AL_TRUE)
alSourcePlay(source)
Print "音声を再生中。何かキーを押すと中断します。終了は ESC を押してください。"
Dim As String key
Dim As Integer active = -1
Do
key = Inkey()
If (Len(key) > 0) Then
If (key = Chr(27)) Then
Exit Do
End If
If (active) Then
alSourcePause(source)
active = 0
Else
alSourcePlay(source)
active = -1
End If
End If
Loop
alSourceStop(source)
''
'' Clean up
''
alDeleteBuffers(1, @buffer)
alDeleteSources(1, @source)
alutExit()
例2:
'' OpenAL-based .wav player example
#include "AL/al.bi"
#include "AL/alut.bi"
Const SOUND_FILE = "test.wav"
'' Initialize OpenAL
alutInit( 0 , 0 )
''
'' Load the .wav into an OpenAL buffer
''
Dim As ALuint buffer
alGenBuffers( 1 , @buffer)
Dim As ALenum wavFormat
Dim As ALsizei wavSize
Dim As ALsizei wavFreq
Dim As Any Ptr wavData
Dim As ALboolean wavLoop
alutLoadWAVFile( SOUND_FILE, @wavFormat, @wavData, @wavSize, @wavFreq, @wavLoop)
alBufferData( buffer, wavFormat, wavData, wavSize, wavFreq)
alutUnloadWAV( wavFormat, wavData, wavSize, wavFreq)
If ( alGetError( ) <> AL_NO_ERROR) Then
Print "Error: Loading the .wav failed!"
End If
''
'' Setup sound sources -- each one can have a 3D position & velocity.
''
Dim As ALuint source
alGenSources( 1 , @source)
Dim As ALfloat SourcePos( 0 To 2 ) = { 0 .0 , 0 .0 , 0 .0 }
Dim As ALfloat SourceVel( 0 To 2 ) = { 0 .0 , 0 .0 , 0 .0 }
alSourcei( source, AL_BUFFER, buffer)
alSourcef( source, AL_PITCH, 1 .0 )
alSourcef( source, AL_GAIN, 1 .0 )
alSourcefv( source, AL_POSITION, @SourcePos( 0 ) )
alSourcefv( source, AL_VELOCITY, @SourceVel( 0 ) )
''
'' Setup the listener's 3D position etc.
''
Dim As ALfloat listener_position( 0 To 2 ) = { 0 .0 , 0 .0 , 0 .0 }
Dim As ALfloat listener_velocity( 0 To 2 ) = { 0 .0 , 0 .0 , 0 .0 }
Dim As ALfloat listener_orientation( 0 To 5 ) = { 0 .0 , 0 .0 , -1 .0 , _ '' look at
0 .0 , 0 .0 , 1 .0 } '' up vector
alListenerfv( AL_POSITION, @listener_position( 0 ) )
alListenerfv( AL_VELOCITY, @listener_velocity( 0 ) )
alListenerfv( AL_ORIENTATION, @listener_orientation( 0 ) )
''
'' Play the sound (change to AL_FALSE to disable looping)
''
alSourcei( source, AL_LOOPING, AL_TRUE)
alSourcePlay( source)
Print "Sound is playing, press ESC to exit and anything else to pause..."
Dim As String key
Dim As Integer active = -1
Do
key = Inkey ( )
If ( Len ( key) > 0 ) Then
If ( key = Chr ( 27 ) ) Then
Exit Do
End If
If ( active) Then
alSourcePause( source)
active = 0
Else
alSourcePlay( source)
active = -1
End If
End If
Loop
alSourceStop( source)
''
'' Clean up
''
alDeleteBuffers( 1 , @buffer)
alDeleteSources( 1 , @source)
alutExit( )
ページ歴史:2015-07-01 08:18:15
日本語翻訳:WATANABE Makoto、原文著作者:SirMud