yashsingh1/xdaforums huggingface dataset:
[Legend General] mikereidis:
Thanks qzem, but FYI, I think I've already read just about every FM and BT thread on devices with the TI chips by now, on XDA and elsewhere. (Well every useful one anyway.) Also several threads on devices with Broadcom chips, since those may offer clues to HTC and other manufacturers audio routing. Any device with a 7227 or similar chip may be similar in audio issues. That includes lots of newish budget and mid-range devices including the LG Chic (and LG Optimus One) I tried a few weeks ago.

I've managed to download the latest TI code for their testing utility "fmradio", and other stuff, so I'm not wanting for code right now. I just need to take the time to pore through it and experiment.

My "pre-alpha" level App Inventor app is working nicely now, so I'm ready to move back to solving the audio routing issues. Since the HTC Legend stock FM app works, (it has one right ? I never tried or even looked hard before rooting and CMing), we know the hardware works. And I'm absolutely positive that sooner or later, either I or someone else will solve the routing issue.

Perhaps within the next week or so I'll have an app ready for anyone who wants to test (Audio or no). As is, it might even output sound on some devices.

As for the Motorola Droid (original aka Droid 1), that's the one that after so much work by some people, it was found that the FM antenna connection went nowhere. The connection point was under an RF shield so would require impractical major surgery to connect. The threads I've read indicate much despair when this was discovered. :(

We Legend owners will not suffer such a fate given that the stock ROM supports the radio fine. (Right?) I'm still not sure yet if the Legend has a decent Tx connection for the transmitter. If not, the Tx may only have a few inches range (which will work for some people), or even none at all.
[Legend General] ojessie:
Just to confirm FM Radio was working fine with the connected earphones. Wired Earphones are needed because the act as antenna.
[Legend General] MrWunderbaum:
Lol
[Legend General] karl_k:
Hi mikereidis !

Its great that someone has started working on the FM radio for our Legends, i did not dare hope for it anymore.

I see you are making progress and that you want to make some money from your work. I would like to give my 50c to that:

I am supporting several open source projects, not because i have to, but because i want to. I appreciate when people do work that solves problems for everyone, not just their customers. This is why i donate to libreoffice, debian and some CM deveopers. I refuse to buy closed source software that solves a problem only for me.

To make things short, i would really appreciate if you make all your basic work open source, ideally by adding your low-level code to CM so that every radio app can use the hooks. If you then also offer a good radio app on the market i would buy it, or donate to you in any other way. However, i hope you understand that if your app is the only app that is then able to do FM radio on the Legend, and you are not opening the low-level workings for others i would rather do without the FM radio.

You are doing magnificent work, open it for the world to see !

For eternal fame ! :)

I would also suggest you create a donate button here on the forum.

I would donate 10€ immediately.

No offence meant, just my opinion.

Cheers,

Karl
[Legend General] mikereidis:
Thanks ojessie. I presume that FM radio audio can be sent to speaker via a selection, even though the wired phones are installed.

Anyone know the connections/pinout of the earphone jack and switches? Is there any sort of standard for this that allows 3rd party phones to be used ?

I presume one could cut the earphones wire to have an antenna without earphones etc. dangling.
[Legend General] mikereidis:
Thanks karl_k. Yeah a donate button sounds like a great idea. I'd prefer to prove myself by getting audio functioning first though, just in case I got hit with the proverbial truck or whatever. :)

I presume I can identify doners and pay more attention to their requests for help or new features.

Yeah I think fully open source and information disclosure is best. Although not alway true, I enjoy the expression "Do what you love, the money will come".

My wife and I have an agreement about my employment/this project, and seeing even a small trickle coming in would satisfy the 3 and 6 month milestones I proposed.
[Legend General] ali ba:
As far as I know FM radio audio is hard-wired to the headphones. At least that's what's done on a few other devices.

By the way, there's no need to write an FM radio app, CM already has one. We "just" need framework support for TI chips. Have a look at how it's done on broadcom devices - I didn't find it hard to understand, but your mileage my vary.
[Legend General] mikereidis:
Hard wired ? I'd think there must be some mute type switch somewhere otherwise we might get static when no other audio is playing.

And the stock FM app can send to the speaker OR the earphones right ?

If it was analog hard wired I'd think my enabling analog output would have resulted in audio by now.

I also do:

adb shell 'echo "fm_headset" > /sys/class/htc_accessory/fm/flag'

but this results in no audio. I read something indicating the switch_set_state() might not do anything when writing to the fm flag, as it should.

And yes, I've taken a quick look at the MIUI app. If it supported TI and broadcom, I think it'd have the potential to work on most devices with FM since TI and BC seem to have the majority of the FM chip market tied up. I'll look at it further once I figure out audio. Re: audio routing being the current gating factor: "So close, yet so far", LOL. :)

BTW, something has seemed funny about attempting to turn on bluetooth on this CM7 ROM I installed a week or two ago. The GUI settings never show it as enabled, even despite that I ran "bttest enabled" fine from adb shell and clearly I see the FM radio portion working.

I picked up a cheap BT headset tonight, but the settings GUI won't let me scan for devices due to this. Perhaps I can find out how to do that with hcitool. And/or maybe update CM7 ?
[Legend General] ali ba:
The routing is definitely enabled by software, but there might be the possibility that audio output coming from the TI chip is hard wired to the headphones output directly.

I think there's some framework code involved too. You would have to explicitly enable FM audio routing. I don't believe that the original ROM does software routing through audio flinger. So the framework has to disable FM routing and enable "normal" audio if e.g. a call comes in.

You mean you enabled bluetooth on the command line? Well then Android won't know it was enabled, as it doesn't monitor the hardware. If you are trying to enable bt in the GUI then it actually should work, just checked with a recent build (the same applies to wlan too).

Did you have time to disassemble (baksmali) the original FM radio app? It points to a few TI-functions in the HTC framework.
[Legend General] mikereidis:
No, but my BT problem is resolved by a reboot. I guess the hcitool commands I send to enable FM must be interfering with normal BT functionality. What happens is the BT Settings changed starts to power up BT, but never finishes.

And, maybe I'm BT naive, but I thought it might enable opening up some Settings option that would allow all normal system sounds to go through BT But that doesn't seem to be available, yet the headset DOES allow BT initiated dialing and such.

No, no disassembly for me yet. I'm trying to get an SCO audio connection going, and I guess the new Open SL ES APIs might help with that. Or the older APIs.
[Legend General] mikereidis:
I posted a thread in the dev section: FM Radio app by HTC: Reverse Engineer: Please help

http://xdaforums.com/showthread.php?p=11675448#post11675448

I could use some help in deciding which ROM to flash to reverse engineer the HTC radio app, and how best to swap back and forth between the ROMs.

Thanks !
[Legend General] cowplod:
make a donate button, you're going to have money coming your way :)

keep on trying man!
[Legend General] mikereidis:
OK, cool. :)

Thanks to speedyink and TheGrammarFreak I'm now running the Blayo ROM with HTC FM app. Works fine.

What I want to do now is try running my scripts and see if they work on Blayo ROM.

If yes, then the Blayo ROM has something the CM7 ROM needs.

If no, then there's likely some magic step required on either stock ROM or CM7 ROM and likely the HTC FM app is doing that step, directly or indirectly.

But the needed hcitool is not on Blayo ROM. I find 3 of the hci utils and install them. Now I can't get hciattach running, which I think is needed for hcitool.

I'm guessing I can edit /init.legend.rc and change service hciattach to enabled. Reboot and no dice. Try running from command line also with no luck. At one point it hung, but now:

# hciattach -n -s 115200 /dev/ttyHS0 texasalt 4000000 flow

Unknown device type or id

# hciattach -n -s 115200 /dev/ttyHS0 any 4000000 flow

Can't set device: Device or resource busy

Can't initialize device: Device or resource busy

# hciattach -n -s 115200 /dev/ttyHS0 any

Can't set device: Device or resource busy

Can't initialize device: Device or resource busy

I DID see the following working to switch output when running the HTC FM app. Strangely, using "disable" did nothing. As if there is some hidden enable switch elsewhere. Hmm.

# Headset

adb shell 'echo "fm_headset" > /sys/class/htc_accessory/fm/flag'

# Speaker

adb shell 'echo "fm_speaker" > /sys/class/htc_accessory/fm/flag'

# View

adb shell cat /sys/class/htc_accessory/fm/flag
[Legend General] Dinyu:
I wasn't allowed to post in the developer forum, because I haven't got enough post - which I absolutely understand why you do that.

I'm currently on cm7 build 8 (the new one) and wanted to ask, if it's just me or is the sensitivity of the display dramatically worse? Sometimes I have to press very hard to have any reaction or even worse: the display doesn't react at all and I have to navigate with the trackpad. I went from #7 back to #5 because of the mobile data bug. and with #5 this problem started to occur. I moved on to #8, hoping this would eliminate the problem, but it didn't.

I also have noticed that the installation of the builds #5 and #8 were suspiciously fast. could there be a problem with the rom manager?
[Legend General] mikereidis:
Feel free to start your own thread in this forum, Legend General.

Anyone wanting to see my latest can monitor the dev thread here: http://xdaforums.com/showthread.php?p=11686965#post11686965
[Legend General] mikereidis:
I'm very happy to report success in the gating factor for an FM app: the routing of audio to analog speaker or headset ! :)

I hope to get some test utilities and/or an app of some sort out in the next week or two. Anyone wanting to get an early copy for testing just pm me.

And yes, I'll get a donation button active ASAP. :) Somehow I don't think I'll get much from that, so, in order to live I think I'll have to create some pay app. Anyone who donates can get an equivalent discount on one or more licenses if they wish.

I'm happy to hear anyone's opinions on that, but really, a guy (and his wife, kids, and cats) has to live, right ? Anyone think a person could make at least 30k a year on donations ?

That said, I totally support the ideas of open source... but that doesn't mean one can't have a pay version right ?

Let me know what you want. Should I port/modify the MIUI FM app ? Create libraries that can be called from various languages including App Inventor ?

I've been thinking of creating a layer identical to V4L2 /dev/radio API, but in userspace, since HCI is more easily accessible (?) and because no low level device driver stuff is really needed.

This would allow V4L radio apps to be easily ported. But it seems to me that's just a handful of command line apps of various vintage. The real plus is that V4L is an open, documented and understood API. AFAIK, it's effectively the only API for radios.

Perhaps a real device driver bridge to create a real /dev/radio device if needed.

Anyway, let me know what you think.
[Legend General] beggar23:
Congrats, very well done! And it was great that you shared all your steps and findings. Quite thrilling actually. :)
[Legend General] mikereidis:
:)

Well, my donate button is active now. If I see enough donations I'll keep 100% to fully open info and development.

PLEASE don't let the corporate world swallow me up again. Heck, even corporate donors of one stripe or another would likely try to steer me certain ways I'd rather not go.

Funny, my local favorite alternative rock station just had a brief "techbytes" segment where they mentioned Android is taking off... Seems fitting the night I get FM audio. ;)

Hmm, I HAVE wondered recently if "old fashioned over the air" radio stations might sponsor/pay if an app supported special features for them. Kind of hard to chase down many stations though. I just noticed my fav station has an IOS app of some sort.
[Legend General] beggar23:
Well, up to now I haven't heard of any REAL hybrid approach. Mostly radio stations simply adding pics or podcasts just unintentionally. But I would really love to check out a true, moderated multimedia radio approach. :)
[Legend General] mikereidis:
Hmmm, the ability to switch back and forth with streaming and real FM might be nice, although it certainly wouldn't be seamless, like cell tower handoffs usually are.

But, in search of possible funding sources, I'm now thinking about the radio business model. Basically, commercial stations sell ears to advertisers, like Google sells eyeballs and ears.

An app could provide radio stations and/or their advertisers more information about their target customers and additional opportunities to promote their products visually, or even just provide convenience, like "show me the google map location for the last advertiser".

And for the user, more information about song playing or played in the last X hours might be cool. Also, additional ways for people to enter contests or make music requests.

Anyway, let's get an app with basic functionality working first. :)
[Legend General] poruid:
Integration of your work into the CM code base will certainly yield the widest use of your *great* efforts.

Besides that, when you'll create an app that supports walki-talki then you might make a nice profit.

On the question of how to make a profit and at the same time adhere to higher goals (OSS), niche apps offer support opportunities. Also initially distributing an app first closed source and after a certain period relicense it as OSS might be an idea.

Good luck!
[Legend General] mikereidis:
Thanks for your thoughts poruid.

By integration into CM do you mean an app that comes standard in the stock CM ? I presume the MIUI app is in the stock CM7 for the 2 phones it currently supports.

I'd agree that would create quite a number of apps installed without people having to explicitly load my app from the market or wherever.

As for support, yes I have been thinking that two identical (or almost identical) apps could be created. One free, and one non-free that comes with support. If an added feature were needed it could simply be a mechanism to send debug data and a user report to me that I could then attempt to solve. This "added feature" could even be a separate mini-app that communicates with the main app.

But I don't see a lot of potential for support with a reasonably simple app. "Unfortunately" my past software projects have a tendency to be close to bug free. So if, for example, one just had an app to control power, tune, scan, set volume and perhaps a few other small things, I don't think there's much to go wrong, assuming the app is run on a supported and tested OK device.

But yes, if/when an app becomes much more sophisticated, there are many more things that can be confusing or go wrong so a paid support model can be more viable.

On intriguing support thought occurs to me though: Support for a toolkit/development tools to allow one to customize and extend the radio capabilities. An App Inventor toolkit could allow non-programmers to do interesting things. But those non-programmers will generally get confused when going beyond their capability level.

But I think a paid support toolkit would need to be relatively rich in functionality. For example, providing access to RDS data streams, and ideally FM transmission WITH RDS. Once again "walkie talkie" functionality (data or audio) could be a compelling feature.

Re: initially distributing an app first closed source

Even that I'm not TOO fond of. Releasing the source means others can extend functionality and find and fix bugs and that helps my cause. Releasing the source early helps when help may be needed most.

But there ARE technical reasons, mostly unrelated to business concerns, why releasing source might be delayed by a month or so after an app. That could change though if there are people eagerly anticipating the latest source, but those people could be sent early source.
[Legend General] mikereidis:
Regarding the MONEY part of the title:

Very shortly after I enabled my donation button about 36 hours ago, I received the first 2 donations: 1 for $15 US and 1 for 10 Euro. Much thanks to the donators !

But since then, nothing. Perhaps I'm a bit hasty after only 36 hours, but I think that illustrates my point about the donation model. It results in very little, although that little is certainly appreciated.

IMO same thing happened in the "Shareware" days. That model has virtually died.

Anyway, to help encourage donations, I'll reiterate my promise that if I create any paid app or other service, donators will be entitled to at least as much as they donated in value. And I'll certainly be paying more attention to their requests for features or assistance.

Beyond that, I'm reasonably certain that I can keep at this project for the next year or so. At that point I'd have to reconsider my position should no clear source of further funding be found.
[Legend General] joka90:
Thanks for bringing the Fm-radio back to my Legend. As you haven't heard of any Legend owners that have got the radio working I thought I better report. ;)

Got the radio working by doing as they said in the thread below from the tatoo forum.

http : / /xdaforums.com/showthread.php?t=980158

I am using CM 6.1 with S-off.

Update:

Made a test using the latest version from the thread in the dev forum. Both speaker and headset working. But there was no way to turn the radio off as in the tattoo script. So I used that script to turn the radio off instead.

As you probably know the playback stops if you change the volume.
[Legend General] mikereidis:
Great ! Thanks for the report joka90.

No I didn't know about audio stopping if volume is changed. Doesn't happen to me. Do you mean using the hardware buttons to change volume ?

If I use the volume buttons, it modifies the ringer volume, as if no media is being played. This is to be expected at this time. Also, if I play audio with another application, volume only affects that other application media volume. FM audio keeps on playing, mixed with the other audio.

Can you give me any more details about volume controls disabling audio ?

OK, I see someone ( cn.fyodor?) has modified my script, which is perfectly cool of course.

That script writes "disable" to the pseudo-file /sys/class/htc_accessory/fm/flag .

The "disable" has never worked for me running Blayo or CM7 on Legend. For whatever reason the kernel code doesn't work. Even the original HTC radio app does something different to mute sound. But I'm guessing it must work on the Tattoo.

In any case, turning off bluetooth or running shell commands like the following will work:

# Set volume to 0

hcitool cmd 0x3f 0x135 0x1c 0x02 0x00 0x00 0x00

# FM Rx and RDS disable

hcitool cmd 0x3f 0x135 0x20 0x02 0x00 0x00 0x00

# FM core power down

hcitool cmd 0x3f 0x137 0x01 0x00

# Turn off BT

bttest disable
[Legend General] ponchofiesta:
If you do it for the money, you shouldn't do it. If you release a working app/addon/whatever and I can use FM radio again, I would pay for it. I think the best way to earn some money is to release a payed app or/and one with ads.
[Legend General] joka90:
Did a quick test this morning.

It seams that the radio only turns off the first time I press the volume buttons. If I run the script again the radio starts as usual and is not affected by the volume buttons.

If I reboot the phone the same thing happens the first time I launch the FM script. But not the second time.

The off script you posted works. I made a new file in /system/bin to turn the radio off.

I hope this helps and we will see an awesome FM-application in a few weeks.:)

Update:

logcat when using the script for the first time after reboot.

ht tp : // pastebin.com/wasD2g0X
[Legend General] qzem:
@mike

I've kinda lost track, but have you also managed to get Fm transmitter working? Or do you belive that chip is not physicaly connected, so that transmitting is not possible?
[Legend General] gaga111:
u mean it could be possible to send audio via a FM frequency to another radio?
[Legend General] qzem:
Yes the chip has this possibility but, I'm nobody is sure if it is connected this way...
[Legend General] joka90:
Your appinventor app is working greate on CM 6.1!

The volume bugg is still there.

The weird thing is that I did not restart the phone before trying your app. But the radio turned off the first time I changed volume. Maybe this can give a clue what is going wrong the first time..

Posting here as I don't have access to the Dev section yet and to keep the dev thread clean.

A notice to all S-ON users. You probably need to S-OFF to write to /system/bin as the install script does.
[Legend General] NX3:
Just found this thread. The only I've not rooted and installed a custom rom yet is because I use the FM Radio everyday. Happy to donate but think paid for app is better route or ad supported if you want to see any income.
[Legend General] gaga111:
would be cool if that works o.o
[Legend General] mikereidis:
Thank you all for your reports and comments. Yes I agree and have said from beginning that I think some sort of paid app is likely the best way to feed myself etc. while continuing to work on this project. (No, I'm not starving, just making a point.)

Yes I'll investigate the volume issue. Happens to me too, but only sometimes. Should be easy to figure out (famous last words :).

Good point about S-Off. I think the binary could be placed elsewhere that won't require S-Off. That will require a minor script mod.
[Legend General] mikereidis:
The transmitter inside the same chip definitely "works", insofar as I can write to it's registers and read the results I would expect.

I last tried 2 weeks ago, but could not detect any transmission, even an inch or two away.

I have two major theories why I can't see any transmission, and both could be true:

(1) The FM transmitter pin may be connected to ground, or connected to nothing. If that pin is inside an RF shield, as I guess is likely, then it would require major phone surgery to fix.

Would anyone like to disassemble a phone and find out ? I can find no good teardowns for the Legend; closest is an FCC doc with pictures that only show limited detail.

(2) We may need to load FM Transmit specific firmware.

There's a 3rd possibility, that there could be some virtual switch in the phone than enables Tx. But since Legend was AFAIK never intended to transmit, I doubt it, unless a stock reference design was used.

I will try to look into (2).

The transmitter and receiver are exclusive. Only one can run at a time, but they can be switched quickly, as with a walkie-talkie.