Internet Radio Player based on MOC
May 16, 2018

RSO (Radio sans ondes which loosely translates to waveless radio) is an Internet radio player written with Lazarus, the open source Free Pascal RAD IDE. Because it uses the Music on Console audio media player to handle the hard part, it runs on Linux. I am using it on my Ubuntu 17.10 desktop computer.

RSO is not meant to be a replacement for a full-fledged media player such as Rhythmbox which does a splendid job of playing Internet audio streams and is much better at handling playlists and the like. The application is a test bed for an Internet radio player built around a Raspberry Pi to be connected to an older sound system. I will be using it to simulate and test possible hardware user interfaces. As shown on the image above, I am currently thinking of using a classic LCD screen and two rotary encoders with push switches each of which is represented by an up and down control and a button. There is also an on/off button represented by the red dot.

Currently, the left encoder is a volume/mute control while the right encoder is a station selector. There is an obvious analogy with an old-style car radio, but if volume and tuning were the only functions to be handled by the interface a single rotary encoder would probably suffice.

There are supplementary buttons that do not represent elements of the interface. A couple are for debugging purposes. The info button displays the current state of the Music On Console player.

The more button expands the window to show income messages from MOC in real time.

Because I actually do use it to play stations while working at my computer, the application can be minimised to an icon on the task bar . This is done by clicking on the white box with the underscore at the top right. Of course there will not be an equivalent object in the physical project. The labels showing the sound level and the index of the displayed radio stations are also just for information and will not be part of the hardware.

The window can be dragged to anywhere on the screen, except when trying to open a new station. There is a software design flaw, although I am not too sure if I need to worry about it.

The list of known stations is maintained in a relatively simple JSON formatted file. Just what will be contained in that file is still open. Unlike the typical media player application, the content of the file must be adjusted by hand. Eventually, I will be writing an application to easily update that file on the desktop to be downloaded to the Raspberry Pi.

Of course, MOC had to be installed on the Ubuntu desktop which was a straightforward operation. However, there is some problem with my system, in part because I want to use speakers built in my HDMI monitor. Sometimes the system does not load the appropriate digital HDMI sound driver and often, but not always, the system uses the internal analogue sound card as the default output. This seems to be partly if not totally related to the sequence in which the computer and the monitor are powered up. In any case, before using RSO, I always look at the sound system settings to ensure that HDMI audio controller is being used with the correct profile and test that the sound is coming from the speakers and then I restart the MOC service.

michel@hp:~$ sudo systemctl restart moc@michel

Only when the OS is updated to Ubuntu 18.04 LTS will I look into fixing these sound card related problems if they are not already solved by then.

The source code is available in a zip archive: rso_01.zip which contains the following files.

main.lfm The Lazarus form file with the configuration information for all components on the only form in the project.
main.pas The Pascal source code for the actions related to the objects in the main.lfm file.
mocpi.pas Unit source code of a Pascal wrapper for the Music on Console daemon.
radios.pas Unit source code to manage a JSON formatted list of Internet radio stations.
radios.json JSON formatted list of Internet radio stations. This is not a definitive list by any means and there are voluntary errors to test the software and other inadvertent errors without doubt.
rso_icon_256x256.png Image file (ugly!) which can be used to create the project icon: Project/Project Options/Application/Load Icon.
rso.lpi Lazarus project information file with project-specific settings.
rso.lpr Lazarus program file an IDE managed file that initialises the application, creating the main form and starting the event loop.

Hope I have not forgotten anything essential. Comments and suggestions welcomed.