Showing posts with label g1. Show all posts
Showing posts with label g1. Show all posts

Saturday, December 19, 2009

Bluetooth AVRCP failure

I learned that the mysterious behavior of the AVRCP (audio/video remote control protocol) failure on my HTC G1 is actually systematic and repeatable. If the phone is sleeping when the Bluetooth device is powered on, AVRCP will not be setup correctly. However, if the phone is awake, the connection will proceed perfectly. Here is a side-by-side comparison of the logs for a successful setup (left) and a failure (right):
It appears that the failure occurs because the phone doesn't initiate the A2DP connection. Note the time differences between the "AT sent OK" and "Auto-connecting A2DP" for each scenario. I have posted this on the Cyanogenmod issues tracker:
http://code.google.com/p/cyanogenmod/issues/detail?id=611

I've also been looking through the Cyanogen code, but I haven't noticed anything yet that would cause the device's behavior to change based on whether it is sleeping or not.

Friday, November 20, 2009

Installing Bluetooth audio in my car with a Motorola s705

I am nearly done with my project to create a seamless way of playing music that is stored on my computer in my car. I bought a Motorola s705, which is a Bluetooth audio receiver with headphone jack. It is capable of operating as a standard phone headset and also capable of receiving high-quality audio. First, let me review the s705 itself:

I easily paired the s705 with my HTC G1, and was able to play music through the s705 with no trouble. The sound quality was extremely good -- significantly better than the G1's own headphone adapter. It appears the high-pass filtering that the G1 uses on its own audio stream are thankfully not also used on the bluetooth high-quality audio stream. I could not hear any compression artifacts, and the sound quality remained top-notch as I walked up to about 15 feet away from the phone. I did not test the s705's battery life. I accidentally turned on the FM radio a few times, and I wish that feature could be disabled. The only negative thing is that the s705 and G1 sometimes do not connect to each other after being separated, then brought back together. Sometimes, they will only establish a phone audio connection and not a high-quality (A2DP) connection. Turning the phone off and on (or going into airplane mode and back) always fixes the problem. Turning the s705 off and on sometimes fixes the problem.



So after I decided the s705 would probably do the job, I took it apart (of course). I needed a way to remotely control the s705 power (to have it turn on everytime I started the car, and off when I shut car off), and also a way to allow it to charge its own battery while not running the car battery down.

In order to turn the s705 on or off, the power switch must be held down for three seconds. One side of the power switch would go high (about 4 volts) when the switch was pressed. Thus, I could control the device's power state by sending it a 4 volt pulse that lasted three seconds. My first plan was to use an Atmel AVR microcontroller and use a feedback circuit so that the AVR would know whether the unit was on or off. I had difficulty finding a reliable logic signal on the s705 circuit board that could be used as an on/off indicator. I was also having difficulty with the Atmel IDE that night, so I scrapped it, and decided to use two basic timer circuits (a 555 and 558 chip). The circuits send a pulse when the car turns on, and another pulse when the car turns off. It's possible for the device to become out of sync, but I don't think it will happen. The circuit uses a MOSFET whose gate is driven by a capacitor-resistor network and charged by the "on" signal from the car stereo. This way, the device will draw essentially zero current after the gate discharges and the MOSFET turns off. I've configured the capacitor value so that the circuit stays powered for 15 seconds after the car turns off.


I also wanted to sneak the audio wires out the back of the unit instead of using the headphone jack on top. I figured this would look a lot nicer when I mounted the unit on my car's dashboard.




I used the s705 shirt clip to attach it to an unused switch plate in my 1992 Honda Civic. It fits right next to the rear defroster switch.

The row of header pins have the following signals:
1. gnd
2. +12V always on from the battery
3. +5V signal from car stereo when the aux input is active
4. audio signal gnd
5. audio left
6. audio right

The audio connections go to my car stereo "aux input" which I described in another post:






The shirt clip was ABS plastic as was the switch dummy plate. I used some Weld-On #16 glue which will very securely bond ABS plastic.

It's a pretty clean installation. I've just finished it, and I'll let everyone know how it works in day-to-day use. So far, my tests in the driveway have been really great -- just step into the car and turn on the stereo, hit play on the s705, and the music starts. I don't even have to take the phone out of my pocket.

Tuesday, November 10, 2009

Rooting and modding an HTC Dream (Google G1)

This project all started with my plan to abandon music CDs and use my G1 phone to carry all of my music. Here's how my ideal situation would work: When I get in my car, I would like to press a button and hear a series of random songs from my music collection that is stored on my computer. Note that I didn't say anything about connecting wires, syncing, downloading, looking through settings or album lists, etc. In the ideal plan, the music would all be handled seamlessly without any thought on my mind except "play".

By the way, I have been using MediaMonkey to handle my music, and I really like it:
http://www.mediamonkey.com

The G1 is a very flexible device, so I figured this would be no problem. However, there are problems. First, the audio quality coming out of the usb->headphone jack adapter on the G1 is truly dreadful. I am not being a stuck-up about this. I mean it's just plain bad. The sound has no bass (it seems anything below 150Hz is completely gone). There are a lot of compression artifacts evident in cymbal sounds, and the high-mids are unusually harsh-sounding. Finally, the overall amount of signal coming out of the headphone jack is very low. Before anyone accuses me of using low-quality MP3, let me say that I made these MP3 myself from CDs and used 320kbit for some test files. They are good MP3 and sound perfectly fine on normal sound systems.

So, connecting the G1 to my car's sound system via a headphone jack, while slightly inconvenient may not work at all because of the low quality. This prompted me to wonder if the Android software had any control over the sound output. As a matter of fact. It does, and it's possible the designers purposefully cut everything below 150Hz for use with speech-only audio.
http://forum.xda-developers.com/showthread.php?t=517745&page=120
Ah, nothing like a 120-page thread. I'm sure it will only take a few hours to read it.

Anyway, the short story is that a developer named meltus has found three audio files in the system/etc directory of the android operating system that have some effect on the sound processing. I was intrigued and wanted to edit the files myself to see how much of the audio quality was dependent upon software. Unfortunately, the android system will not allow anyone to edit system files (even me, the owner of the damn phone). I instantly decided to "root" the phone so that I could investigate the full potential of the device.

Gaining root access is possible on the G1 by a few different ways, but the information available on the web is sketchy. There are only two groups of people who root their phones: 1. Serious developers who are so into Android, that they don't have time to explain the process to newbies 2. Newbies who want root access but don't know what it is. There is a major echo chamber on the web just filled with mindless stupid comments from people hacking away at their phones. I am not against hacking, I am only against repeating misinformation in forums and wasting bandwidth by repeating hearsay over and over again.

Anyway, I followed Cyanogen's instructions, and didn't have any problems at all:
http://wiki.cyanogenmod.com/index.php/Full_Update_Guide_-_G1/Dream_Firmware_to_CyanogenMod
This guy deserves major props for writing a clear, concise set of directions.

The process of downgrading to RC29 is not that hard, and the whole process took less than an hour.

So, here it is, and I know have complete control of my own phone.

The next steps will be to see how much better the audio quality can be made, testing bluetooth high-quality audio, syncing MP3 over Wifi, installing a bluetooth receiver in the car, etc.