yashsingh1/xdaforums huggingface dataset:
[Spirit FM] MrSteve555:
Hi Mike,

I'm trying to get native FM radio support on huashan CM11(Xperia SP), but after building, I can use the radio app, but there is absolutely no reception.

I can only get some crackling sounds, that get louder on certain frequencies.

I'm getting the same problem on Spirit 2 - I diagnosed this a bit and found out that the antenna "layout" is weird on Xperia SP. Internal uses headphone cord to recieve the FM waves, and I think the External uses the internal antenna. It's inverted and I have absolutely no idea how to fix it.

But here comes my real question:

Is there any way to switch the antennas with a command/BoardConfig flag/hack/anything? I'd love to get your app and native CM app to work ;)
[Spirit FM] j1miroquai:
Hi Mike.

I bought both your apps but unfortunately they don't work since I'm on Mahdi rom 4.4.4.

Of course its not your fault. I just have to ask. Is there any chance at all the app will work in the future on aosp roms? I own a lg g2 d802
[Spirit FM] :
My chainsaw is dull now...

... but FM radio still works sharp as a razor's edge.

:D

Tested the experimental release 2014/09/20 on my I9000 running CM11 nightly release as of 2014/09/19.

Volume control now works on lockscreen, yay!

Speaker mode works, volume is more than sufficient.

FM over bluetooth did not test.

I receive more FM channels than ever. The amount of station storage places is not enough as for todays reception possibilities!

I wonder if you did some magic on the tuner.

When receiving a call audio is properly muted and continues after call has ended.

This is not dependent on who ends the call.

When making a call its all the same.

When overriding FM with another app that needs audio, FM is properly muted but does not continue after app is closed.

You have to restart FM.

Please aks for any other checks i can do with my hardware. I would be glad if it helps.

Spirit is what it says :good:: Inspired.
[Spirit FM] mikereidis:
Hi, Thanks for your support. :)

Absolutely, I'm happily running the Vanir ROM with no problems on my Sprint LS980 variant of the LG G2.

At this point it's up to the Mahdi ROM dev(s) to decide if they want working FM support.

At one point, Spirit worked on Mahdi. Then he switched to a Nexus derived kernel to fix audio problems. Sadly the Nexus kernel audio driver did not have FM support.

I spent many hours developing a patch for the Mahdi kernel. It worked fine and I posted the patches and kernels here and on the Mahdi thread, with the hope the Mahdi dev would incorporate. It should take less than 5 minutes to do IMO.

But I guess he declined. There's nothing I can do about that; I can't force other people to do what I ask. And I can't get bogged down in creating and maintaining kernels on an ongoing basis. I have more than enough to do with my apps alone, with all the phones and ROMs I support, ongoing fixes, and major updates needed for Android L (and most Android releases really.)

I then found that the Vanir ROM already had the stuff needed in the audio driver for FM. So I've been happily running Vanir and all it's OTA updates. I don't use my G2 as a real phone so I have no idea how good it is as a "daily driver" ROM.

I'd recommend that you use kernels that have FM friendly audio drivers. I'm not sure which might at this time; I can only say Vanir works fine. CM11 used to work fine also, and may still do so, but I guess a lot of people didn't like that it required old bootloaders; I'm not sure if that is still true.

Beyond that, please feel free to "bug" kernel or ROM devs nicely for FM compatible audio drivers, more so perhaps if you've made any donations to their cause.
[Spirit FM] mikereidis:
Spirit1 and Spirit2 both handle this automatically, as long as "ro.product.device" starts with (case independent) "C53", "M35" or "HAUSHAN" (for SP; there are others, see my C code at the end.)

Spirit1 can even be explicitly set, using Debug-> QCom Antenna.

Xperia SP requires "External". Most other Sony's require "Internal" and these are the ones that Spirit Transmit works on.

Pretty much all other Qualcomm chip based devices need "External", so the SP is more non-Sony "normal".

I have not found a single device that can use both; External or Internal refer to one of the two FM antenna pins on the chip, and in all cases I've seen, only one is connected to the wired headset, the other always seems to be grounded/disabled.

C code I use:

if (! strncasecmp (prop_get ("ro.product.manufacturer"), "SONY", 4)) {
if (! strncasecmp (prop_get ("ro.product.device"), "C2", 2) || ! strncasecmp (prop_get ("ro.product.device"), "S39", 3) || ! strncasecmp (prop_get ("ro.product.device"), "C19", 3) ||
! strncasecmp (prop_get ("ro.product.device"), "C53", 3) || ! strncasecmp (prop_get ("ro.product.device"), "M35", 3) || //! strncasecmp (prop_get ("ro.product.device"), "C19", 3) ||
! strncasecmp (prop_get ("ro.product.device"), "NICKI", 5) || ! strncasecmp (prop_get ("ro.product.device"), "TAOSHAN", 7) || ! strncasecmp (prop_get ("ro.product.device"), "HUASHAN", 7)
)
v4l_antenna = 2;
else
v4l_antenna = 3;
}

if (v4l_antenna >= 2) {
ret = chip_ctrl_set (V4L2_CID_PRIVATE_IRIS_ANTENNA, v4l_antenna - 2); // 0 = External/headset antenna for OneS/XL/Evo 4G/All others, 1 = internal for Xperia T - Z1
logd ("chip_pwr_on PRIVATE_IRIS_ANTENNA ret: %d v4l_antenna: %d", ret, v4l_antenna);
}
[Spirit FM] MrSteve555:
Hmm,

Maybe it wasn't working from day 0 or something has changed recently, because right now External is the one that doesn't work, and Internal works perfectly fine.

And nice to know that actually the name External/Internal don't refer to headphones/no headphones. I'm a complete newbie into this, so forigve my lack of knowledge.
[Spirit FM] mikereidis:
I'm roughly on "Hawaii time", or up from about 19:00 - 11:00 GMT. :)

Great ! I definitely appreciate testing around phone calls; this is one of the more common issues and I don't have the resources to buy 20 SIMs and do a lot of phone call testing myself.

An issue to watch for on GT-I9000 is the "chipmunk" problem, where audio frequencies are doubled. This happens after an app (including Google Now) uses the microphone in mono mode. The audio driver gets stuck in mono and can't be switched back to stereo. A few people report that they ALWAYS get audio frequency doubling, even after a fresh boot. I think they must have some app that starts the microphone, even if only briefly at startup. Google Now hotword detection needs to be disabled lately to avoid this.

I'm actually pleasantly surprised that I got GT-I9000 working as well as I did. I was almost sure I'd have to leave it behind for Android L, due to the mono only microphone issue. (But I'm not sure CM12 or any L ROM will ever be built or work well on such a "classic" phone.)

I rarely touch tuner code any more and haven't done so for the Silicon Labs tuner lately. Sometime people say reception got better, or worse, and I just say that nothing was changed. Sometimes people mistake audio quality issues for tuner reception issues.

BUT, I did recently amplify the sound volume for GT-I9000, so maybe that's what you are noticing.

When a "temporary loss of audio focus" happens, such as for an audio notification, Android audio apps are supposed to pause and restart audio, or lower and re-raise volume.

When a "permanent loss of audio focus" happens, such as when a music app starts, Android audio apps are supposed to stop "semi-permanently", which means permanently, unless the user restarts it of course.

Spirit follows these rules for Android audio apps. Of course FM radio has the added issue of the running tuner. I COULD make Spirit continue to run the tuner with audio paused until explicitly turned off.

But all other stock and non-stock FM radio apps turn the tuner off completely in this scenario, so Spirit does the same. Most people want FM turned off completely when starting another music app. It's easy enough to restart for those who want that.
[Spirit FM] mikereidis:
Try both. Whichever one works, works.

It's possible somebody flipped this in the kernel driver in order to get the Qualcomm app, or one of my apps to work.

In the first 6 months of 2014, Spirit2 always used "Internal" for Sony's. That was fine for Xperia T - Z1, but a few models like SP used "External".

So somebody might have flipped it to get Spirit2 to work (unless your aware of all related kernel code changes in the last year and there was none such as this.)
[Spirit FM] MrSteve555:
Well, I don't think Sony engineers would flip it like that(I'm using CyanogenMod 11 running on stock kernel). Actually all the apps are trying to use External, so flipping External with Internal doesn't seem like a smart idea, does it?

Right now Spirit FM2 doesn't work because, as you said, it uses External antenna by default. And I'm trying to say that it actually should use the Internal antenna, because Internal works, and External doesn't.
[Spirit FM] mikereidis:
Okay, maybe it's just the Xperia L that uses external.

Does this work then ? : http://d-h.st/dmJ
[Spirit FM] MrSteve555:
You are really good, Mike! It now works as it should, thanks for adressing the issue.
[Spirit FM] MrSteve555:
Mike,

I can confirm that Spirit Transmit(I tried the free V1 version) works on Xperia SP. So now we can be sure that SP uses Internal antenna + has transmit capabilities, pretty nice stuff ;)
[Spirit FM] j1miroquai:
Thanks a lot.

I already downloaded the rom and I'll give it a try. :)
[Spirit FM] :
Mike,

just some additions:

Chipmunk sounds are all gone. I had those a few times after updating CM11 nightlies on regular Spirit2.

New effect, not a problem:

But sometimes when hopping channels quickly i hear intermittend "stuttering" of audio and two times

it happened that i could hear myself on the phones microphone instead of FM when unplugged and plugged headphones.

But there is one issue i did not notice so far.

The audio seems to be all MONO.

To assure i used a decend headphone amp and really high quality headphones to listen to FM.

Mono and the stereo switch on settings page has no effect.

Plus not both channels sounded the same.

Now it is fact that my right ear is slightly worse than the left, so i swapped channels but the "strangeness" in sound

was not gone.

The effect is that on the right channel there is kind of a bass "thump" (like eq'ed low frequencies).

Next i tried the crossfeed emulation in DSP Manager. This has a real HUGE amount of influence on the sound.

Something like "fake stereo" as we did in the 70s.

But still the sound is strange and with DSP kind of artificial or tinny.

To make sure that this all is not due to bad hardware or interconnects i simply uninstalled Spirit2 experimental and got back the

latest version from playstore.

Everything is as usual for now. DSP Manager influence to the sound is subtle as was before (and intended, i guess).

And it is Stereo on strong stations again.

Finally, soundwise, i am back to the regular "analog" version.

I still like Spirit1 for the fact that mono to stereo blend works much smoother and is switchable to your liking..
[Spirit FM] mikereidis:
Great ! That's one more supported phone for transmit and I've updated the Play listing. :)

I was going to recommend you try it to verify it REALLY DOES use "Internal", but thought it might confuse the issue.
[Spirit FM] mikereidis:
Thanks for your report. :)

By "Analog" do you mean Spirit1 with Audio-> Method = Galaxy S ALSA/ ICS ? This is the only true analog method. (Ignoring that all FM chips use digital internally.)

Yes, on a few phones I felt there may have been some bad audio effects, but my ears aren't well tuned for audio, so I prefer to get testing feedback from people with better ears.

One some older phones, such as GT-I9000, there may be some mono/stereo issues, since most use microphones that are mono.

There may also be issues with limited frequency response, because using microphone may tune the audio for telephony or simple voice recording, instead of 44.1 KHz response. I'm reasonably confident that I can fix these issues, at least on more recent phones.

I currently use Audio Input 0 = "Default" on all but Xperia Z2. Using the input for "Camcorder" or some other may help.

And the approach of using the microphone means that there will likely be at least a short burst of audio from the microphone, but I can probably reduce or avoid this issue with some code and tuning of the code.
[Spirit FM] :
M: By "Analog" do you mean Spirit1 with Audio-> Method = Galaxy S ALSA/ ICS ? This is the only true analog method. (Ignoring that all FM chips use digital internally.)

F: No. I was not clear. Forget about that.

I meant Spirit2 version from playstore when i said "analog". Which is wrong because both versions use digital audio methods.

M: One some older phones, such as GT-I9000, there may be some mono/stereo issues, since most use microphones that are mono.

F: Yes. There is no stereo microphone on the I9000. That may be the reason for audio being mono only.

The thing about "bass thump on the right channel" was gone after a reinstallation.

At the moment my local radio station runs a special feature on the 80th birthday of Leonard Cohen.

They have interviews where the persons are clearly sitting left and right from the stereo mike.

So this definately reveals audio is MONO only on the new version of Spirit2.

Switching back to Spirit2 2014/09/12 gives a fine STEREO sound back.
[Spirit FM] MrSteve555:
Yeah, I also think it's pretty nice, and the range is actually not that bad as I thought it would be. :) Nice work overally!

And about your test version of Spirit 2(that with the sneaky microphone change mechanism):

- the pausing/unpausing mechanism when getting notifications/getting audio from another stream/Google Now hotwords works well - everything just works, and it's the best desciption for that ;)

But there is one issue I'm facing:

When using FM, the sounds recorded by microphone are being routed to the output device. Actually huashan uses Speaker DMIC Stereo for recording(and this alsa device is being used in Spirit FM2), that device is dual mic, so it generates pretty loud noises.
[Spirit FM] mikereidis:
OK, so you're hearing microphone sound ? In addition to FM or instead of FM ?

I didn't see/hear this on any of my other Qualcomm based devices: Stock Z and Z2, Stock MotoG, CM11 One M8, CM11 OneXL.

And the code for Qualcomm FM devices is pretty much the same for all, independent of generation. OneXL = 2012, One M8 = 2014.
[Spirit FM] MrSteve555:
I'm hearing microphone sound in addition to FM sound.

Hmm, maybe you didn't notice it because they are using other devices for sound recording, and are being muted properly?
[Spirit FM] mervluk:
Probably not the same thing, but my Xperia Z with latest Spirit 2 beta playing now has a new distinct echo with up to 1-2 sec delay; sometimes. (I disabled Viper to see if that was the problem, it made no difference). Especially noticeable with voice. Comes and goes, but is not cured by pause/restart or a reboot. On the other hand muting for system sounds and calls is now improved. And stereo seems to work much better, and audio generally is less glitchy with much fewer "no audio silences" when playing. Getting there. :D

Edit: well, listened to an opera tonight, and it was like being in the auditorium, rather than being outside, as with previous versions. Credit indeed. :thumbup:
[Spirit FM] mikereidis:
Yeah, it will take some time, as it did to get Spirit2 this far in the last year.

I wasn't even expecting to put out this experimental release so soon.

But it seemed to work well enough that it seemed to be time to get some feedback.
[Spirit FM] Fnord12:
Bit of a late reply here but I only recently reverted my phone (G2 - LS980) at the prompting of something I must have done wrong.

Tried Spirit 2 to no avail, just sits at the splash screen forever, and Spirit 1 looks like it tunes but I don't actually hear anything.

Sure NextRadio works but it's UI is kind of hideous, if it isn't too much of a bother I would like to get one of those two working.
[Spirit FM] mikereidis:
I have an LS980 and it was running CM11 until a few months ago. I updated the bootloader to the KitKat version (? or whatever ?) and have been running Vanir ROM since then.

My understanding is that I can't go back to CM11 now because it needed the old bootloader. Has the old bootloader requirement for CM11 changed ?

In Spirit1 try these Audio-> Method settings:

- Digital LG2

- LG G2 ALSA

- Sony T/QC Intent

- Sony Z/QC Intent

If nothing works, send a debug log from Spirit1.

Tap the frequency button, enter the number 7 and tap "OK". After 20 seconds or so, press Send from your email client.
[Spirit FM] Fnord12:
Not running CM11, i'm running the stock LS980 ZVD rom that's been rooted.

Blue text shows up as "FM: BC OEM" I do have bluetooth on by default but also tried it with it off.

Sent the email, if it's not easily doable then don't worry too much about it.
[Spirit FM] mikereidis:
I think stock ROM worked the last time I tried it.

If the tuner part works, try the Audio-> Method settings I wrote.

You can also set Debug-> FM API to "Low Level" and try with those audio methods again.

I am very VERY hesitant to put stock ROM back on my LG G2. Every time I have, and almost every time I try a new ROM, something gets messed up and I have to spend at least 3-4 hours scratching my head and fixing it.

I don't have this issue with most other devices, and I think it's mostly because LG does not provide an unlocking / S-Off like method, and nobody has cracked it. I probably won't even consider a G3 unless LG comes up with the unlocking plan they were allegedly pondering. I've had 2 LG phones in 3.5 years and I've hated both of them. :(
[Spirit FM] Fnord12:
Well, that's odd. Worked once on LG G2 ALSA and didn't work again after a reboot, most screwy.

Oh well, I wouldn't worry about it, not worth the risk bringing yours back to stock just for one person. This piece of *bleep* seems to actively resist flashing of all kinds. Nearly bricked mine several times already, once being on an ordinary CM11 update. Monday night I had to toss it in download mode and wipe the thing and revert it to ZVC given the mic stopped working during my attempts to change ROMs on Sunday. (couple near bricks then as well)

I don't quite hate it but i'm nearly there, what with the whole bootloader and lack of fastboot thing. Then there's the amount of crap that LG "customized" and I have to replace. (launcher, messaging, clock, home screen widget, contacts and likely at least one or two that I forgot)

Let's just say i'm very much regretting getting this phone. Had I know about SDR at the time of purchase I would have gotten a Nexus 5 instead and used that + a wireless charger for FM.
[Spirit FM] blackcat51:
[APP][2.1+] Spirit FM --- How to make it work on MOTOG (1st gen)

I tried installing the free version, it shows that it is locked on to the channels, shows signal strength and channel name, but no audio can be heard, if somebody can let me know the settings please.
[Spirit FM] mikereidis:
The Free version of Spirit1 is a year old now, older than the Moto G, and doesn't have some needed tweaks.

If your MotoG is rooted, there's a test release of Spirit2 here: http://d-h.st/dmJ

Works fine on my MotoG, stock or AOSP.
[Spirit FM] mikereidis:
The original LG G2 audio is pretty messed up and that's why several ROMs/kernels pulled code for Nexus (which has no FM support). I found it would often reboot just trying to get a list of ALSA controls. And LG added weird code for FM audio. Weirder yet there's a special switch chip I've never seen before only in phones supporting FM which selects BT or FM.

My feeling is that LG cuts every corner they can find, to make the phone cheaper* and get it out faster. Sadly, I think cheaper and sooner is why they've had some success the last few years. (* And yet that silly extra chip must have cost a few cents extra.)

Most people want their phone pocket-able, so USB dongles are not an option. And I personally am not very happy with the reception/audio quality using an RTL dongle and SDR touch, the Wave... app, or even my own experimental SDR code. And this despite that my hearing quality is pretty lame.

Some fancy cabling, and I think a kernel switch for "Charge during OTG" is needed to get RTL SDR working without the device battery dying relatively quickly.
[Spirit FM] gimmeitorilltell:
I hope it's ok to post this here since I'm asking about FM radio only? I am compiling for the HTC One Max and spirit radio works great but the FM radio has NO sound. All the functions work properly as far as the correct channels, searching, & recording but I have no audio. It seems that you know you radio quite well so I wanted to get your thought and input if I could. I am using the audio-caf source from cm-11.0 and after reading your threads I'm not so sure about this commit I've made ---> https://github.com/gimmeitorilltell...mmit/f1b79627c70fc8186e77d06280b9b7a7ba586e4c
[Spirit FM] mikereidis:
One Max uses Qualcomm FM/BT/WiFi combo chip and Qualcomm wcd93xx audio, right ?

Spirit2 should detect and use that automatically. Spirit1 should do the same, but you can force specific Audio-> Method settings. Try these:

- Digital QCom

- Qualcomm ALSA

- Sony Z/QC Intent

- Sony T/QC Intent

- HTC (if using stock audio blob HALs, it might work.)

The first 2 methods above are low level and go straight to /dev/snd/controlC0 with ALSA settings.

Your file patches seem appropriate, if you're going through the HAL somehow and using ALSA UCM (Use Case Manager). My Qualcomm ALSA method enables these:

- "SLIMBUS_0_RX Port Mixer INTERNAL_FM_TX"

- "SLIMBUS_DL_HL Switch"

And then starts a hostless PCM transfer on /dev/snd/pcmC0D6c .
[Spirit FM] gimmeitorilltell:
Well my logcat finally shows to be using the ALSA UCM but I still have no audio from the FM radio. It's confusing that Spirit1 works fine but the fm radio has no sound. I'm guessing that the real issue is in the HAL or POWER HAL maybe. I am getting "E/QCOM PowerHAL( 206): Error opening /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor: Permission denied" in my log but certainly this has nothing to do with the radio app. I do appreciate your time in responding to my questions, especially since I'm not familiar with much of the fm radio aspect. If you don't mind checking out my logs? This is my most recent log http://pastebin.com/XurLxyH5 and this is the first log I grabbed before pulling in and editing more http://pastebin.com/9U2fB0Ni Now that I look at my old log, it seems like it was closer to working than it is now?
[Spirit FM] LenAsh:
For the record, Z2 on CM11 - Spirit 2 has no audio on 20/9 but is fine back on 12/9.

EDIT - the only audio on 20/9 is from the headset Mic.