• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Callback problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Callback problems


  • Subject: Callback problems
  • From: "Frances Buck" <email@hidden>
  • Date: Sat, 21 Feb 2004 17:45:12 +0000

Hello,

I am new to this mailing - list and new to CoreAudio - Thing.
I start to stream a waveFile without a header to see if I get the idea of the AudioUnit and its Callback.
I can hear the music but I do get some small crackle above the music.
So I think I am doing something wrong.

I hope that someone can help me.


Thank you,
Frances


Here ist the Code

FILE* waveFile;
char buffer[8192]; // if I try 4096 (or smaller) I get into trouble
long bytes_read;

OSStatus MyRenderer(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, 4
const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber,
UInt32 inNumberFrames, AudioBufferList *ioData)
{
bytes_read = fread(buffer, 1, 8192, waveFile);

memcpy(ioData->mBuffers[0].mData, buffer, bytes_read);
ioData->mBuffers[0].mDataByteSize = bytes_read;

return noErr;
}


void ThePlayFunction()
{
OSStatus err = noErr;
AudioUnit gOutputUnit;

// The Wave - File without a Header
waveFile = fopen("test.wav" , "rb");

// Open the default output unit
ComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;

Component comp = FindNextComponent(NULL, &desc);

err = OpenAComponent(comp, &gOutputUnit);

err = AudioUnitInitialize(gOutputUnit);

// Set up a callback function to generate output to the output unit
AURenderCallbackStruct input;
input.inputProc = MyRenderer;
input.inputProcRefCon = NULL;

err = AudioUnitSetProperty (gOutputUnit, kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Input, 0, &input, sizeof(input));

// We tell the Output Unit what format we're going to supply data ...
AudioStreamBasicDescription streamFormat;
streamFormat.mSampleRate = 44100.0;
streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
streamFormat.mBytesPerPacket = 4;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerFrame = 4;
streamFormat.mChannelsPerFrame = 2;
streamFormat.mBitsPerChannel = 16;

err = AudioUnitSetProperty (gOutputUnit, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, 0, &streamFormat,
sizeof(streamFormat));

// Start the rendering
err = AudioOutputUnitStart (gOutputUnit);

do{
}
while (true);

//AndTheRest...
}

_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger http://www.msn.co.uk/messenger
_______________________________________________
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.
  • Follow-Ups:
    • Re: Callback problems
      • From: Philippe Wicker <email@hidden>
  • Prev by Date: Re: USB/laptop interfaces?
  • Next by Date: Re: Callback problems
  • Previous by thread: Re: Cocoa AU hosts Edit menu
  • Next by thread: Re: Callback problems
  • Index(es):
    • Date
    • Thread