Re: Working with Audio
Re: Working with Audio
- Subject: Re: Working with Audio
- From: Todd Heberlein <email@hidden>
- Date: Wed, 27 Mar 2002 14:50:20 -0800
On 3/26/02 8:01 PM, "Matthew Johnson" <email@hidden> wrote:
>
One problem though is the playback is slowed down dramtically It
>
sounds like a different sample rate.
I initially had the opposite problem: I sounded like the chipmunks from
Alvin and the Chipmunks. In my case, it was because I initially did not
account for the difference between the one channel microphone and the two
channel speaker.
I did not have to set the sampling rates, I just needed to duplicate the
data sent to the output. However, you can set various properties for an
audio device with the AudioDeviceSetProperty() function - my guess is that
you should use the kAudioDevicePropertyStreamFormat flag.
Below is a snippet of code (reformatted) from the DisplayHALDeviceInfo.c
source code that Apple provides, along with the output it generated when I
ran the program. (Note, the_format variable changes name to inFormat in the
function called to display it).
My guess is you can call AudioDeviceGetProperty () once to get the
information, modify the sample rate to the desired value, and then call
AudioDeviceSetProperty() to reset the sample rate to the desired value.
The full description for the AudioStreamBasicDescription data structure can
be found in
/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudioTypes.h
on your system.
memset(&the_format, 0, sizeof(AudioStreamBasicDescription));
theStatus = AudioDeviceGetProperty(
inDeviceID, 0, 1,
kAudioDevicePropertyStreamFormat,
&the_size, &the_format);
PrintLine(" Current input format");
DisplayFormat(&theFormat);
Print4CharCode(" Format ID: ", inFormat->mFormatID);
PrintHex (" Format flags: ", inFormat->mFormatFlags);
PrintFloat (" Sample rate: ", inFormat->mSampleRate);
PrintInt (" Bytes per packet: ", inFormat->mBytesPerPacket);
PrintInt (" Frames per packet: ", inFormat->mFramesPerPacket);
PrintInt (" Bytes per frame: ", inFormat->mBytesPerFrame);
PrintInt (" Channels per frame: ", inFormat->mChannelsPerFrame);
PrintInt (" Bits per channel: ", inFormat->mBitsPerChannel);
// Format ID: lpcm
// Format flags: 0xB
// Sample rate: 44100.000
// Bytes per packet: 4
// Frames per packet: 1
// Bytes per frame: 4
// Channels per frame: 1
>
Now I have a array of floats being the audio data I assume I can use
>
libsndfile to determine what format to save the
>
data as?
Ha! This is much better than what I was looking at. I pulled down specs
for AIFF and was planning on my own coding effort. This looks like a much
better solution.
Todd
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.