• AVR Freaks

USB audio device for a FM Radio

Author
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
2010/04/27 04:38:06 (permalink)
0

USB audio device for a FM Radio

I've purchased one FM radio from Sparkfun - AR1000 chipset, it's kind of nice, has RDS, has a full set of registers...
I can communicate with it though I can't receive any station so far but... will see Smile

I have interfaced it to a basic HID USB module, just to comunicate with it.
Then I came to thinking that it would be nice if I could make it a USB device, in order to receive the audio without the analog connection to the speakers.

So I'm asking - it would be my first try into the USB audio class, I only read some threads in the past - if there's a *simple* *working* implementation available, for a PIC18F2550, that can create a only-input USB audio device.

thanks in advance

GENOVA :D :D ! GODO
#1

17 Replies Related Threads

    stefanopod
    Super Member
    • Total Posts : 1285
    • Reward points : 0
    • Joined: 2007/06/25 02:33:59
    • Location: Bologna,Italy
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 05:24:01 (permalink)
    0
    Of course you'll have considered the set of examples from Microchip labeled as USB Device Audio.
    I found them useful.

    provando e riprovando
    #2
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 05:33:39 (permalink)
    0
    Microchip's  example should help. You can also try Mike Zoran's USB Sound Card project.

    This might help as well -- USB FM Radio from Silabs.
    http://www.silabs.com/products/mcu/Pages/USBFMRadioRD.aspx


    Not so sure if this helps.
    http://openusbfxs.wordpress.com/
    http://code.google.com/p/openusbfxs/


      USB_Links and libusb
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 05:43:08 (permalink)
    0
    ORIGINAL: stefanopod

    Of course you'll have considered the set of examples from Microchip labeled as USB Device Audio.
    I found them useful.


    Of course I had not sadSmile until I posted this question, which arose to my mind last night Smile

    Thank you then. I'm trying to compile it, adapted to my board.

    I actually also wanted to know if anyone has used it and it there are any pitfalls or special issues.
    I basically imagine of a interrupt-driven reading of one or 2 ADC channels, sampling say @16KHz... well, maybe less on a 18F part Smile and streaming it to the USB in blocks.

    I'll also need an OpAmp since the radio's output is not so large...

    Just a "proof-of-concept" actually.


    GENOVA :D :D ! GODO
    #4
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 05:53:59 (permalink)
    0
    ..and thank you Xiaofan! Yes I had read MZoran's posts.

    That one from SiLabs looks nice. I actually had bought a "similar" one from a local PC distributors some weeks ago but... it is not a "USB device" - it just grabs the power from PC but audio goes via headphones and tuning is done via the old 2 buttons... sad

    Will let you know.

    GENOVA :D :D ! GODO
    #5
    stefanopod
    Super Member
    • Total Posts : 1285
    • Reward points : 0
    • Joined: 2007/06/25 02:33:59
    • Location: Bologna,Italy
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 06:02:13 (permalink)
    0
    If I remember well (and usually I don't) I employed successfully USB Audio Microchip examples, and they were a base for some of my tricks.
    If you have particular issues, maybe my memory will help me better.
    Since I see you are playing with 24FJ, my advice is to port audio trials directly to it. That won't be very difficult, on some sides it will be easier.
    post edited by stefanopod - 2010/04/27 06:07:28

    provando e riprovando
    #6
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 06:47:44 (permalink)
    0
    Thank you Stefano.
    Actually I'm playing with the 24 on another board (see maybe the other threads about it); the FM Radio is connected to a simple 18F miniboard that I use for tests (it was born as a mouse), since I only wanted to send to it I2C commands and listen to radio using the analog output.

    Then I came out with the USB Audio device.

    Tested now the Microchip example, and it seems to work.
    But...
    It has no Mixer interface, and (possibly because of it) I can't route its output straight to the speakers - I have to open an audio-recorder software and then I can retrieve some output. Of course this is not good for a radio Smile

    Moreover, I'd like to add a HID channel for housekeeping, say Tuning etc. If anybody wants to help me struggling with Descriptors... much obliged  Smile



    GENOVA :D :D ! GODO
    #7
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 07:08:43 (permalink)
    0
    ORIGINAL: DarioG
    Moreover, I'd like to add a HID channel for housekeeping, say Tuning etc. If anybody wants to help me struggling with Descriptors... much obliged  Smile


    This only helps a bit as the guy forgot to detach the HID kernel driver before running lsusb.
    http://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg49328.html

    This should help as well (IAD: HID + CDC + Audio + Custom)
    http://code.google.com/p/sdr-widget/downloads/list

    One more (HID + Video + Audio) -- more complicated Linux gadget driver
    http://permalink.gmane.org/gmane.linux.usb.general/30679

      USB_Links and libusb
    #8
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 08:24:23 (permalink)
    0
    Thank you Xiaofan! Checking the 2nd one now.

    GENOVA :D :D ! GODO
    #9
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/27 09:49:48 (permalink)
    0
    Wow Smile
    it works, I have my HID interface Smile

    Back to the audio/radio part now..

    GENOVA :D :D ! GODO
    #10
    mzoran
    Super Member
    • Total Posts : 683
    • Reward points : 0
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/28 13:14:50 (permalink)
    0
    That's a really cool project. I should have thought of that myself.Smile

    I do have a small piece of test code that uses the microphone example descriptors from the Audio spec to create an audio IN device that just inputs a square function. It's a bit too simplified, so it might not be of much use.

    In general, my understanding is that input is easier then output because the hard part is on the host. Each frame you just send the number of samples you were able to sample that frame and the PC does the adjustments. This is different from output, where the PC sends a constant number of samples and the device needs to do the adjustment.

    One concern I have is if a 10bit A/D is going to be enough. If your going to stay with 18F, it might be better to use the 18F2553 or use the 18F26J53 since it's a 3.3V part and the FM receiver is 3.3V. Too bad Microchip doesn't have a 16bit MC with USB and 12bit A/D.

    BTW, you can always use a audio codec chip since they often support a high sample rate with a large number of bits, but I think many of them are a bit hard to interface with a PIC.



    #11
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/28 14:38:59 (permalink)
    0
    Thank you MZoran Smile

    Well, yes, at the moment I'm just testing it. As I wrote it does work as per the example, now I should implement the ADC - I already wrote the code that samples every 125uS and stores into a buffer ready for USB TX (still have to test it).

    I also need to put in there an OpAmp to adapt the radio output to the PIC's input.

    As for the capabilities, well, yes: 16 bit stereo would be better Smile but I don't need right now.
    Maybe a 24 part with a SPI ADC would do...

    I was also going to ask you about the "mixer" part I mentioned above, i.e. have you already succeded in implementin a device that does show with a mixer slider and, hence (I suppose) will let you listen to it via the speakers , straight? (more useful for a radio...)

    GENOVA :D :D ! GODO
    #12
    mzoran
    Super Member
    • Total Posts : 683
    • Reward points : 0
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/28 15:28:30 (permalink)
    0
    I believe at least Vista and greater will show the slider regardless(at least for output). I believe it does this via a digital mixer which essentially throws away bits to lower the volume which isn't so good especially when bits are scarce.

    BTW, I'm playing with vista now and I can't find a way to get the audio mixer to send audio inputs to an output. It appears that the driver needs to have special support for this(Some builtin devices from IDT do this).

    So you might need to write an application anyway to loop the audio from the FM receiver into the speaker which in a way defeats the point of using USB Audio. USB Audio would allow you to use standard applications like Audicity to record and edit msusic from the radio.

    For example, I have my laptop with a builtin Microphone array connected to a big screen LCD television via HDMI. I don't see any obvious way in the audio control panel of Vista to send the microphone sound to the TV.
    post edited by mzoran - 2010/04/28 17:05:21
    #13
    xiaofan
    Super Member
    • Total Posts : 6247
    • Reward points : 0
    • Joined: 2005/04/14 07:05:25
    • Location: Singapore
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/28 15:57:18 (permalink)
    0
    You may need to write an application anyway.

    From Silabs page (Vista supported)

    http://www.silabs.com/products/mcu/Pages/USBFMRadioRD.aspx
    http://www.silabs.com/Support%20Documents/TechnicalDocs/AN264.pdf



    5. Windows Software
    The graphical user interface (GUI) software is located in AN264SW.zip, under the “GUI” directory. This software
    was developed in C++ using Visual Studio 6.0.

    When the GUI is first launched, it begins by looking for a USB FM Radio device. Once a device is found, it is
    opened up as a USB Audio Device for audio streaming and as a HID device for FM Tuner control. In addition, the
    default WAV output device is opened to playback the audio stream.

    Audio Stream—The host application uses a circular buffer of 20 32 kB blocks to accept audio from the USB FM
    Radio device. Initially, 19 of the buffers are filled with audio data. Next, this data is sent to the WAV output device,
    and as streaming continues, pointers to the first free block and first playable block are incremented around the
    circular buffer to provide a constant and seamless flow of audio.

    Audio will stream until a user action occurs such as tune, seek, or an alteration of radio settings. When this occurs,
    the audio stream will stop, and the commands for the requested action are sent down through the HID interface.
    Once the acknowledgement of the command comes back, the GUI is updated and stream playback will continue.

    Device Status—In addition to the audio streaming, the device is also polled for its current attributes such as the
    current station, the received signal strength, and a stereo/mono indicator. As this information changes, it will also
    change on the display of the GUI.

    Device Removal—Audio streaming and polling will stop if the device is disconnected from the USB. In this case,
    all of the device handles are closed, and the host application will begin to poll for connected devices.

    USB Device Driver—Because Windows has built-in drivers for USB audio and HID class devices, the USB FM
    Radio does not require an OEM supplied driver disk for operation. The player executable is the only required user
    software. A similar approach is possible for other operating systems, if they have built-in support for these two USB
    device classes.


      USB_Links and libusb
    #14
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/29 02:52:10 (permalink)
    0
    Thank you guys.
    What I meant is that I can, usually, activate Microphone (an analog one... that may be different) route directly to speaker output, on almost any PC that I had since Win98.
    Indeed it could be, that it can be done only with analog sources...

    Ok, writing such an app is not that difficult: BTW, I found that the Voice Recognition Tab, in Control Panel (XP) has an option to "test" the source and this lets you hear the USB Mic output.

    Or, we should try making the peripheral a "Generic Line Input" rather than a microphone: has anybody tried it? Is it difficult, or is it enough changing the descriptors?

    GENOVA :D :D ! GODO
    #15
    idefix
    Senior Member
    • Total Posts : 141
    • Reward points : 0
    • Joined: 2009/10/29 09:58:14
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/29 06:51:35 (permalink)
    0
    I suspect it's more complicated then the descriptors because you're trying to patch across two audio devices. For Pulseaudio, that became possible recently by
    loading a 'loopback' addon module, which then allows e.g to cross connect from USB Microphone / Guitar input / Line etc to internal soundcard speakers. I've managed to get iMic and Behringer UCG102 working with the onboard soundcard this way but the latency makes a reverb line superfluous. Perhaps that's why
    the 'Monitor Microphone via Headphone' button is not available on non-analogue mixer panels.
    #16
    mzoran
    Super Member
    • Total Posts : 683
    • Reward points : 0
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/29 09:40:50 (permalink)
    0
    I think this may have been removed in Vista. I'm not sure analog sources are supported anymore and idefix gives good reasons why it doesn't work with digital sources.

    Like you said, such an application isn't that hard to build and an application is needed regardless to be able to control the receiver for tuning the station.

    I was looking at the SiLabs receiver chip and it appears to be far superior to the Sparkfun module. You have to go through the sales rep to get the technical documentation, but from what I see in the marketing material one version of the receiver has builtin D/A converters and can use a simple loop antanna on the PCB. That's a big advantage over having a 2 foot piece of wire hanging off the board. They advertise this is the receiver chip used by Microsoft's "Zune".

    Do you have the technical documentation to the SparkFun module? I only see some example code for Atmel and a doc for a "similar" NXP module.

    This project may still be fun to do even if "commercial" quality isn't obtainable with these components.
    #17
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: USB audio device for a FM Radio 2010/04/29 13:27:59 (permalink)
    0
    I see guys, thank you. Yes an application will be the way to go - I'm actually making up an OCX to be embedded into my home automation (I used to use a RS232 radio but it ceased working and it's not available any more... maybe 2002 or so... not to mention that RS232 are fading away!)

    The sparkfun module looks complete enough - probably the one I got has no RDS but no problem. The I2C interface is nice and SPI would be useful as well. I purchased it because I had a 25$ Visa free bonus Smile and was in need of a radio. To me too, the Silabs module sounds better... at a glance.

    Problem is, I've interfaced it correctly and can talk (using HID). But, I only receive noise - changing noise when I tune...
    I do have the 2 meter antenna that I used to use before with the other radio.
    Now I'm not sure if I need any shielding or such, in theory I should not need it but...

    GENOVA :D :D ! GODO
    #18
    Jump to:
    © 2019 APG vNext Commercial Version 4.5