LoginSignup
8
8

More than 5 years have passed since last update.

[メモ] Raspberry Pi + DVB-T USBチューナー(RTL-SDR)で FMラジオを聴く + もう一台のRPi2でpifmでFMとばす.

Last updated at Posted at 2016-06-11

概要

環境

  • Rapberry Pi 2 / 3
  • 2016-05-27-raspbian-jessie-lite.img
  • DVB-T+DAB+FM USB チューナー(+アンテナ): RTL2832U R820Tとかで、アマゾンとかで検索
  • イヤホン (ラズパイに挿す)

手順

  1. いつもの初期設定. USBチューナとイヤホンをラズパイに挿す。
  2. sudo apt-get install rtl-sdr
  3. rtl_fm -f 96.3e6 -M wbfm -s 200000 -r 48000 - | aplay -r 48k -f S16_LE
    # 96.3e6 (=96.3MHz)の数値を変えて、選局。

その他

コマンドラインでの音量の変更(amixer)

  • Sound configuration on Raspberry Pi with ALSA
    • amixer controls
      numid=1,iface=MIXER,name='PCM Playback Volume'
      =>numid=1が再生ボリューム
    • amixer cset umid=1 75%
      =>ボリュームを75%
    • amixer cget umid=1
      =>現在の設定値取得..
      min=-10239,max=400という範囲でvalues=-2258とでたら、
\frac{-2258-(-10239)}{400-(-10239)} = \frac{7981}{10639} = 0.750... \fallingdotseq 75\%

(pifm) 別のRaspberry Pi 2からFMをとばしてきく

#WAV形式: 16 bit 22.050 kHz Mono
sudo ./pi2fm sounds/star-wars.wav 77.7
#
#avconv: Audio形式変換
sudo apt-get install libav-tools
#
# mp3を変換して、FM飛ばす。
avconv -i sound.mp3 -f s16le -ar 22.05k -ac 1 -vol 128 - | sudo ./pi2fm - 111.1
## -i 入力ファイル
## -f 出力形式
## -ar 出力サンプリング周波数
## -ac チャンネル数
## -vol 256 で通常ボリューム 128で半分

ふつうにイヤホンでmp3聴く...

# avconvで変換 => aplay
avconv -i sound.mp3 -f s16le -ar 44.1k -ac 2 - | aplay -r 44.1k -f S16_LE -c 2
#
#
# sudo apt-get install mpg321 
mpg321 sound.mp3

ログ

USBのVID/PID
pi@raspberrypi:~$ lsusb
Bus 001 Device 005: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 001 Device 004: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@raspberrypi:~$
rtl_fmのヘルプ
pi@raspberrypi:~$ rtl_fm -help
rtl_fm, a simple narrow band FM demodulator for RTL2832 based DVB-T receivers

Use:    rtl_fm -f freq [-options] [filename]
        -f frequency_to_tune_to [Hz]
            use multiple -f for scanning (requires squelch)
            ranges supported, -f 118M:137M:25k
        [-M modulation (default: fm)]
            fm, wbfm, raw, am, usb, lsb
            wbfm == -M fm -s 170k -o 4 -A fast -r 32k -l 0 -E deemp
            raw mode outputs 2x16 bit IQ pairs
        [-s sample_rate (default: 24k)]
        [-d device_index (default: 0)]
        [-g tuner_gain (default: automatic)]
        [-l squelch_level (default: 0/off)]
        [-p ppm_error (default: 0)]
        [-E enable_option (default: none)]
            use multiple -E to enable multiple options
            edge:   enable lower edge tuning
            dc:     enable dc blocking filter
            deemp:  enable de-emphasis filter
            direct: enable direct sampling
            offset: enable offset tuning
        filename ('-' means stdout)
            omitting the filename also uses stdout

Experimental options:
        [-r resample_rate (default: none / same as -s)]
        [-t squelch_delay (default: 10)]
            +values will mute/scan, -values will exit
        [-F fir_size (default: off)]
            enables low-leakage downsample filter
            size can be 0 or 9.  0 has bad roll off
        [-A std/fast/lut choose atan math (default: std)]

Produces signed 16 bit ints, use Sox or aplay to hear them.
        rtl_fm ... | play -t raw -r 24k -es -b 16 -c 1 -V1 -
                   | aplay -r 24k -f S16_LE -t raw -c 1
          -M wbfm  | play -r 32k ...
          -s 22050 | multimon -t raw /dev/stdin

pi@raspberrypi:~$
rtl-sdrパッケージ
pi@raspberrypi:~$ apt-cache showpkg rtl-sdr
Package: rtl-sdr
Versions:
0.5.3-3 (/var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_jessie_main_binary-armhf_Packages) (/var/lib/dpkg/status)
 Description Language:
                 File: /var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_jessie_main_binary-armhf_Packages
                  MD5: e83ebc54466f1df73b3c0ad5540e4f0d


Reverse Depends:
Dependencies:
0.5.3-3 - librtlsdr0 (5 0.5.3-3) libc6 (2 2.15) libusb-1.0-0 (2 2:1.0.8)
Provides:
0.5.3-3 -
Reverse Provides:
pi@raspberrypi:~$
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8