Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MTCoreAudio quickie



i can think of three things that might cause you grief.

#1 most important: the data you're writing out is 32-bit floating point, which i didn't think was a format supported by LAME.

#2 if you have more than one stream on your audio device, this will write the buffers for each stream sequentially, rather than interleaving all the channels. there's no communication of this chunking to LAME, so it won't know when you've switched streams.

#3 similar issue with channels -- each frame of audio has the samples for each channel interleaved. so LAME needs to know how many channels are represented in your saved file.

also, an area that might cause trouble is that doing -appendBytes:length: in your IOProc could cause a memory (re)allocation and potentially large data copies. either of those could cause an audio overload, which would cause dropouts in the recording.

you can use audio_copy() (in MTConversionBuffer.m) to interleave however many streams your input device has into one wide buffer before you write it into your goes-to-a-file buffer. if you need to convert from floating point to some other format for LAME (like 16-bit signed big-endian), you can use an AudioConverter, or do it manually.

as long as your NSMutableData buffer is initially allocated with enough space to hold however much audio you're going to put into it, you won't have to worry about reallocations/copies and the potential overload that could cause. however, you may be talking about a considerable amount of memory if you want to hold a large sample. one approach (of many many possibilities) you could take to allow for recordings of arbitrary length would be

use an MTCircularQueue with some reasonable length, like several seconds' worth at your sample rate/number of channels

interleave any multiple input streams into one intermediate stream buffer, and write that (using -[MTCircularQueue writeBytesWithoutBlockingFrom:length:]) to the queue in your IOProc

in a different thread, have some while(notDone) loop that uses the blocking read method (-[MTCircularQueue readBytesTo:length:]) to read some reasonable number of bytes to a write-to-disk buffer, (potentially) change its format for LAME, and write to disk. repeat til the queue is empty and you're done recording.

hope this helps.

-mike


On Wednesday, September 24, 2003, at 08:32 AM, Rick Bourner wrote:

Just a quick question from a newb -

I'm creating my first sound app for OS X. It's been hell so far and it
seems to be the same for most people trying
to record sound for the first time.

The venerable MTCoreAudio framework helped. Within a day I was
recording from various input sources - great!

Within my IOProc callback function I do the following for each input
received:

int i;
long size;
for ( size = 0, i = 0; i < inInputData->mNumberBuffers; i++ )
[_data appendBytes: inInputData->mBuffers[i].mData length:
inInputData->mBuffers[i].mDataByteSize ];


where _data is a simple NSMutableData object. I then save the
NSMutableData to disk
and convert to MP3 using lame.

It works but the recording has **loads** of noise.

It would be great if you could help me get a crisp recording. If I can
get it working I'll
release the code for the other newb's to core-audio.

Cheers,

Rick.
_______________________________________________
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.
_______________________________________________
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.

References: 
 >MTCoreAudio quickie (From: Rick Bourner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.