1 vs. 2 processors
1 vs. 2 processors
- Subject: 1 vs. 2 processors
- From: Steve Checkoway <email@hidden>
- Date: Tue, 20 Jul 2004 16:26:24 -0700
I have a very strange problem involving single processor computers.
A little background first. The project that I'm working on is StepMania
(
http://sf.net/projects/stepmania), a DDR simulator for Mac OS X,
Linux, Windows, and when the planets align, the moon is full, and it's
a Tuesday, it works on Xbox. For those that don't know, DDR (or Dance
Dance Revolution) is a music game where the player presses directional
arrows on a platform while "dancing" to the music. The arrow presses
coincide with flashing arrows on screen scrolling up to meet receptor
arrows. Since DDR, and thus StepMania, is a timing based game, the
arrows scroll according to the position of the playing music.
Since we use many different methods of outputting sound (alsa, oss,
Direct Sound, CoreAudio), there is an abstracted meaning of sound. Each
sound driver has its own conception of position that it reports to
another part of the application which converts each driver's notion to
its own. As a result of this, the application knows the approximate
position of the playing sound based on how much data it has passed to
the driver. It can ask the driver what the exact position of the sound
is for the purposes of scoring. If the time returned is not within the
expected time frame, the arrows on screen jerk to the position returned
by the driver.
One final piece of background information is that there is a decoding
thread that buffers the sound so that when the CoreAudio callback is
called, it already has data to be sent to the output device.
Now here is the very strange part. If I play the game with only one
processor enabled, I get very jerky arrows on screen even though I get
several hundred frames per second of video. If I enable both
processors, I don't have this problem. This holds true for both my 2
GHz dual G5 and my 450 MHz dual G4.
Here is the code to get the playing position and the CoreAudio callback:
int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const
{
AudioTimeStamp time;
mOutputDevice->GetCurrentTime(time);
return int64_t(time.mSampleTime);
}
OSStatus RageSound_CA::GetData(AudioDeviceID inDevice,
const AudioTimeStamp *inNow,
const AudioBufferList *inInputData,
const AudioTimeStamp *inInputTime,
AudioBufferList *outOutputData,
const AudioTimeStamp *inOutputTime,
void *inClientData)
{
RageSound_CA *This = (RageSound_CA *)inClientData;
AudioBuffer& buf = outOutputData->mBuffers[0];
UInt32 dataPackets = buf.mDataByteSize >> 3;
int64_t decodePos = int64_t(inOutputTime->mSampleTime);
int64_t now = int64_t(inNow->mSampleTime);
int16_t buffer[dataPackets * (kBytesPerPacket >> 1)];
This->Mix(buffer, dataPackets, decodePos, now);
AudioConverterConvertBuffer(This->mConverter, dataPackets *
kBytesPerPacket,
buffer, &buf.mDataByteSize, buf.mData);
return noErr;
}
where mOutputDevice is declared as a CAAudioHardwareDevice* and
kBytesPerPacket is 4. Mix() mixes dataPackets * kBytesPerPacket bytes
of signed 16 bit integer linear PCM data into buffer based on the time
it will be output and the current time.
I'm CC'ing the StepMania developer's list in case I was in error about
any of this.
Thank you for any help,
Steve
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.