0

I am trying to decode the data which is received through rtl_fm with rtl-sdr. I am using the below command

rtl_fm -f 144.5e6 -s 200000 -r 48000 | aplay -r 48000 -c 1 -f S16_LE | minimodem --rx 1200 -A0

I am receiving the audio, but minimodem is not decoding the data. I am using alsa driver. If i run this command

minimodem --rx 1200 -A0

I am getting this error... E: Cannot create ALSA stream: No such file or directory

When i use pulseaudio, if I play any audio and then if i run minimodem command, the playing audio is breaking and totally distorted.. Can anyone please tell me, what i am doing wrong...

6
  • Let me see. Rtl_fm can send audio data to aplay which decodes data to audio signal (ALSA) and play it on the loudspeaker. On the other hand, minicom usually inputs strings of binary/text (ASCII)characters/strings and echo or do some character/string processing and output to the text/video terminal. In short, minicom does not have a audio signal decoder/converter to output audio stuff.
    – tlfong01
    Commented Jun 1, 2019 at 3:09
  • Thanks for your reply tlfong01.... This is not minicom.... it is minimodem. Commented Jun 1, 2019 at 3:32
  • Ah, I am terribly sorry. I am a newbie and only know minicom, and never heard of minimodem. I need to google and learn more. My apology for the foolish mistake. :)
    – tlfong01
    Commented Jun 1, 2019 at 3:40
  • So I googled to catch up - minimodem - general-purpose software audio FSK modem whence.com/minimodem It is (1) a command-line program decoding audio modem tones, acts a general-purpose software FSK modem, supports protocols such as RTTY, (2) can play and capture audio modem tones in real-time via the system audio device, or in batched mode via audio files, (3) can be used to transfer data between computers using audio cable, or between remote computers using radio, telephone, or another audio communications medium. I forgot what is FSK/RTTY, need google on, :( / to continue, ...
    – tlfong01
    Commented Jun 1, 2019 at 3:57
  • I forgot what is FSK. So I googled. The following links refreshes my memory, and also my ears which missed a lot, the modem sound! :) - The Sound of dial-up Internet 9,560,315 views youtube.com/watch?v=gsNaR6FRuO0 Sound of the dialup modem explained 339,875 views youtube.com/watch?v=abapFJN6glo The sound of the dialup, pictured - Oona Räisänen 2012nov17 windytan.com/2012/11/the-sound-of-dialup-pictured.html FSK (Frequency-shift keying) - Wikipedia en.wikipedia.org/wiki/Frequency-shift_keying
    – tlfong01
    Commented Jun 1, 2019 at 4:14

2 Answers 2

2

Try to understand how minimodem output redirection work:

man minimodem|minimodem --tx -8 1200|tee /tmp/datas.wav
du -h /tmp/datas.wav
0     /tmp/datas.wav

man minimodem|minimodem --tx -8 1200 -f /tmp/datas.wav
du -h /tmp/datas.wav
6.4M  /tmp/datas.wav

Try to understand how aplay output redirection work:

aplay /tmp/datas.wav|tee /tmp/aplay_stdout.datas
du -h /tmp/datas.wav
0  /tmp/datas.wav

Also return an output buffer of 0 byte empty file, it's bad.

You must use fifo or another tricks, and understand that: minimodem need WAV file ,yes it can be done with a specific command and tool capable to encode raw to wav and using pipe, for example with this tool : SoX - Sound eXchange, the Swiss Army knife of audio manipulation and using FIFO file.

And please , specify HOW you send your datas (device type, modulation etc...), thank you.

AUTOMATIC-TASK SCRIPT

#!/bin/bash
# rtl_sox_minimodem.sh
# Automatic FM/FSK demodulation task 
# with rtl_fm,sox,aplay and minimodem 
# by Ephemeral (2019)


# YOU CAN CONFIGURE THIS VARIABLES
FREQUENCY=;
AUDIO_FREQUENCY=48000;
BAUD=1200;
INTERACT=0 # 0 or 1, 0 for interactive questions...
# USE_GUI=1, open aplay and minimodem in new terminal
USE_GUI=1;
# All 20 secs check for pidof rtl_fm, aplay,
# minimodem (INTERACT variable must be 0 and FORCE_RUN must be 1)
FORCE_RUN=1
TIME_TO_CHECK_ALWAYS_RUNNING=20;
MINIMODEM_LOG=/tmp/minimodem.$(date +"%Y-%m-%d_%H-%M-%S").log

FIFO=/tmp/fifo;
MINIMODEM_CMD="minimodem --rx -8 ${BAUD} -f ${FIFO}";
APLAY_CMD="aplay ${FIFO}";
RTL_FM_SOX_CMD="rtl_fm -f ${FREQUENCY} -s ${AUDIO_FREQUENCY} -|sox -t raw -esigned-integer -b16 -r${AUDIO_FREQUENCY} - -t wav -esigned-integer -b16 -r${AUDIO_FREQUENCY} ${FIFO}";




function ERROR(){
    echo -e "\t$(tput setaf 1)${1}$(tput sgr 0)"
}
function INFO(){
    echo -e "\t${1}"
}
function WARN(){
    echo -e "\t$(tput setaf 3)${1}$(tput sgr 0)"
}



function CHECK(){
echo -e "\n\n[$(date)]"
if [ ! -e "${FIFO}" ];then
    INFO "No FIFO file, create this...";
    mkfifo /tmp/fifo
    if [ "${?}" -eq "0" ];then
        INFO "FIFO file created with success."
    else
        ERROR "An error was occured when create FIFO, please check the error.";
        exit 1;
    fi;
else
    INFO "FIFO file already exists...";
fi;

if [ -z "$(pidof rtl_fm)" ];then
    INFO "rtl_fm is not running, start that...";
    if [ ! -z "$(pidof minimodem)" ]&&[ ! -z "$(pidof aplay)" ];then
        WARN "rtl_fm require aplay and minimodem not running";
        WARN "cannot start rtl_fm."

        if [ "${INTERACT}" -eq "0" ];then
            INFO "Force Kill pid=$(pidof minimodem aplay)";
            kill -9 $(pidof minimodem aplay);
        else
            CHOICE=
            while [ -z "${CHOICE}" ]:
            do
                INFO -en "Would you like to close aplay and minimodem pid ? >> "
                read CHOICE
                case "${CHOICE}" in
                    y|Y) INFO "Kill pid=$(pidof aplay minimodem)";kill -9 $(pidof aplay minimodem); break;;
                    n|N) echo "Bye";exit 0;;
                    *) ERROR "Please enter y or Y (Yes), n or N (No)!"; CHOICE="";;
                esac
            done;
        fi;
    else
        INFO "Aplay and minimodem is not running, ok to start rtl_fm...";
    fi;
    INFO "${RTL_FM_SOX_CMD}";
    # 
    if [ "${USE_GUI}" -eq "1" ];then

        # cannot use pipe in --command , then use current shell and open inly minimodem and aplay in new term.
        #lxterminal --title="Minimodem" --command="${MINIMODEM_CMD}";
        rtl_fm -f ${FREQUENCY} -s ${AUDIO_FREQUENCY} -|sox -t raw -esigned-integer -b16 -r${AUDIO_FREQUENCY} - -t wav -esigned-integer -b16 -r${AUDIO_FREQUENCY} ${FIFO} &

    else
        rtl_fm -f ${FREQUENCY} -s ${AUDIO_FREQUENCY} -|sox -t raw -esigned-integer -b16 -r${AUDIO_FREQUENCY} - -t wav -esigned-integer -b16 -r${AUDIO_FREQUENCY} ${FIFO} &
    fi;
    INFO "rtl_fm started: $?, continue in 10 secs...";
    sleep 5;
else
    INFO "rtl_fm already started, noting to done...";
fi;


if [ -z "$(pidof minimodem)" ];then
    INFO "Minimodem is not running, start that...";
    if [ "${USE_GUI}" -eq "1" ];then
        echo "Start at $(date)" >> "${MINIMODEM_LOG}";
        lxterminal --title="Minimodem" --command="bash -c \"${MINIMODEM_CMD}\"";
    else
        minimodem --rx -8 ${BAUD} -f ${FIFO} &>"${MINIMODEM_LOG}" &
    fi;
    sleep 3;
    if [ -z "$(pidof minimodem)" ];then
        WARN "ERROR: unable to run minimodem, re-trying..."
        kill -9 $(pidof rtl_fm aplay sox);
        CHECK;
        return
    fi;
else
    INFO "Minimodem already started, nothing to done...";
fi;



if [ -z "$(pidof aplay)" ];then
    INFO "Aplay is not running, start that...";

    if [ "${USE_GUI}" -eq "1" ];then
        lxterminal --title="Aplay" --command="${APLAY_CMD}";
    else
        aplay "${FIFO}" &
    fi;
else
    INFO "Aplay already started, nothing to done...";
fi;

}




function MAIN(){

    if [ -z "${FREQUENCY}" ];then
        ERROR "Please configure FREQUENCY variable before using this script.";
        exit 1;
    fi;

    kill -9 $(pidof sox minimodem aplay rtl_fm);

    if [ "${FORCE_RUN}" -eq "1" ];then
        if [ "${INTERACT}" -eq 1 ];then
            ERROR "ERROR: You cannot use INTERACT=1 when you use FORCE_RUN=1";
            exit 1;
        else
            if [ ! -f "${MINIMODEM_LOG}" ];then
                echo "[+] Creating minimodem log file ${MINIMODEM_LOG}";    
                touch "${MINIMODEM_LOG}";
            fi;

            while :
            do
                CHECK
                INFO "Waiting ${TIME_TO_CHECK_ALWAYS_RUNNING} secs before verification...";
                sleep ${TIME_TO_CHECK_ALWAYS_RUNNING};
            done;
        fi;
    else
        CHECK;
    fi;
}

MAIN

HOW TO USE THIS SCRIPT ?

1/ REAL-TIME+LXTERMINAL

configure FREQUENCY variable in the script header and then:

sudo chmod ug+x rtl_sox_minimodem.sh
bash rtl_sox_minimodem.sh

As you can see , rtl_fm use current terminal where the bash rtl_fm command as running, minimodem is opened in a new terminal for real-time display demodulated datas and then anoter terminal is opened for display the sound for the user.

The script is configured by default for checking if he is already ALIVE every 20 secondes, you can adjust this value for your needs.

Try to close the aplay or minimodem terminal (or the two term.) manually when all is running, wait 20 secs and normally all is automaticly restarted correctly without any errors (for me for sure) and you can see the demodulated datas in the minimodem terminal.

If you see one error:

ERROR: unable to run minimodem, re-trying...

Please wait for another iteration of the loop, and check if minimodem terminal is finally open, he must be.

2/ BACKGROUND-TASK + POSSIBLE REAL-TIME FROM ANOTHER TERM.

configure USE_GUI=0 in the script header and then run:

sudo chmod ug+x rtl_sox_minimodem.sh
bash rtl_sox_minimodem.sh

With this mode all is done in background and minimodem datas are written into a specified file /tmp/minimodem.${date}.log, then you can open a new terminal (manually) and use (the filename is specified in this script output):

tail -f /tmp/minimodem.${date}.log 

You can also filtered any specific datas in real-time:

tail -f /tmp/minimodem.${date}.log | grep "ONLY KNOWN DATAS"

for showing the datas in real-time (because with USE_GUI=0 minimodem redirect output in this file). Or read this file at any time.

MORE

You can put this script at-startup by creating an systemd unit file and configure it with this script.

This script was written relatively quickly, it can and must be improved.

14
  • 1
    I did not read the minimodem user guide carefully, and so I did not know that it needs a wave file as input. Also I did not know the output redirection thing, so I didn't understand why there is no ALSA stream. But I did once upon a time used a real, physical hardware modem. So perhaps I can guess why software minimodem can NEVER output an ALSA stream.
    – tlfong01
    Commented Jun 1, 2019 at 7:09
  • @tlfong01, yes no problem, I understand. How are you since our last conversation on LCD screens? :) He have not specified how he send his datas... It is not very usefull for a good answer.
    – Ephemeral
    Commented Jun 1, 2019 at 7:30
  • Ah, I have not yet built the touch LCD kernel module. I have diverted to the LCD 2 line 40 character project, and then to a GPS project. My plan is to first get the GPS text and graphical data. Then I come back to build the touch LCD kernel module, and then display text data in monochrome LCD, and the GPS sky map in the RGB LCD. raspberrypi.stackexchange.com/questions/98840/…
    – tlfong01
    Commented Jun 1, 2019 at 7:47
  • Please don't use pictures of text. Instead paste the text direct into the answer.
    – Ingo
    Commented Jun 1, 2019 at 19:30
  • Hi, Ephemeral... Thank you very much...Your examples works perfectly. One small request to you, is there anyway to pass the sox output directly to minimodem like this.. rtl_fm -> sox -> minimodem. Because once i stops the minimodem command and opens it back, i am getting this error.. "myfifo: File contains data in an unknown format." Or is there anyway to solve this. I am going to transmit the data form one computer to the another. If anyone of the computer breaks and connect again it has to work without error... Thank you again... Commented Jun 2, 2019 at 5:12
0

Question

Try to decode the data through rtl_fm with rtl-sdr

Receiving audio, but minimodem is not decoding the data

Using ALSA driver, coimmand minimodem --rx 1200 -A0 - error Cannot create ALSA stream

Answer

I guess the software minimodem, like the hardware modem, has the following signal specifications.

FSK (Frequency Shift Keying)

FSK is a signal consisting two frequencies, "mark" frequency denoting "1", and "space" frequency denoting "0". The modem uses FSK signals to talk to the telephone exchange.

RS232/UART

When two modems are connected, they talk using serial signals, such as 9600 baud, no parity, 1 stop bit.

I guess, for software modems, the input may be in WAV format, but the contents is still FSK or UART, not audio signals.

In other words, minimodem is never designed to output audio signals.

Appendices

minimodem - general-purpose software audio FSK modem

minimodem - general-purpose software audio FSK modem for GNU/Linux systems 30,947 views

The Sound of dial-up Internet 9,560,315 views

Sound of the dialup modem explained 339,875 views

The sound of the dialup, pictured - Oona Räisänen 2012nov17

FSK (Frequency-shift keying) - Wikipedia

Frequency-shift keying (FSK) is a frequency modulation scheme in which digital information is transmitted through discrete frequency changes of a carrier signal.The technology is used for communication systems such as telemetry, weather balloon radiosondes, caller ID, garage door openers, and low frequency radio transmission in the VLF and ELF bands. The simplest FSK is binary FSK (BFSK). BFSK uses a pair of discrete frequencies to transmit binary (0s and 1s) information.[2] With this scheme, the "1" is called the mark frequency and the "0" is called the space frequency.

fsk rs232

ALSA (Advanced Linux Sound Architecture) - Wikipedia

ALSA is part of the Linux kernel, while PulseAudio is middleware, a part of the lower levels of the desktop stack. So is SDL. Advanced Linux Sound Architecture (ALSA) is a software framework and part of the Linux kernel that provides an application programming interface (API) for sound card device drivers.

Some of the goals of the ALSA project at its inception were automatic configuration of sound-card hardware and graceful handling of multiple sound devices in a system.

The sound servers PulseAudio and JACK (low-latency professional-grade audio editing and mixing), the higher-level abstraction APIs OpenAL, SDL audio, etc. work on top of ALSA and implemented sound card device drivers. On Linux systems, ALSA succeeded the older Open Sound System (OSS).

ALSA was designed with some features which were not, at the time of its conception, supported by OSS:

Hardware-based MIDI synthesis.

Hardware mixing of multiple channels.

Full-duplex operation.

Multiprocessor-friendly, thread-safe device drivers.

Besides the sound device drivers, ALSA bundles a user-space library for application developers who want to use driver features through an interface that is higher-level than the interface provided for direct interaction with the kernel drivers.

Unlike the kernel API, which tries to reflect the capabilities of the hardware directly, ALSA's user-space library presents an abstraction that remains as standardized as possible across disparate underlying hardware elements.

This goal is achieved in part by using software plug-ins; for example, many modern sound cards or built-in sound chips do not have a "master volume" control. Instead, for these devices, the user space library provides a software volume control using the "softvol" plug-in, and ordinary application software need not care whether such a control is implemented by underlying hardware or software emulation of such underlying hardware.

Concepts

This section provides an overview of basic concepts pertaining to ALSA.7[9]

Typically, ALSA supports up to eight cards, numbered 0 through 7; each card is a physical or logical kernel device capable of input, output. Furthermore, each card may also be addressed by its id, which is an explanatory string such as "Headset" or "ICH9".

A card has devices, numbered starting at 0; a device may be of playback type, meaning it outputs sound from the computer, or some other type such as capture, control, timer, or sequencer[10]; device number 0 is used by default when no particular device is specified.

A device may have subdevices, numbered starting at 0; a subdevice represents some relevant sound endpoint for the device, such as a speaker pair. If the subdevice is not specified, or if subdevice number −1 is specified, then any available subdevice is used.

A card's interface is a description of an ALSA protocol for accessing the card; possible interfaces include: hw, plughw, default, and plug:dmix. The hw interface provides direct access to the kernel device, but no software mixing or stream adaptation support. The plughw and default enable sound output where the hw interface would produce an error.

An application typically describes sound output by combining all of the aforementioned specifications together in a device string, which has one of the following forms (which are case-sensitive):

An ALSA stream is a data flow representing sound; the most common stream format is PCM that must be produced in such a way as to match the characteristics or parameters of the hardware, including:

sampling rate: often 44.1 kHz on home stereos, or 48 kHz on home theaters, yet up to 88.2 kHz, 96 kHz, or even 192 kHz for hi-fi audio production or reproduction.

sample width: measured in some number of bits per sample (such as 8, 16, 24, or 32 bits/sample)

sample encoding: such as endianness

number of channels: 1 for mono, 2 for stereo, or 6 for AC-3/IEC958

Implementations

The ALSA System on Chip (ASoC) layer aims to provide better support for ALSA on embedded systems that use a system-on-chip (SoC) design.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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