-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for ALAC #1
Comments
For what it's worth, OS X + iOS all seem to support PCM just fine - iTunes (directly, rather than via system audio) is the only thing I've come across thus far that refuses to perform without ALAC. |
Looks like Aurora.js can be used in a node-context via https://www.npmjs.org/package/av, which has ALAC decoder available. Might be useful. |
@auchenberg Funnily enough, the only issue on that repo (audiocogs/alac.js#9) is one I posted 6 months ago asking about usage in node. I unfortunately don't have the bandwidth to play with this for now- but, if you're interested in experimenting with this, it would be amazing! |
I was looking into the Sonos use-case and Sonos seem to support ALAC and ACC, so I'm wondering if the mp3 encoding via lame simply could be removed? NodeTunes would simply then open a stream of what-ever which Sonos can connect to? |
Definitely a possibility. Previously, I had thought that mp3 was the only codec that Sonos would allow streamed, but I was proven wrong, at least for the case of PCM streaming: stephen/airsonos#26 |
I wonder if we could detect the stream type, and if it's ALAC send it to Sonos as an experiment? |
Am thinking the same - there's a patched nicercast here that directly writes out PCM - we can try a similar approach with just ALAC. Am currently away from my Sonos setup until Monday, but I'll try to find some time to test then. |
Yeah, that might be an option too, but I think we can bypass the local encoder completely, and simply forward it to the Sonos device, as it supports the codecs natively. I'm away from my Sonos the next weeks, so I'll give it a stab once I'm back. Do you know how do detect the codec from the input stream? |
Played with this today. I think the data that comes out of the RTP stream isn't usable as is - all I got was static out the Sonos end. Trying to listen by pointing a browser at the stream (i.e. http://localhost:8000/listen), quicktime was also unable to decode the audio, so I figure there's some additional work missing here. Here's a dump of the the data piped from nodetunes -> Sonos (with some HTTP headers mixed in): https://gist.github.com/stephen/91cb68f5c244b3ac8ce4 |
Interesting. I'm still away from my Sonos setup, but I'll dig into it once I'm back. |
Okay, I had some time last night, and tried piping the nodetunes stream through ffmpeg via fluent-ffmpeg, and got this: `ffmpeg exited with code 1: pipe:0: Invalid data found when processing input``, so it looks like the stream is not a "clean" audio stream, but mixed with something else. I'm not a stream expert, but my thinking was to pass the stream through ffmpeg, as it supports almost every codec, convert it to MP3, and stream it back via nicercast. A simple replacement of LAME with FFMPEG. |
@auchenberg - What's the command you're running ffmpeg with? I think we might have been incorrectly decrypting the audio before:
from https://github.com/lperrin/node_airtunes#audio-streaming I'm playing with this modified rtp handler: https://gist.github.com/stephen/34811f240eecbed329a4 which decrypts as 16 byte blocks and leaves the last block untouched. |
Aha. Quick and dirty Still getting |
Yep, getting the same thing for now.. dumping a slice of the rtp stream, the first 16 bytes look like a header (https://gist.github.com/stephen/35f750ea03b3d52167a3). Getting rid of it doesn't help though. I'm also thinking we might not be able to play the output directly, if ALAC requires a container format (e.g. an mp4 container) to play? |
Hmmh. With my FFMPEG hack MP3 isn't working either, so I think the stream from nodetunes needs to be wrapped somehow. Do you know what the received stream consists off? Header + data? |
I just had a look at other AirTunes implementations and your are right. The first 16 bytes are encrypted for ALAC. See this port of shairport in Java https://github.com/bencall/RPlay/blob/master/src/AudioBuffer.java#L219 When piping the inputStream to ffmpeg, ffmpeg can't read the stream, so I think the root problem is in the RTP layer. |
Spotify also seems to be affected by this issue - Trying to use AirTunes to send to AirFoil fails with the same error. Sadly the System Audio workaround results in new mail notifications and other system noises being sent. |
I do wonder about how accurate the theory that Sonos supports streamed ALAC is. See this thread with Sonos support where they post the same chart shown above, but end up concluding that only mp3/aac/wma are supported (as HTTP streams). If so the ffmpeg approach will be safest. |
I have added this alac-lib: https://github.com/stephank/node-libalac |
This is interesting @aspergatus. Did you manage to get a working ALAC stream from the server that you could decode? I tried passing it to decoders,and they all choked. |
I now managed to get some data our of the decoder. But after 2-3 sucessful decoding, I then get an error. I will ask @stephank for help stephank/node-libalac#1 |
Thats cool, great work! |
Oh! I actually wrote that lib because I was trying to integrate it with nodetunes. But I think the implementation is broken. I don't remember the specifics, only that I fundamentally misunderstood how the encoder works. To get that lib functional probably means a change in API. I don't think I'll be able to find the time to fix it up, though. Feel free to use it as a starting point and hack it up. |
Any luck with getting this to work? Would be useful for something I am working on, so happy to lend a hand if you could point me in the right direction? |
I tried to get audiocogs/alac.js#11 work, but somehow I don't get the decoding correctly. When I have more time to look at that again, I would compare the encoding and decoding process in details, as well as comparing the input pcm -> encoded alac -> decoded pcm to figure out where the error is. |
I am getting audio skips, looks like the cpu usage is higher with alac than it was with pcm. |
@twentworth12 Thanks. |
I also tried replacing the endionportable.c file that's inside the codec directory and then ran make from inside the codec directory as that is where I saw the make file. |
I was able to get this to work. I reinstalled airsonos and now I have no issues playing from ios9. Thanks to everyone!!!! |
Does anyone the cause of this error I'm getting, after following tiberiumihai's instructions? I'm running Ubuntu 14.04 with node 0.12.4.
|
I have updated the dependency tree on my version of nodetunes to contain the raspberry pi fix, so for those that are having issues; you should be just be able to point at that, and not have to start messing around with replacing directories and rerunning make
|
many thanks microadam, but I have tried modifying the package.json to point to your nodetunes.git but the airsonos show the sonos room, bur no sound comes out the speaker with no error message |
it works on raspberry pi 2 model b with the modification of @microadam. But i get the sound only on one sonos box. i have two sonos in stereo mode. After a few seconds (e.g. 30s) the sound stagnate for a milli second. that repeats sometimes. After e.g. 1 minute sound breaks completely. No sound is comming out. |
Thanks @microadam I can now get audio but I get a glitch every few seconds. I have tried overclocking the pi2 to 900 and it makes no difference. Any ideas anyone?? |
Not tried nodetunes on a raspberry pi, but it's quite possible that the ALAC decoding is quite CPU intensive, so a pi might just not be powerful enough for it. Node is single threaded, so it won't be able to take advantage of the multi cores.
|
the cpu usage is on raspberry pi 2 between 50% and 75% on cpu 1. I hope you can optimize it please. |
I doubt there is much that can be done in terms of optimisation of the ALAC decoding. The decoder is provided by apple, so I imagine it's already pretty optimal.
|
Thanks Adam for the clarification |
Having said all that, I could very well be wrong :) past my abilities though I am afraid!
|
But there is one Thing that i realised. ALAC exists since 2004. on the Last OS X 10.10 Yosemite airsonos Works very well on raspberry pi 2. i Hope there is anywhere an optimization possible. Thanks |
Thx @tiberiumihai, your instructions #1 (comment) works well with OS X 10.11. |
Update for the raspberry users, I had the skips / glitches as described by @skippster in #1 (comment). Updated my Raspberry Pi 2 Model B to the following configuration:
Do not have any audio skips / glitches anymore and cpu usage is about 50%-60%. |
Thanks @buholzer. |
+1,,,everything works flawlessly on Raspbian v8 - Jessie and Node 4.2.1 Thanks everyone!!! |
Thanks @buholzer. |
We are lucky to get by with 60% CPU use and it all depends on what other stuff the raspberry is doing in the background. There are three relatively CPU intensive tasks the airsonos package does as a whole:
3 is done in the thread pool, out of the event loop, and that's good. There can be some contention between 1 and 2 which run in the main event loop. Probably moving 2 to the thread pool can improve things a bit on some marginal situations. |
I have tried again on my Raspberry model B with overclocking to maximum and updated node to 4.2.1, it works very well, I just lose the first 25 second at the beginning of the connection. thanks @microadam and everyone you save my Raspberry ! |
@stephen, please. When will you release a new version of AirSonos which works with El Capitan and iOS9??? It’s a pain in the ass trying to follow all the advices that are posted here. We’re just waiting for you, dude! |
Thanks @tiberiumihai. I followed your instructions and it works perfect.
Thanks a lot ! |
Hey, this is some great work... I have a problem though. I'm blind so using the command line to fix airsonos is a little difficult, I was wondering if there was a way of going through finder on mac instead to edit thecode? I'm kinda green when it comes to such things so forgive my stupidity... I'd really like to get this working,, mainly so I can get my play 1s working with my apple tv, as I'm sure you can understand, good sound is very important to me. Thanks in advance. O |
I managed to find the file and change the line within finder, should that work or does it need to compile again or something? it seems to call another package with the replaced line sowill this just happen when I type airsonos in terminal? I could just wait for the package update I guess. :) |
Make sure the file is saved after the dependency is changed. After you've changed the nodetunes dependency you will have to type the command: npm install into airsonos directory to update the airsonos dependencies. After doing that you should be able to use airsonos from terminal. Cheers! |
Bang on, thanks so much, thought there would be a step missing Now working very nicely, though dropping out a little but I think that’s just my isp. Thanks again.
|
With regards to decoding ALAC being CPU intensive. I am by no means a programmer myself but my understanding is that ALAC decoding should not be excessively CPU intensive as that was the specific goal when Apple originally designed it. Remember the original implementation of ALAC dates back to the original iPod which of course in modern terms has an incredibly feeble processor. ALAC encoding on the other hand might be more CPU intensive but not decoding. Supposedly the main difference between FLAC and ALAC is that ALAC is supposed to be less demanding to do decoding than FLAC. (Both produce similar size files and of course identical quality files.) If you are decoding a PCM stream and then re-encoding it to ALAC to send to Sonos then this might be the issue as this is then contrary to the comments here not decoding ALAC but rather encoding to ALAC. Now what may also be applicable is where the ALAC library your using comes from. Originally ALAC was closed source and the first third-party code to process ALAC was done by reverse engineering ALAC by David Hammerton. It is quite likely this original source was nowhere near as optimised as Apple's then private code. More recently Apple of course did make ALAC open source and published the code on macosforge.org. It is quite likely any ffmpeg or similar ALAC libraries pre-date Apple making ALAC open-source. |
Currently only supports PCM data; no ALAC support yet.
For AirSonos users: You can work around this on OS X by selecting the system audio instead of direct output from iTunes or AirFoil. You can do this by alt+clicking the volume icon in the top bar, or going through Sound Output in System Preferences.
OS X Volume Icon:
Or via System Preferences:
The text was updated successfully, but these errors were encountered: