iam working on a small project where i play music over bluetooth to my Raspberry pi. Also i would like to analyse the audio too.
How can i pipe the Raspberry pi audio output to a gstreamer c script? I got a correctly working solution with an mp3 file, but ofc i would like to expand this to read audio output from my RPi.
Here is the source i used in my gstreamer script to read from a file:
data.source = gst_element_factory_make ("uridecodebin", "source");
g_object_set (data.source, "uri", "file:///home/pi/example.mp3", NULL);
Do i need to loopback the audio to the microphone jack and use this as a source? Or is there a better way to do this?
I'm not familiar with the RPi. Assuming it runs a regular linux chances are high that the sound output is done via PulseAudio. for each output device PulseAudio also offers a "monitor" device fir this output. This one can be used to capture audio data.
These monitor devices may be made visible by some system configuration - but I'm not sure. Maybe they exist by default.
From a GStreamer point of view you would use the "pulsesrc" element to capture audio:
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-pulsesrc.html
From there your regular GStreamer functions apply - meaning you could write the data to disk, make live analysis of the data etc.. Since this can be quite complex its hard to give a general advice..
Related
I hope to know how to capture audio by using dummy sound card driver.
I'm thinking how to implement the steps below.
we play audio in ubuntu, however the audio is just played through dummy sound card driver, to capture audio stream.
captured audio is sent to windows through network.
audio is actually played in windows.
What you need is to activate ALSA snd-aloop module, that provides a full-duplex virtual loopback soundcard. Please have a look to the following links for instructions about activation and example usage:
https://github.com/TheSalarKhan/Linux-Audio-Loopback-Device
https://sysplay.in/blog/linux/2019/06/playing-with-alsa-loopback-devices/
A couple of important points to consider:
The subdevices are linked in pairs; whatever you play on hw:n,0,m goes out on hw:n,1,m (see the example in the 1st link)
The first application opening one of the subdevices will force the second application to use the same set of parameters: sample rate, format, number of channels. For example, suppose the recording application opens a capture stream on hw:2,1,0 with stereo/44100/S16_LE format; the playback application on hw:2,1,0 will be forced to use a the same stereo/44100/S16_LE format
Hope this helps
I want to read the data generated by USB sound card connected to my RaspberryPi using a C code. The samples should be stored in an array or are written to a csv file.
I am using ALSA library through a function "snd_pcm_readi". Can someone explain how to access the data read by "snd_pcm_readi"?
Or is there a better alternative?
Look at the libusb library, https://libusb.info/
This library gives you simple C functions to find and open the device, and then send and receive data. You may want to do some reading about USB devices.
You may also want to look at udev - you can write a udev rule to symbolically link the desired device to a known filename.
You may need to know the vendor_id and product_id. At the command line, enter lsusb to see the usb devices.
I recently starting using Gstreamer and I have succeeded in muxing an audio stream and 2 camera streams into a MPEG-TS file using the mpegtsmux and now want to inject telemetry data from an accelerometer into the data stream. I was thinking by using teletext to do that, which is supported by the mpegtsmux and then use the appsrc to inject the data into the pipeline. Does anyone succeeded in doing this before, I can't seem to find any examples with injecting teletext into a data stream.
How about to use the sound channel without compression?
Use the application/x-teletext caps to create pad to the mux..
I'm yet to able successfully do it. If you have, I'd be interested on how you used appsrc.
I need some pointers where to start with the following:
From any application that plays audio using ALSA to the connected speaker I'd like to grab the samples and do some audio processing.
I am not in control of the player and I'd like to be able to process the audio from any source. Basically it will be an UV-meter, perhaps later with FFT (all just on the command line). Additionally I'd like my app to be self-contained.
In my research I've found:
There is a loopback kernel module.
You can do fancy stuff with the configuration file.
There is the ability to create plugins.
Using the kernel module and altering the configuration file introduces some dependencies of my application to the configuration of the system.
And creating a plugin I give up control over the app and cannot start/terminate it whenever I want.
This is not satisfactory to me so I'd like to know if there is a way to either:
create a loopback device programmatically
or is there any other way to read from the pcm playback device other applications are writing to.
You can use the pulseaudio for linux where you can very easily create a loopback device .There ia a pactl command -it will help you create a null sink and you can loopback from it .
something like this
//this would create a null sink with specified channel conf
pactl load-module module-null-sink sink_name=sink6ch format=s16le rate=48000 channels=6 channel_map=front-left,front-right,front-center,lfe,rear-left,rear-right
//make it default
pactl set-default-sink sink6ch
you can use its monitor device to read about the monitor devices of pulse audio
How can I connect an Arduino board and MATLAB for image processing?
I am making an autonomous robot which require image processing in MATLAB.
You can use the MATLAB-to-Arduino package at the offical MATLAB site, "MATLAB Interface to Arduino".
If you have serial communication on the Arduino, Matlab has built in tools for talking with the chip over USB or RS232. It is fairly simple to setup, but if your images are high in resolution you may not get the necessary speed from standard RS232.
something along the lines of:
s=serial('COM1','baudrate',115200)
Then you can read and write to the Arduino through Matlab functions and scripts
You can get connected to the MATLAB interface by simply using the serial and fopen commands on MATLAB
eg:
s=serial('COM2','Baudrate',9600,'Databits',8);
fopen(s);
count=0;
while count<50
a=fscanf(s);
count=count+1;
end
fclose(s);
whereas on Arduino, use Serial.print() function.
Simple data can be sent using this. I never tried camera by using this technique. But by using a camera shield mounted on Ardunino, taking snapshots and later sending the data through Arduino to MATLAB as a matrix might work. Just an idea, might be possible.
Edit1:
I was looked up more into this, and found some potential hardwares for the same:
1. ArduCam Shield for Arduino
2. https://www.sparkfun.com/products/11418