Re: SoundConverterConvertBuffer() is broken on Mac OS X
Re: SoundConverterConvertBuffer() is broken on Mac OS X
- Subject: Re: SoundConverterConvertBuffer() is broken on Mac OS X
- From: Andrew Taylor <email@hidden>
- Date: Thu, 13 Dec 2001 12:55:02 -0500
Sorry for the long message below, but it explicitly shows what is
different with Mac OS X vs Mac OS 9.
At 3:50 PM -0800 12/12/01, Jeff Moore wrote:
on 12/12/01 2:38 PM, Andrew Taylor <email@hidden> wrote:
For Mac OS X, interrupt callbacks don't seem to work.
Unfortunately, there is a bug in the sinp component that sits on top of the
HAL that prevents this from working.
So I rewrote
the code to use a completion routine, which works, but the resulting
data coming out of SoundConverterConvertBuffer is wrong. It is as if
the voice played back is very very very slow.
Has anybody else encountered this?
Has something changed in the data that is delivered from SPBRecord?
Are different parameters required for SoundConverterConvertBuffer() ?
The components the SoundConverter uses are pretty much the same code on X as
they are on 9. This behavior has not come up in any testing. Can you distill
the code down and provide an example?
Your answer below sparked a memory and I just confirmed it. I had not
thought to verify the difference before.
The default compression on Mac OS 9 is 'NONE'. At least that is what
I see when I ask the input device.
The default compression on Mac OS X is 'twos'.
As part of the initialization process we set the compression to
'NONE', but then our subsequent check of that setting shows it to be
'twos' anyway (on Mac OS X). There is no error reported when setting
compression to 'NONE'.
In addition the number of channels stays at two in Mac OS X (no error
reported) and Mac OS 9 succeeds when we set the number of channels to
1.
So:
compression - X -'twos' vs 9 - 'NONE'
num channels - X - 2 vs 9 - 1
I imagine that this affects the data that is delivered in the sound
buffers and therefore why SoundConverterConvertBuffer does not work
as expected.
Now what can I do about it?
Thanks.
-------------------------------------------
Code that I used to determine this below.
#include <Sound.h>
#include <SoundInput.h>
void TestSound();
void TestSound()
{
long SoundInRefNum = -1;
short originalInputSource;
long originalSampleRate;
short originalSampleSize;
short originalTwosComplement;
short originalNumChannels;
OSType originalCompression;
short originalContinuous;
short originalAGCOnOff;
long DeviceBufferInfo;
long desiredSampleRate = rate44khz;
short desiredSampleSize = 16;
short desiredTwosComplement = 1;
short desiredNumChannels = 1;
OSType desiredCompression = 'NONE';
short desiredContinous = 1;
short desiredAGCOnOff = 0;
long actualSampleRate;
short actualSampleSize;
short actualTwosComplement;
short actualNumChannels;
OSType actualCompression;
short actualContinuous;
short actualAGCOnOff;
short on = 1;
short off = 0;
OSErr err;
err = SPBOpenDevice("\p", siWritePermission, &SoundInRefNum);
//FIND OUT WHAT IS THERE TO BEGIN WITH
err = SPBGetDeviceInfo(SoundInRefNum, siInputSource,
&originalInputSource );
// (originalInputSource returns X - 1, 9 - 1)
err = SPBGetDeviceInfo(SoundInRefNum, siSampleRate,
&originalSampleRate );
// (originalSampleRate returns 0xAC440000 - 44khz everywhere)
err = SPBGetDeviceInfo(SoundInRefNum, siSampleSize,
&originalSampleSize );
// originalSampleSize returns 16 everywhere
err = SPBGetDeviceInfo(SoundInRefNum, siTwosComplementOnOff,
(Ptr) &originalTwosComplement);
// X - 1, 9 - 1
err = SPBGetDeviceInfo(SoundInRefNum, siNumberChannels,
&originalNumChannels );
// (originalNumChannels returns 2 everywhere)
err = SPBGetDeviceInfo(SoundInRefNum, siCompressionType,
&originalCompression );
// X - 'twos', 9 - 'NONE'
err = SPBGetDeviceInfo(SoundInRefNum, siContinuous, (Ptr)
&originalContinuous);
// X - 0, 9 - 0
err = SPBGetDeviceInfo(SoundInRefNum, siAGCOnOff, (Ptr)
&originalAGCOnOff);
// (this returns error -231 on Mac OS X, but succeeds on Mac OS 9)
err = SPBGetDeviceInfo(SoundInRefNum, siDeviceBufferInfo,
&DeviceBufferInfo ); // size of input buffer
// X - 4096, 9 - 16384
//SET IT THE WAY WE WANT IT
err = SPBSetDeviceInfo(SoundInRefNum, siLevelMeterOnOff, (Ptr) &on);
err = SPBSetDeviceInfo(SoundInRefNum, siSampleRate, (Ptr)
&desiredSampleRate);
err = SPBSetDeviceInfo(SoundInRefNum, siSampleSize, (Ptr)
&desiredSampleSize);
err = SPBSetDeviceInfo(SoundInRefNum, siTwosComplementOnOff,
(Ptr) &desiredTwosComplement);
err = SPBSetDeviceInfo(SoundInRefNum, siNumberChannels, (Ptr)
&desiredNumChannels);
// X - -201 error, 9 - succeeds
err = SPBSetDeviceInfo(SoundInRefNum, siCompressionType,
(Ptr) &desiredCompression);
err = SPBSetDeviceInfo(SoundInRefNum, siContinuous, (Ptr)
&desiredContinous);
err = SPBSetDeviceInfo(SoundInRefNum, siAGCOnOff, (Ptr)
&desiredAGCOnOff);
// (this returns error -231 on Mac OS X, but succeeds on Mac OS 9)
//WHAT ACTUALLY HAPPENED
err = SPBGetDeviceInfo(SoundInRefNum, siSampleRate, (Ptr)
&actualSampleRate);
// actualSampleRate returns 0xAC440000 = 44khz
err = SPBGetDeviceInfo(SoundInRefNum, siSampleSize, (Ptr)
&actualSampleSize);
// X - 16, 9 - 16
err = SPBGetDeviceInfo(SoundInRefNum, siTwosComplementOnOff,
(Ptr) &actualTwosComplement);
// X - 1, 9 - 1
err = SPBGetDeviceInfo(SoundInRefNum, siNumberChannels, (Ptr)
&actualNumChannels);
// X returns 2 --THIS IS DIFFERENT FROM WHAT WAS SET
// MAC OS 9 - 1
err = SPBGetDeviceInfo(SoundInRefNum, siCompressionType,
(Ptr) &actualCompression);
// X - compression returns 'twos' -- THIS IS DIFFERENT FROM
WHAT WAS SET
// MAC OS 9 - 'NONE'
err = SPBGetDeviceInfo(SoundInRefNum, siContinuous, (Ptr)
&actualContinuous);
// X - 1, 9 - 1
err = SPBGetDeviceInfo(SoundInRefNum, siAGCOnOff, (Ptr)
&actualAGCOnOff);
// (this returns error -231 on Mac OS X, but succeeds on Mac OS 9)
//RESTORE ORIGINAL SETTINGS
err = SPBSetDeviceInfo(SoundInRefNum, siInputSource,
&originalInputSource );
err = SPBSetDeviceInfo(SoundInRefNum, siSampleRate,
&originalSampleRate );
err = SPBSetDeviceInfo(SoundInRefNum, siSampleSize,
&originalSampleSize );
err = SPBSetDeviceInfo(SoundInRefNum, siTwosComplementOnOff,
(Ptr) &originalTwosComplement);
err = SPBSetDeviceInfo(SoundInRefNum, siNumberChannels,
&originalNumChannels );
err = SPBSetDeviceInfo(SoundInRefNum, siCompressionType,
&originalCompression );
err = SPBSetDeviceInfo(SoundInRefNum, siContinuous, (Ptr)
&originalContinuous);
err = SPBSetDeviceInfo(SoundInRefNum, siAGCOnOff, (Ptr)
&originalAGCOnOff);
err = SPBCloseDevice(SoundInRefNum);
}
--
---------------------------
Andrew Taylor
Founder/CTO
MacSpeech, Inc.
<
http://www.macspeech.com>