Re: How to get the number of bytes per packet of the default output device?
Re: How to get the number of bytes per packet of the default output device?
- Subject: Re: How to get the number of bytes per packet of the default output device?
- From: Jeff Moore <email@hidden>
- Date: Fri, 29 Jan 2010 10:40:45 -0800
On Jan 29, 2010, at 10:19 AM, cparodi.ugemi wrote:
> Hi all, my name is Charles, I've just subscribed and already have one question for you Coreaudio gurus.
>
> I know how to determine the ID of the Default Output device, and I also know how to get its nominal sample rate; since I want to generate some basic waveform sounds by means of a callback render function, I also need to know the buffer size and the number of bytes per packet, so that I can then loop at a given number of samples calculated as buffer size / packet size.
You also need to know whether or not the samples are floating point or integer and how many bits deep each sample in the packet is as well as how many channels of data there are. Plus, you will also need to know what the stream layout of the device is, etc.
> I want to do that in the simplest possible way to avoid headaches with Audio Units and the whole list of Audio Streams etc.: I just want to ask the Default Output device to please tell me what is its current buffer size and number of bytes per packet.
First, AUHAL, the AudioUnit wrapper for the HAL actually does a lot of things for you to make dealing with stuff like this a great deal simpler. So, avoiding the AU approach isn't saving you any work. In fact it will increase the amount of work you need to do because you will have to duplicate the nifty things that AUHAL does like flattening the stream layout, handling format conversions, etc. We highly recommend
Second if you skip using AUHAL, you necessarily will have to get your hands very dirty and work the the AudioStream objects on an AudioDevice to discover the format for each stream. You will also need to do all the massaging to get your data into the form that the hardware wants.
> Is property kAudioDevicePropertyBufferFrameSize of any help with this?
This property tells you how many sample frames of data will be delivered/asked for in your IOProc.
> And is kAudioDevicePropertyBufferFrameSize (that gives me the buffer size right?) deprecated?
No.
> Any suggestions please? I am really struggling with this.
Getting the stream format of an AudioDevice is fairly involved. Here's the general algorithm in pseudo-C:
get the list of streams in the direction you are interested in from the device (kAudioDevicePropertyStreams).
for each stream in the returned list
get the virtual stream format for each stream (kAudioStreamPropertyVirtualFormat)
When you are done, you will have a list of AudioStreamBasicDescription structs that are filled out to tell you what format the data needs to be supplied in your IOProc.
Finally to wrap this up, I want to point out that we have APIs like the AudioQueue in addition to Audio Units and the HAL for getting audio data in and out of the system. The AudioQueue is a higher level API whose job it is to smooth over a lot of the complexities that the lower level APIs have. It is probably more suited to the sort of things you are trying to do. I encourage you to check it out.
--
Jeff Moore
Core Audio
Apple
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden