29 June 2021

Fixing pyaudio installation errors in Ubuntu and Raspberry Pi

I don't understand why developers can't just write a script to automatically detect the OS and install dependencies automatically. When installing pyaudio, there's this error that shows up on Ubuntu:

ERROR: Command errored out with exit status 1:

...blah blah...

src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
    compilation terminated.
    error: command '/usr/bin/gcc' failed with exit code 1

The solution is to install the dependencies. Not all of the below dependencies are required, but it's safe to just copy-paste these one by one to get them installed...just to be sure.

sudo apt-get install -y libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
sudo apt-get install -y ffmpeg libav-tools

And finally...

sudo apt-get install -y python-pyaudio python3-pyaudio

or
sudo pip install pyaudio 

or 

sudo apt-get install -y python3-pyaudio 

or 

sudo apt-get install -y python-pyaudio

or
sudo -s
pip install pyaudio

Sources: source1, source2.

If the problem happens in Raspberry Pi, these are the steps:
Remove the directory PyAudio which is already present in /home/pi and then try these steps:
sudo apt-get install git
sudo git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
sudo apt-get install -y libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo apt-get install -y python-dev
cd pyaudio
sudo python setup.py install

Thats it! Have fun.

24 June 2021

How to use Jupyter notebook locally (and an intro to Fast AI)

When refreshing my knowledge about which Deep Learning library is currently most popular, I came across a blog which listed PyTorch at the top. Theano was apparently on its way to oblivion, and libraries like Neural Magic and Caffe claimed to offer better performance than TensorFlow. However, Fast AI was a library which had an accompanying course that was gaining popularity quite fast. Their book is available as a free Jupyter notebook, but I wanted to try it offline. Here's how:

You don't need to install Anaconda. Just do:

pip install jupyter

To get Fast AI's book, do:

git clone https://github.com/fastai/fastbook.git

Open a terminal in the cloned folder and type:

jupyter notebook


Your default web browser will open up and the Jupyter environment will be available on localhost as http://localhost:8888/tree.

 

It's that simple. Now just click on the hyperlinks on the page, and the ipynb notebook will be visible. You'll have to wait a few seconds for the notebook to load though. 

Do have a look at Fast AI's course too. Quite good. Although I prefer watching it directly on YouTube, since there are additional video controls there. Lesson 0, lesson1, lesson 2, lesson 3, lesson 4, lesson 5, lesson 6 and lesson 7.


01 June 2021

Using DosBox in Ubuntu

When an Australian who goes by the internet name "Sparcie" decided to review some of my games (I guess he found it via a GitHub search), I noticed he did it on an MS-DOS emulator named DosBox. 

(Sparcie has a treasure of awesome videos on various BASIC programs, games and legacy hardware. Check out his channel and blog)


I thought I'd give it a try too, and although it was a bit hard to understand at first, it's easy once you understand why it was created as such. 

Installing dosbox

To run it on Ubuntu, first install it using:

sudo apt-get install -y dosbox

Then start it by typing "dosbox" (without the quotes) in a terminal. That'll create a config file that you can find in a hidden folder in your home folder, named ".dosbox". 

ls -altrh will show you the folder. In Nautilus (the graphical file manager that's the equivalent of Windows Explorer), you can press Ctrl+H to see the file, since it's a hidden file.

Initial configuration

To be able to access files from Ubuntu on dosbox, you can create a shared folder named DOS. I'll assume you've created the folder in the home folder ~/DOS. The tilde (~) is a shortcut for the home folder in Ubuntu.

The hidden folder is in Ubuntu's home folder, and contains a configuration file named dosbox-<version>.conf.

Similar to the autoexec.bat file in MS-DOS which used to be run on startup (same as startup scripts for Ubuntu), the dosbox conf file has an autoexec section where you can type DOS commands to execute when dosbox starts. So search at the bottom of the conf file to find "[autoexec]", and below it you can type your commands. I typed the following:

[autoexec]

mount C ~/DOS

echo "~/DOS is mounted onto the C drive"

C:


Remember that the folder names are case sensitive. This ensured that the DOS folder was mounted onto the C drive and the current drive was automatically shifted from the default dosbox Z drive to the C drive. 

Now, once you start dosbox from the Ubuntu terminal, you'll see an emulated MS-DOS command prompt from where you can run "dir" and you'll see the files you've placed in the ~/DOS folder. 

Adjusting program execution speed:

If your plan was to run DOS games, you can do so. However, you'll notice that some games run slower than they are supposed to, and some run too fast. To adjust this, you can search the conf file for the line containing "cycles=auto", and do some trial and error with various values like:

cycles=normal 1000

or 

cycles=normal 5000

For a more specific value, see these tables which show which CPU type the values represent.

 

The conf file shows there are a lot of other settings that can be emulated. See the FAQ for more info on dosbox. Wish you a happy trip down the memory lane.


Update:

As Sparcie mentioned in the comments, you can use Ctrl+F11 to reduce the cycles while dosbox is running (the cycle value will be shown at the top of the window. Ctrl+F12 speeds it up). However, if dosbox is using just one core, taking the cycle count too high will simply put one CPU core at 100% and slow down the program in dosbox. Adjusting the core's setting might help, but I haven't tried that yet. Perhaps a simpler option would be to just use a virtualbox with an older version of Windows installed. Or, use one of the modern QBasic interpreters.

Turns out there's an official QBasic for Windows 10, from Microsoft, there's a QBasic64 for Windows, Linux and Mac! (with source code). Nice to see people maintaing QBasic even after all these decades. Similarly, there's even a modern Logo.