Re: implementing an AudioIOFunction
Re: implementing an AudioIOFunction
- Subject: Re: implementing an AudioIOFunction
- From: Josh Rodatus <email@hidden>
- Date: Sun, 24 Dec 2006 22:17:58 -0500
Thanks, yes I checked that.
Actually I figured out the answer a little while ago, while inspecting how IOAudioStream.cpp calls its AudioIOFunctions. Apparently if it finds that it has one or more IO functions to call, it skips running the clipOutputSamples method and calls them instead. So all I had to do was run clipOutputSamples myself and the audio passes through just fine.
For reference, here's the working IO function:
IOReturn ImpluseAudioIOProc(void *mixBuf, void *sampleBuf, UInt32 firstFrame, UInt32 numFrames, IOAudioStreamFormat *streamFormat, IOAudioStream *audioStream)
{
int fstate;
struct iovec iovec;
struct uio uio;
int numChannels = streamFormat->fNumChannels;
int sampleSize = streamFormat->fBitWidth / 8;
audioStream->audioEngine->clipOutputSamples(mixBuf, sampleBuf, firstFrame, numFrames, streamFormat, audioStream);
if (gSock != NULL) {
iovec.iov_base = (char *)&((signed short *)sampleBuf)[firstFrame * numChannels];
iovec.iov_len = sampleSize * numChannels * numFrames;
uio.uio_iov = &iovec;
uio.uio_iovcnt = 1;
uio.uio_offset = 0;
uio.uio_resid = iovec.iov_len;
uio.uio_segflg = UIO_SYSSPACE;
uio.uio_rw = UIO_WRITE;
uio.uio_procp = NULL;
fstate = thread_funnel_set(network_flock, TRUE);
sosend(gSock, NULL, &uio, NULL, NULL, 0);
thread_funnel_set(network_flock, fstate);
}
return kIOReturnSuccess;
}
I'm working on a project called Impulse, a music beat visualizer. It gets its source audio from the now-finished kernel extension. So far it's only using a basic beat detection algorithm I prototyped awhile back, and no graphics yet - but it sure gets the Terminal rocking! : )
Thanks for your help!
~ Josh
On Dec 24, 2006, at 8:34 PM, Herb Petschauer wrote:
This may not help you at all (I'm just killing time waiting for my turn at the oven on Xmas Eve :-) ). Have you looked at /Developer/Examples/Kernel/IOKit/Audio/PhantomAudioDriver/PhantomAudioEngine.cpp? Search on AudioIOFunction and you will get a hit. This is probably old news but thought I'd chime in...
Cheers,
-H.
On 23/12/06, Josh Rodatus <email@hidden> wrote:
I am writing a KEXT that taps system audio output by first locating the
output IOAudioStream object in the registry, and then calling its
setIOFunction() method to install a custom AudioIOFunction in the
pipeline.
The typedef for an AudioIOFunction as declared in IOAudioStream.h is:
typedef IOReturn (*AudioIOFunction)(const void *mixBuf, void
*sampleBuf, UInt32 firstSampleFrame, UInt32 numSampleFrames, const
IOAudioStreamFormat *streamFormat, IOAudioStream *audioStream);
The problem is that installing my IO function prevents any output audio
from reaching the device. All I can figure is that an AudioIOFunction
is expected to copy a section of mixBuf into sampleBuf, or vice versa.
Unfortunately my attempts copying the samples from one buffer to the
other only result in distorted output audio.
Here's how I'm copying it:
IOReturn AudioIOProc(const void *mixBuf, void *sampleBuf, UInt32
firstSampleFrame, UInt32 numSampleFrames, const IOAudioStreamFormat
*streamFormat, IOAudioStream *audioStream) {
{
void *samples = (float *)mixBuf + (firstSampleFrame *
streamFormat->fNumChannels);
size_t size = numSampleFrames * sizeof(float) *
streamFormat->fNumChannels;
bcopy(samples, sampleBuf, size);
return kIOReturnSuccess;
}
I tried Googling for source code and documentation, to no avail. If
anyone could give some advice or instruction on how to properly
implement an AudioIOFunction, I would be most grateful.
Thanks,
Josh
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden )
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden