Open AL script

Hi Phil,

I did that using Ronie’s OpenAL binding and Merwann’s wav parser back in 2014-2015:

MCSmalltalkhubRepository
owner: ‘ronsaldo’
project: ‘OpenAL’

MCSmalltalkhubRepository
owner: ‘MerwanOuddane’
project: ‘WAVParser’

I did things such as (build yourself something derived from this code I did not check if it works):

MyClass>>example
WAVParser wavFromStream: (‘resources/music/spellNoise.wav’ asFileReference readStream binary readStream).
contextAttributes := ALContextAttributes new.
device := OpenALC openDefaultDevice.
context := device createContext: contextAttributes asList.
context process.
context currentDuring: [
“Create the buffer”
buffer := self makeBufferFromHeader: wav header data: wav data asByteArray.
“Create the source”
source := OpenAL genSource.
OpenAL sourcei: source param: AL_BUFFER value: buffer.
“Play the source”
OpenAL sourcePlay: source.
“Play for sometime ”
(Delay forSeconds: wav header soundDuration) wait.
“Delete the source and the buffer”
OpenAL deleteSource: source;
deleteBuffer: buffer
].
OpenALC nullCurrentContext.
context destroy.
device close.

MyClass>>makeBufferFromHeader: header data: data
| buffer |
buffer := OpenAL genBuffer.
OpenAL bufferData: buffer format: (self readFormatFromHeader: header) data: data size: data size freq: header sampleRate.
^ buffer

MyClass>>readFormatFromHeader: header
^ header channels = 1
ifTrue: [
header bitsPerSample = 8
ifTrue: [ AL_FORMAT_MONO8 ]
ifFalse: [ AL_FORMAT_MONO16 ] ]
ifFalse: [
header bitsPerSample = 8
ifTrue: [ AL_FORMAT_STEREO8 ]
ifFalse: [ AL_FORMAT_STEREO16 ] ]

I am pretty sure with a little work those things could work again. I have never succeeded in playing mp3 files from Pharo though (but I’m on mac and I remembered trying solutions that did not work on Mac but may work on other OS).

Have fun guys 🙂

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: