PortAudio Port Help Request
John M McIntosh
johnmci at smalltalkconsulting.com
Wed Nov 2 00:02:21 UTC 2005
I'll note you can choose to either make:
A lightweight plugin that interfaces to a platform-agnostic api that
requires you to use lots of platform specific C code.
A heavyweight class(es) that manages data and passes data only to a
plugin which makes the DLL API call, no pre/post C code wrapping api
call.
or a plugin that abuses self cCode: inSmalltalk: and makes the api
calls required and has no external C code, except for say a DLL
library of some sort.
Or of course use FFI.
In some respects exposing the RAW DLL API in a plugin then having a
heavyweight class drive it is best because any changes to logic can
mostly be done in smalltalk, otherwise
with a platform agnostic API you get to post and mange change via
external C code and publish plugins forever...
So for example:
primitiveMPEG3AudioSamples: fileHandle stream: aNumber
| file result |
"long mpeg3_audio_samples(mpeg3_t *file, int stream)"
self var: #file declareC: 'mpeg3_t * file'.
self primitive: 'primitiveMPEG3AudioSamples'
parameters: #(Oop SmallInteger).
file := self mpeg3tValueOf: fileHandle.
file = nil ifTrue: [^0].
aNumber < 0 ifTrue: [interpreterProxy success: false. ^nil].
aNumber >= (self cCode: 'mpeg3_total_astreams(file)') ifTrue: [
interpreterProxy success: false. ^0.
].
self cCode: 'result = mpeg3_audio_samples(file,aNumber)'.
^result asOop: Float
I could have made the check for file nil, and the check for stream
part of the smalltalk code that interfaces to the plugin so that I
would only have
primitiveMPEG3AudioSamples: fileHandle stream: aNumber
| result |
"long mpeg3_audio_samples(mpeg3_t *file, int stream)"
self var: #file declareC: 'mpeg3_t * file'.
self primitive: 'primitiveMPEG3AudioSamples'
parameters: #(Oop SmallInteger).
self cCode: 'result = mpeg3_audio_samples(file,aNumber)'.
^result asOop: Float
Note we return the samples as a Float to avoid the issue with small
versus large integers. I guess today we could return a 32bit Integer,
but I believe those methods was added later when we were working on
the large file indexing support.
On 1-Nov-05, at 2:01 PM, tim Rowledge wrote:
>
> Wise padawan. Make sure it is nice and clean, use a subclass of
> SmartSyntaxInterpreterPlugin if possible and little by little you
> can duck-nibble the problem to death.
>
>
--
========================================================================
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
========================================================================
===
More information about the Squeak-dev
mailing list
|