Poor Man’s Radio Player: making live recordings ..?

Forum Forums General Software Poor Man’s Radio Player: making live recordings ..?

  • This topic has 5 replies, 3 voices, and was last updated Oct 2-6:07 am by mikey777.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #68098
    Member
    mikey777

      I love listening to the endless stream and choice of music on an app that comes packaged in antix-goodies: Poor Man’s Radio Player.

      Is there a way of recording the music directly on my laptop as it streams on my headphones?
      What low resource software would you recommend for this?

      • This topic was modified 1 year, 7 months ago by mikey777.

      ▪ 32-bit antix19.4-core+LXDE installed on :
      - (2011) Samsung NP-N145 Plus (JP04UK) – single-core CPU Intel Atom N455@1.66GHz, 2GB RAM, integrated graphics.
      ▪ 64-bit antix21-base+LXDE installed on:
      - (2008) Asus X71Q (7SC002) – dual CPU Intel T3200@2.0GHz, 4GB RAM. Graphics: Intel Mobile 4 Series, integrated graphics
      - (2007) Packard Bell Easynote MX37 (ALP-Ajax C3) – dual CPU Intel T2310@1.46GHz, 2GB RAM. Graphics: Silicon Integrated Systems.

      #68102
      Anonymous
        Helpful
        Up
        0
        ::

        sudo apt install streamripper
        Refer to its manpage. You’ll probably want to use -r option (records the stream and relays the stream to a music player).

        some keywords for your followup websearch: streamripper, streamtuner2, vlc

        #68110
        Member
        Robin
          Helpful
          Up
          1
          ::

          Well, actually there is no need to install anything. We have everything on board, but it’s a bit tricky to set it up correctly. You can do all this with alsa.

          First of all you need to activate the alsa virtual loopback device:

          sudo modprobe snd-aloop

          After this restart the alsa server:

          sudo /etc/init.d/alsa-utils stop
          sudo /etc/init.d/alsa-utils start

          Next make sure your audio is not muted (see sound tray icon), and also check the mixer controls (right click on sound tray icon and choose mixer).

          And now you need to create a file in your /home/<user> directory, it must be named:
          .asoundrc

          Open it in a text editor (like geany or leafpad, NOT in libreoffice or any other word processing software) and copy the following content into it, save it.

          pcm.!default {
            type asym
            playback.pcm "Out_A+B"
            capture.pcm "hw:0,1"
          }
          
          pcm.Out_A+B {
            type plug
            slave.pcm Duplicate_AB
            route_policy "duplicate"
          }
          
          pcm.Duplicate_AB {
            type multi
            slaves.a.pcm pcm.Out_A
            slaves.a.channels 2
            slaves.b.pcm pcm.Out_B
            slaves.b.channels 2
            bindings.0.slave a
            bindings.0.channel 0
            bindings.1.slave a
            bindings.1.channel 1
            bindings.2.slave b
            bindings.2.channel 0
            bindings.3.slave b
            bindings.3.channel 1
          }
          
          pcm.Out_A {
            type dmix
            ipc_key 1024
            slave {
              pcm "hw:0,0"
              rate 48000
              periods 128
              period_time 0
              period_size 1024 # must be power of 2
              buffer_size 8192
            }
          }
          
          pcm.Out_B {
            type dmix
            ipc_key 1025
            slave {
              pcm "hw:Loopback,0,0"
              rate 48000
              periods 128
              period_time 0
              period_size 1024 # must be power of 2
              buffer_size 8192
            }
          }

          And now comes the tricky part of it: You’ll have to figure which hardware IDs (hw:m,n) you have to write into this file.
          Check the output of the following commands:

          grep -P 'rates|bits' /proc/asound/card0/codec\#0
          arecord -l
          aplay -l

          From this you’ll get an idea which numbers you have to use in the file for the hardware identification of playback and capture device in line 4 and line 33. Just replace the hw:m,n values with your findings from the output of the commands above. In line 4 is expected your default capture device, most commonly something like hw:0,… and in line 33 is expected your default playback device, also mostly hw:0,… (or hw:1,… in case you have two hardware sound devices installed). The first value after hw:, which is (m), is the card number, the second value (n) is the device number as found in the command output. A reading of e.g. card 0: Intel [HDA Intel], device 1: ALC880 Digital [ALC880 Digital] results in hw:0,1 consequently. Depending on your findings from the first command you’ll have also to adjust the values for the rate from 48000 to 44100 possibly, but normally your sound card should be able to handle 48kHz sampling rate.

          If you can hear after this operation all playback on the speakers as you are used to, everything should be fine.

          But indeed the audio stream gets duplicated now and is sent through the loopback device parallel, so you can capture it while hearing:

          The command
          arecord -f S16_LE -c2 -D hw:2,1 -r48000 output.wav
          will create a wav file from what you hear. This method is quite resurce conserving, so it’ll work on weak PCs also. But it needs more disk space for storage, since it is not a compressed audio format. (Make sure to use the same sampling rate here as in the .asoundrc file)

          Again here you’ll have to replace the hw:m,n in this command by your findings from the output of the three commands above. If you have only one hardware device installed, you will probably have to use something like hw:1,1 or hw:1,n instead, with n set to some number you have found out. In any case this has to point to the virtual loopback device.

          You can play the file after stopping the record simply using the command

          aplay output.wav

          If you prefer an output file in mp3 format, simply add a pipe:

          arecord -f S16_LE -c2 -D hw:2,1 -r48000 -t raw | lame -r --preset extreme - output.mp3

          But be warned: the encoding in mp3 in realtime can overburden your CPU easily and the result will be scrambled, chopped sound in the file if this happens. So on weaker machines (e.g. my 32 bit single core pentium, even with 1,7GHz, it is a good idea rather not to realtime encode the output to mp3, but to do this later in a second step separately. So the CPU can take all the time for the encoding job it needs.

          Further background reading:
          Streaming audio with alsa
          Audio Recording and Encoding in Linux
          How to determine your audio card’s, or USB mic’s, maximum sampling rate
          Playing with ALSA loopback devices

          Windows is like a submarine. Open a window and serious problems will start.

          #68119
          Member
          mikey777
            Helpful
            Up
            0
            ::

            sudo apt install streamripper
            Refer to its manpage. You’ll probably want to use -r option (records the stream and relays the stream to a music player).

            Many thanks skidoo. Streamripper downloaded, but it of course needs the URL of the PMRP channel that I want recording, but PMRP doesn’t show this when it’s open – how do I find the URL?

            ▪ 32-bit antix19.4-core+LXDE installed on :
            - (2011) Samsung NP-N145 Plus (JP04UK) – single-core CPU Intel Atom N455@1.66GHz, 2GB RAM, integrated graphics.
            ▪ 64-bit antix21-base+LXDE installed on:
            - (2008) Asus X71Q (7SC002) – dual CPU Intel T3200@2.0GHz, 4GB RAM. Graphics: Intel Mobile 4 Series, integrated graphics
            - (2007) Packard Bell Easynote MX37 (ALP-Ajax C3) – dual CPU Intel T2310@1.46GHz, 2GB RAM. Graphics: Silicon Integrated Systems.

            #68120
            Member
            mikey777
              Helpful
              Up
              0
              ::

              @Robin
              Thanks Robin – you’ve gone to a lot of trouble here – I feel humbled!
              However, I think I’ll try skidoo’s suggestion of using streamripper, as it seems a lot simpler. If for any reason that doesn’t work for me, I’ll take a closer look at the terminal-based solution you presented. Thanks again.

              • This reply was modified 1 year, 7 months ago by mikey777.

              ▪ 32-bit antix19.4-core+LXDE installed on :
              - (2011) Samsung NP-N145 Plus (JP04UK) – single-core CPU Intel Atom N455@1.66GHz, 2GB RAM, integrated graphics.
              ▪ 64-bit antix21-base+LXDE installed on:
              - (2008) Asus X71Q (7SC002) – dual CPU Intel T3200@2.0GHz, 4GB RAM. Graphics: Intel Mobile 4 Series, integrated graphics
              - (2007) Packard Bell Easynote MX37 (ALP-Ajax C3) – dual CPU Intel T2310@1.46GHz, 2GB RAM. Graphics: Silicon Integrated Systems.

              #68157
              Member
              mikey777
                Helpful
                Up
                0
                ::

                I’ve just found that Streamripper works for some links, e.g.

                $ streamripper http://listen.hardbase.fm/tunein-dsl-pls
                Connecting...
                stream: HardBase.FM - 24h Hardstyle, Jumpstyle and More
                server name: Icecast 2.4.0-kh15-addlog-fix with AdBreak 1.1.3
                declared bitrate: 192
                meta interval: 16000
                
                [skipping...   ] Serzo - Feel It Tonight [  4.95M]

                But not for others, e.g.

                $ streamripper https://www.antenne.de/webradio/top-40
                Connecting...
                error -10 [SR_ERROR_NO_RESPONSE_HEADER: Server is not a shoutcast stream]
                bye.. shutting down

                This bug was reported back in 2009, but doesn’t seem to have been resolved since then.
                See https://sourceforge.net/p/streamripper/bugs/196/

                • This reply was modified 1 year, 7 months ago by mikey777.
                • This reply was modified 1 year, 7 months ago by mikey777.
                • This reply was modified 1 year, 7 months ago by mikey777.

                ▪ 32-bit antix19.4-core+LXDE installed on :
                - (2011) Samsung NP-N145 Plus (JP04UK) – single-core CPU Intel Atom N455@1.66GHz, 2GB RAM, integrated graphics.
                ▪ 64-bit antix21-base+LXDE installed on:
                - (2008) Asus X71Q (7SC002) – dual CPU Intel T3200@2.0GHz, 4GB RAM. Graphics: Intel Mobile 4 Series, integrated graphics
                - (2007) Packard Bell Easynote MX37 (ALP-Ajax C3) – dual CPU Intel T2310@1.46GHz, 2GB RAM. Graphics: Silicon Integrated Systems.

              Viewing 6 posts - 1 through 6 (of 6 total)
              • You must be logged in to reply to this topic.