I am trying to build a project that does a spectrum analysis on audio playing through my Raspberry Pi using FFT. I will be using GPU_FFT in C++ to do the bulk of the calculations (which should be simple enough) but I can't find any resources on getting the actual data to process. My plan is to play audio to my Pi using Raspotify to Bluetooth, pipe the audio that is currently playing to my program that converts it to a format that is usable by GPU_FFT, and then process the resulting data as need be. The problem is how to access the audio being played currently that I might generate Hanning Windows (my best bet at the moment) to be sent to the FFT API.

I am prepared to utilize external hardware or shields as well to aid in this process. I have not worked with DSP at this level before and may be approaching this wrong. I am using a Raspberry Pi 3 Model B+.

Thanks for any help!

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • I don't have enough information specific to the Pi to write a proper answer, but I think googling for "Linux virtual sound card" might help, as might this answer on another SE site: How to record the audio output on raspian. – Mark Smith Apr 17 at 5:57
  • This seems like a promising line to research. Does that produce a static file or is the data able to be processed live, instant to instant? Also could it be a good idea to use a physical external soundcard for the Pi? – Quiixotic Apr 17 at 23:57

Let me see. I don't know nothing about FFT and DSP,not to mention Hanning windows. But I think your problem can be boiled down to ***how to convert analog

  • audio to digital***.

    Part 1 - Converting Analog Audio Signal to Digital

    For ordinary humans, analog audio signal is within the range of 20kHz. (I am assuming your project is not for dogs that have bigger ears) And according to my rusty knowledge in signal processing and information theory, the sampling rate should be twice (or half, I forgot) as high, ie, 40kHz, to make sure there is not information loss, or HiFi enough.

    And by my usually dodgy calculation, 40kHz means 1/40k = 1ms/40 = 1000uS/40 = 25uS.

    Now the problem is to find an ADC that can sample and convert audio signals at 40kHz (40kps), 25uS.

    Most cheap ADCs can do the job. For example, the newbie's favourite ADC, MCP3008, can do 10 bit 200kps.

    MCP3008 ADC Datasheet (10 bit, 200ksps) - Microchip

    Part 2 Extracting Streaming Digital Audio Signal From HDMI Interface

    The OP clarified that he is streaming video/audio directly from Internet. therefore no analog signal to digital conversion is required.

    In this case, I would suggest to fiddle with the HDMI interface. First the basic HDMI audio specification summary:

HDMI audio has the uncompressed stereo PCM format.

Eight channels of uncompressed audio at sample sizes of 16/20/24-bit, with sample rates of 32/44.1/48/88.2/96/176.4/192 kHz.

The Display Data Channel (DDC) is a communication channel based on the I2C bus specification. which is used by the HDMI source device to read the data from HDMI sink device to learn what audio/video formats it can take

Now I would suggest the following:

First, Rpi I2C channel to read from the I2C compatible DDC to know the audio format streaming in.

Second, Rpi GPIO to directly read the digital audio signals (after logical level conversion, and optical isolation, if necessary) from the hardware HDMI connector pins.

Reference - HDMI Wikipedia

HDMI - Wikipedia

HDMI (High-Definition Multimedia Interface) is a proprietary audio/video interface for transmitting uncompressed video data and compressed or uncompressed digital audio data from an HDMI-compliant source device, such as a display controller, to a compatible computer monitor, video projector, digital television, or digital audio device. HDMI is a digital replacement for analog video standards

HDMI are electrically compatible with Digital Visual Interface (DVI). No signal conversion is necessary, nor is there a loss of video quality when a DVI-to-HDMI adapter is used.

For digital audio, if an HDMI device has audio, it is required to implement the baseline format:

stereo (uncompressed) PCM.

Other formats are optional, with HDMI allowing up to 8 channels of uncompressed audio at sample sizes of 16-bit, 20-bit and 24-bit, with sample rates of 32 kHz, 44.1 kHz, 48 kHz, 88.2 kHz, 96 kHz, 176.4 kHz and 192 kHz.

HDMI also carries any compressed audio stream, such as Dolby Digital and DTS, and up to 8 channels of one-bit DSD audio at rates up to four times that of Super Audio CD.

With version 1.3, HDMI allows lossless compressed audio streams Dolby TrueHD and DTS-HD Master Audio

Display Data Channel (DDC)

The Display Data Channel (DDC) is a communication channel based on the I2C bus specification. HDMI specifically requires the device implement the Enhanced Display Data Channel (E-DDC), which is used by the HDMI source device to read the E-EDID data from the HDMI sink device to learn what audio/video formats it can take. HDMI requires that the E-DDC implement I2C standard mode speed (100 kbit/s) and allows it to optionally implement fast mode speed (400 kbit/s).

/ to continue

  • Thank you for responding to my question. This is not exactly the problem I am trying to fix since I do not have any analog audio source (my audio is streaming over the Internet through Spotify and Raspotify). In that case I do not think I will need an ADC. – Quiixotic Apr 17 at 23:53
  • Ah, if your audio is streaming over the Internet, then you can extract the digital audio signal at the hardware HDMI connector pins. Please see if my Part 2 of answer makes any sense. :) – tlfong01 Apr 18 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.