Friday, August 10, 2012

Setting defaults for UIView subclasses

Hey! Cool! You can set default fonts and stuff for UIView subclasses using something fancy called the appearance proxy. You ask the class for the proxy like this;

[UILabel appearance]

And then set whatever values on that you want, like


[[UILabel appearance] setFont:[UIFont fontWithName:@"Miso-Bold" size:15]];

Then any UILabel you make will be created with the font Miso Bold, instead of the default.

Wednesday, July 4, 2012

Tackling Core Audio

I've been working with Alex Wiltchko's Novocaine, which works nicely as a pain-reducing wrapper for lots of basic core audio stuff. Unfortunately, it's not idiot-proof, and I've made at least one idiot-level mistake with it.

Alex very nicely packaged up an AudioFileWriter class with the project which works great for me in the simulator, but fails unpredictably when I try to use it on a device. So for me, anyway, it seems that dream of avoiding touching core audio, and the dreaded AudioStreamBasicDescription has not arrived.

Today I'm playing around with ExtAudioFileWriteAsync, seeing which sorts of settings will work for me.

Writing to AIFF is working without too much trouble, but I'm having a heck of a time writing to m4a. It looks as if ExtAudioFileWriteAsync is sensitive about the number of frames passed when writing files of format kAudioFormatMPEG4AAC. When passing a buffer of 10,000 frames, I get a crash with this error code: -66567.

For anyone reading this who can't make sense of these error codes (like me, until yesterday), you can search the headers of whichever framework you think the error originated from for the code. Here's some explanation.

Anyway, -66567 resolves to kExtAudioFileError_MaxPacketSizeUnknown. I'm unable to find any documentation indicating just what this message means.

Now, when I reduce the number of frames I'm passing to ExtAudioFileWriteAsync to 512, the error message goes away, but the resulting file is only 28 bytes long and is unplayable. This is only in on my iPad. All works fine in the simulator.

Now I'm simplifying and trying to work with the synchronous version of ExtAudioFileWrite. This is failing immediately with kExtAudioFileError_MaxPacketSizeUnknown, even when I give it a very small number of frames (100).

This StackOverflow post indicates that there are some properties that are required to be set. I'm not sure that I read the documentation the same way this poster does, however it seems that in their case, setting kExtAudioFileProperty_CodecManufacturer solved a problem.

Monday, May 7, 2012

Spent four hours on FilePlay today. This app is going to involve quite a lot of hard work. My current status is this: FilePlay successfully streams multiple files from disk. On the iPhone it can handle about three stereo files. Not very impressive. Discovered the files Jay gave me were 24-bit. So I'll be able to stream more like 4 files easily. Still not super impressive. Next step is to be able to swap out one file for another mid-play. Tried doing this and am getting errors in fseek. Blowing off yoga in favor of programming. Went for a 25 minute walk today though.

Thursday, May 3, 2012

Cheap and Deep app progress

Spent most of the day today working on FilePlay, a class that's part of EZPlug and streams files from disk and into an EZPlug network. It's just a little bit trickier than I can easily wrap my head around. Running in to multiple problems: memory issues with no warnings in XCode, and niggly little logic bugs of the type that crop up when I work with juggly-type code. Somehow, anything involving getting to the end of something and then jumping back to the beginning always gives me trouble. I'm going back and forth a bit about whether I should just use Apple's code, because surely they know what they're doing, and surely I don't. But generally, I'm settling on the idea that FilePlay is something I'll be using again and again, and it's worth taking the time to get it right, and to make sure that any time I want to do this stuff in the future, it will be very easy. Very E-Z.