USB mass storage file transfers and real-time file/audio streaming - Page 1
Forum section: electronics / projects

author: luigi_xp
author_rank: Newbie
timestamp: March 10, 2017, 06:04:20 pm
content: My car stereo doesn't have an AUX input, so i need to manually upload music over an USB stick to listen on it.However, i got an idea: Would it be feasible to implement some form of "streaming" audio over USB mass storage?I did look up on google a lot and didn't find too much, apart from mass storage and USB specifications, and some USB sniffers that maybe could help.My idea is emulating an WAV file with a really big length, like 10 hours, and then, as it plays, dynamically send audio data recivied by an audio input through an DAC, using the ARM-based teensy or another similar board. Maybe an raspberry pi zero? (but i don't think having linux in the way would be any easier.)I don't know how much these car stereos can buffer data, but i'd be surpised if it's more than a few seconds.Has anyone messed around with low-level USB? Any "starting point"??Thanks

author: Avacee
author_rank: Unknown
timestamp: March 10, 2017, 06:12:46 pm
content: Completely not answering the technical aspects of your question but a different solution is a very-low power FM transmitter.I have one of these plugged into my android phone and it works great in the car.http://www.ebay.co.uk/itm/Portable-3-5mm-In-car-FM-Transmitter-Radio-Audio-Mobile-Phone-Adapter-For-iPhone-/162425979624Playlists, random, skip forward, back, and all the functionality of the music player app.Search for "FM Transmitter mobile phone"Note: Not legal in all countries as you may not be allowed to transmit anything on the FM frequencies - even at the low power these use.

author: luigi_xp
author_rank: Newbie
timestamp: March 10, 2017, 06:42:49 pm
content: That's interesting and i will buy one to solve my issue, thanks.But i want to go forward with my idea because it's something very interesting to mess around with

author: Avacee
author_rank: Unknown
timestamp: March 10, 2017, 07:40:49 pm
content: It would depend on the file lock the radio gets on the file - if it doesn't allow writing while it is reading then its not going to work.I once worked for a radio station writing the software used by the DJ's in the studio and what you propose for writing a WAV file dynamically is probably possible in this context. It certainly was on PC.Just set the DATACHUNK size to max or however long your radio supports and write ahead of where you think the radio's read pointer is.You won't be able to be very responsive in changing tracks though as you won't know how far ahead the radio has read the file. It might only read ahead 2 seconds, it might read ahead 60 seconds, it might be 2 minutes.Without knowing where the read pointer is you won't know how much the radio has cached - nor can you send a signal to clear the cache and reread the changed audio.If you don't want to change track immediately and can let the current track finish then just write the next track after the current track - you'll know where your write pointer is - subject to the radio's cache.If you want to change audio immediately just write where you think the read pointer should be based on time active and format and wait for the radio to perform its next read.It would be interesting to know if your radio supports other CHUNKS such as CUE, FACT, LIST, FMT and the playlist chuck (can't remember the name of that chunk)Interesting idea - Others will be far more help with the electronics but I can probably help with the software

author: dmills
author_rank: Super Contributor
timestamp: March 10, 2017, 10:54:22 pm
content: You can do better then that, as your disk emulator knows which block was read most recently so knows with the granularity of one allocation unit (Possibly as little as 512 bytes) where the radio is filling its buffers from....You just need to be writing ahead, in fact you only actually need 1kB of ram buffer plus a FAT that lies a bit and during playback you just pingpong the buffers out the USB port pretending to be a mass storage device.The really fun elephant in the room is locking your source rate to the rate the radio is pulling the data, some sort of delay locked loop driven resampler or PLL locked to the rate the radio is requesting new sectors would seem to be indicated.Interesting thought, but given that many mobile phones have USB OTG, it might be possible to write an app that made a phone with a suitable lead behave in this manner? I don't know how flexable the audio routing between apps is on those platforms, and it may require some low level hackery, but it is a thought.I did one version of the core audio engine for the Rivendell radio automation system on Linux years ago, so another old radio automation hand here.73 Dan.

author: luigi_xp
author_rank: Newbie
timestamp: March 11, 2017, 01:41:45 am
content: I'm gonna buy or borrow a Raspberry Pi zero on a few days to try a "simple" way to see if this is possible to do. It's the cheapest device with USB OTG and capable of simulating a usb mass storage device. You can just make a .bin file, mount it as a partition and format it, and make that partition avaliable on the USB OTG port as a mass storage device.I'm going to see if the radio write-locks it (it seems obvious that it would do, but as no one desiging it would think that it would be mutable on the fly there's a resonable chance it may not be) and try to get the concept working.About all the swapping buffer and other stuff you guys mentioned - maybe i need to learn a lot more about low-level stuff in order to make that work. I'm recent in the bit-banging world.Any good books/learning stuff?Quote from: dmills on March 10, 2017, 10:54:22 pmI'm an Android developer as my daily job and used to do modding and rooting,the android USB OTG capabilites are somewhat restricted from what I know.There's in fact a app that emulates a mass storage device from a ISO file, but you need root for it to work and it doesnt work on some phones. So lots of hackery.

author: Avacee
author_rank: Unknown
timestamp: March 11, 2017, 07:56:14 am
content: I have a Pi Zero and Pi Zero W with fresh clean installs of whatever the latest version of NOOBS is.Please post what OS you are using and how you set up the OTG so I can replicate your setup here.You could take the lazy option of a USB flash drive with built in wifi and "stream" to that .. but where's the fun in that ... and jeez, they cost a lot of beer vouchers!

author: dmills
author_rank: Super Contributor
timestamp: March 11, 2017, 12:47:13 pm
content: Quote from: luigi_xp on March 11, 2017, 01:41:45 amShouldn't matter if you control the low level file system code....Regards, Dan.

author: Berni
author_rank: Super Contributor
timestamp: March 11, 2017, 04:47:38 pm
content: Thats something i certainly have never seen done before.The easiest way i see of doing this is to get a microcontroler with a USB port and grab some USB mass storage example code. All you have to do then is replace whatever storage the example is using with your code that does the sneaky manipulation. Your code should receive read and write requests from the USB code on a sector by sector basis.You probably want to make the first few sectors be a non writable area where you put in a master boot record with one gigantic FAT partition that contains one 4GB file that is completely sequential from sector to sector and the first sector of the file is your WAV or MP3 header that also says its a really long file. That should cause the radio to then atempt to read sectors higher than that one by one. Your code intercepts reads to those higher sectors and inserts audio data.

author: hilogicsys
author_rank: Newbie
timestamp: May 04, 2017, 05:05:33 pm
content: Hi, i think this is what you are looking forhttps://hackaday.io/project/19747-esp8266stm32-wifi-usb-mp3-dongleRegards