Automation of Recording
At one point in development, it became necessary to make a larger amount of audio recordings from the FPGASID prototype hardware. In the beginning I was using Audacity as a recording tool and recorded each audio file manually. But this was a lot of work and I could not spend this time for bugfixing.
Someone propsed to me, to automate the recording and I thought that was a good idea! Within a few days, I managed to implement an automated recording mechanism, which is doing the job quite well.
And this is how it works:
The C64 part
Basically the C64 has to load and start a SID-tune automatically. This is not easy because SID-files cannot just be loaded like normal programs. So the first preparation was the conversion of all SID files that were intended for recording to an executable PRG-file. This task can be done by the handy tool PSID64. This tool converts a SID file to a PRG file that can be executed on real C64 hardware. The tool runs on the command prompt of A Windows PC.
To convert all files in one go, you can copy all SID files in a single directory. Then copy psid64.exe into the same directory. In the command prompt change to that directory and type...
This command collects all SID files an converts them to PRG files. Now the first preparation step is done.
Next you need a program that runs on the C64 and loads each of the tunes one after the other. The program must keep track of the previously loaded song in order to load the next tune in the list. This is not easy because the only way to load the next song is to reset the entire C64 then load the next one. It's hard to write programs that survive a reset under any condition. So I decided to do it differently.
The FPGASID prototype has a JiffyDos Kernel installed which is working quite nicely together with a SD2IEC SD-Card reader. One feature of JiffyDos (and possibly other fast-loader kernels) is, that you can press SHIFT+RUN/STOP to load and execute the first program in the current directory on the SD-card. The idea is to simulate such a key-press to make the C64 load and start a BASIC program. That program can then check which is the next SID-tune to load and run.
This is the program I wrote:
The program reads a file 'index.seq' stored on the SD-card (file will be created when it does not exist) and gets the index number of the next song to play. Then the number is incremented and written back to the file. The index number is used to read the file name of the next tune from a list (in the data lines from line 10000 onwards). The tune with this file name is loaded and executed. The next time the BASIC program is executed, it will read the incremented index value and load the next song in the list.
To assure this BASIC program is the first one in the current directory, save it to an empty directory on the SD card. Then copy all the SID-tunes (PRG format as prepared in the first step) into that directory. It is important to keep this order of copying. Then the BASIC program is really the first one in the directory. From now on, do not change into any other directory. The current directory will be the working directory for the recording.
The next thing, that needs to be automated, is a reset of the C64 after a song is recorded and then a keypress on SHIFT+RUN/STOP to start the next song. This automation has to be controlled from a PC that is also doing the recording. The bridge between both worlds is a NetIO board from Pollin.
The NetIO Board
The NetIO board is an ATMEL-based microcontroller board that can be controlled from a PC either by serial or network connection. In this case we are using the serial link (which is easier to handle). The firmware on the NetIO board is the original firmware from Pollin. It allows simple control of the IO lines and that's everything that's needed.
The connection to the C64 is done through the output pins on the SUB-D25 connector of the NetIO board. The connection wiring is shown on the left. The diodes can be of any generic type such as 1N4148 or 1N4005 etc.
On the C64 side the connection will do two basic things:
The connection to pin8 of U20 will invoke a reset of the C64 whenever the NetIO output port 1 is pulled low for some milliseconds.
The connection from NetIO output pin 2 to the C64 pin 17 of U2 will simulate a key press on the SHIFT+RUN/STOP keys. This will load and execute the first program in the current directory. Also this output pin is low active.
The Windows script
For automated recording we can no longer use Audacity. Another very nice tool for command line based recording (and many more) is FFMPEG. It can be used to record directly from a sound card into a MP3-file. You should download the 'static' versions from here. Apart from this we do not need any other external tools.
Everything is done in a batch file:
The configuration in the beginning of the batch file is used to adapt the recording hardware to your needs. Check the FFMPEG documentation on how to list the audio devices in your system. Then configure the proper settings in the batch file.
Next step is the setup of the serial connection to 9600,8N1 parameters.
You will have to prepare a file named 'testcases.txt'. On each line of this file there has to be a number indicating the number of seconds to record (5 seconds will be added just to be sure) and then the name of the song. The name will be part of the file name and therefore should not contain any spaces.
Such a file might look like this:
Please note: The order of the songs in this file must absolutely match the order of songs in the data lines of the basic program on the C64. Otherwise the file names do not match the recorded songs!
The file 'testcases.txt' is read in a for loop line by line. For each song the C64 is reset and the first program on the SD-Card is loaded by a NetIO-invoked keypress on the SHIFT+RUN/STOP key. Then the C64 will take over, check it's index file and load the next song in the list.
When the recording time is elapsed the recording stops and the next song is processed.
Note: Don't get confused by the ping commands in the batch file! They are just used to delay the execution slightly to give the C64 enough time to reset and load the program.
In the working folder with the batch file you need the following:
A subdirectory named rec that will store all the recordings
The ffmpeg.exe file
The testcases.txt file
Testing for FPGASID
The FPGASID project is using this automation to do the recordings of about 20 test songs. The whole recording takes roughly two hours and does not require any manual interaction. So ideally it just runs over night.