Help with FFI - another try

Eugene Beschastnov eugene.beschastnov at gmail.com
Wed Jul 19 11:40:37 UTC 2006


I'm not very good in C, but as I understand - yes, it is typedef for
'short*', but it's standard typedef.

Anyway, what kind of data should I use to call FFI function that
expects 'short*'?

To be more specific, C function is
__declspec(dllexport) BE_ERR    beEncodeChunk(HBE_STREAM hbeStream,
DWORD nSamples, PSHORT pSamples, PBYTE pOutput, PDWORD pdwOutput);
========================================================
For this function I made this apicall construction:
apiBeEncodeChunkHbeStream: hbeStream nSamples: nSamples pSamples:
pSamples pOutput: pOutput pdwOutput: pdwOutput
    <apicall: ulong 'beEncodeChunk' ( ulong long short* byte* long* )
module: 'lame_enc.dll'>
    ^self externalCallFailed
========================================================
And I'm trying to call it in following way:
	pMp3Buffer := ByteArray new: dwMp3Buffer.
	samples := (SampledSound fromWaveFileNamed: 'Message.wav') asSampledSound
				samples asWordArray.
	startOfChunk := 1.
	mp3Output := ByteArray new: 0.
	[startOfChunk <= samples size] whileTrue:
			[endOfChunk := startOfChunk + dwSamples - 1 min: samples size.
			buf := samples copyFrom: startOfChunk to: endOfChunk.
			startOfChunk := endOfChunk + 1.
			pDwWrite := WordArray new: 1.
			errCode := self
						apiBeEncodeChunkHbeStream: hbeStream
						nSamples: buf size
						pSamples: buf
						pOutput: pMp3Buffer
						pdwOutput: pDwWrite.
			errCode ~= self beErrSuccessful
				ifTrue:
					[self apiBeCloseStreamHbeStream: hbeStream.
					Exception signal: 'beEncodeChunk() failed (' , errCode asString , ')'].
			mp3Output addAll: (pMp3Buffer copyFrom: 1 to: pDwWrite first)].
	(FileStream fileNamed: 'Message.mp3') binary
		next: mp3Output size
		putAll: mp3Output
		startingAt: 1

hbeStream, dwSamples and dwMp3Buffer are got from FFI function
'beInitStream', which is called earlier and executed correctly.

2006/7/19, Bert Freudenberg <bert at impara.de>:
> Am 19.07.2006 um 12:33 schrieb Eugene Beschastnov:
>
> > Another question - what construction in Squeak corresponds to
> > PSHORT in C?
>
> There is no type PSHORT in C. It probably is a typedef (could be a
> macro too) which you need to lookup in the headers.
>
> I'd guess it's a 'short*'.
>
> - Bert -
>
>
>


-- 
Eugene



More information about the Squeak-dev mailing list