Saturday, July 31, 2010

In which I chronicle my descent into vim

Remember when I said, two posts ago, that IDE's were the only sane way to write code?  Well, maybe.  But I'm starting to think it may be a good idea to learn vim or emacs, like really learn them, because:
- sometimes you just need to edit text that's not code.  Maybe more often than code.
- IDE's are still great for autocomplete and stuff, especially in Java.  But the higher-level the language, the less good they get.  Like python or javascript.  When it becomes a cute little syntax checker instead of a big auto-complete auto-import magic-everything Blendtec mixer ("will it refactor? that is the question."), then the overhead starts to kill it.  Speaking of which:
- the overhead in IDE's can be killer.  Especially on a big project.  Especially especially over NX or VNC or Remote Desktop or something.
- I can imagine vim/emacs as a web app (and therefore as the future).  I can't imagine Eclipse in the cloud yet.

- learning keyboard shortcuts for anything makes you instantly more badass

And given that, I'm going for vim, because I like its style: super minimal, instead of trying to do everything.  (if I want it to do that, I'll use an IDE, where ctrl-c is copy and ctrl-s is save.)  The dreaded modes are not really that daunting: you're just always in command mode, and sometimes you can press i to blip into insert mode, but only for a minute and then you escape back out into command mode.  Text reading is more common than inserting text.

So far, I think my favorite quirk is "." (do whatever you just did, again).

Tuesday, July 27, 2010

Android AudioRecord

AudioRecord is an Android class that lets you record audio and fiddle with it in real time. MediaRecorder is what you want if you'd rather save the audio to a file and deal with it later.

You'll notice that AudioRecord's constructor takes 5 parameters: audioSource, sampleRateInHz, channelConfig, audioFormat, and bufferSizeInBytes. audioSource is reasonable enough; I used MediaRecorder.AudioSource.MIC. For bufferSizeInBytes, you can use the getMinBufferSize() function. (then you might want to multiply the result by 5 or 10 or something.) But the other 3, you kind of have to guess.

I dealt with this for a while, found something that worked on my Nexus One (2.2), launched an app, and then found out that it crashed the Droid (2.1-update1) on startup. So to save you all a similar experience, here's what I know:

44100 hz, AudioFormat.CHANNEL_IN_MONO, and AudioFormat.ENCODING_PCM_16BIT is the one and only configuration guaranteed to work on all phones. The Android Compatibility Test Suite (that phone makers have to run their phones through before they release them) guarantees this (see AudioRecordTest).

Sample rates of 44100, 22050, 16000, 11025, and 8000 hz (and probably others) work on the Nexus One and Droid. Annoyingly, only 8000 hz works on the emulator (2.1-update1), and by "works", I mean "doesn't crash". I haven't tested that it actually records anything useful.

CHANNEL_IN_STEREO works on the Nexus One, but not on the Droid.

This is all correct as of ... about a month ago. Hopefully nothing drastic has changed since then. Make sure you've put the right permission (RECORD_AUDIO) in your AndroidManifest.xml, and good luck recording audio!

Friday, July 23, 2010

Something tells me it's a good idea to have a programming blog.

For one thing, I hear blogs make you rich. Second, it's good discussion at parties. (though this goes without saying.) Third, I'm shooting for tenure, and this really impresses the committee. Fourth, programming blog posts are instant laughs, and a joke a day keeps the doctor away. Speaking of health, Benefit Number Five of programming and blogging is the sweet bulging biceps you get from coding, which in turn helps with Goal Six: aikido mastery. Seventh, a thorough understanding of programming helps you realize and comprehend the oneness of all things, so hopefully we can all learn together here.

I'll not prescribe too much what this blog will be. It'll sort of chronicle my adventures in coding, which right now are making friggin' sweet Web App Frontends with Java and Javascript and a bunch of Google tools at work, and making at least marginally competent Android apps at home.

Let's get the culture wars out of the way too: IDE's are the only goddamn reasonable tools to write code, the higher-level language the better, and git is the stupid content tracker. Oh, and well I'm gonna be rather biased in a Googley direction, although I'll try (try!) to keep that in check. Don't want to get all fanboy about it; it's only the best big software company on the planet.

(and in case you're wondering about perk number 8 of a programming blog: it's the chicks.)