11. Using Sound

The newer linux kernels for the 5MX now support sound quite well, including recording and minimal mixer support. It is unknown if the sound drivers will work as a module.

11.1. Working Features

Installation of the sox package will give you the two utilities "play" and "rec". However, play produces nasty clicks occasionally with large sound files, which is likely an issue with play. The more primitive cat foo > /dev/dsp plays sound without any clicks. Different buffer sizes inside the sound code have been tried to alleviate the clicks. Currently the buffer size is 4kB, dynamically allocated only when needed, which seems to work best.

Sound files native to the psion can be played - they are "*.al" files, so that "play -t al psionsoundfile" will play them. So, you can record sound under EPOC, and then play them back under OpenPsion without trouble. You can now also record sound under linux with "rec foo.al", which will make a recording in file "foo.al" that will play back without distortion.

11.2. Devices

/dev/dsp: set to 8000Hz 16bit signed linear PCM, mono.

/dev/audio: set to 8000Hz A-Law, mono, which is a format used by EPOC.

/dev/mixer: two channels are supported - master volume and microphone volume. Microphone can be a recording source. Either of the mixer utilities aumix, cpm or gom will work (cpm only on virtual terminal - it needs 80x25).

PCM and A-law are the only supported formats. 5mx hardware is not capable of changing sample rate, doing stereo, or doing sensurround. Nor can you plug in a sub-woofer.

The external buttons for sound on the 5MX are defined as keys F13, F14, and F15. These keys can therefore be tied to the appropriate sound functions using, e.g., keylaunch. In fluxbox, you can define these keys in the .fluxbox/keys file to be:

None F13 :ExecCommand rec /tmp/recording.al
None F14 :ExecCommand killall -2 sox
None F15 :ExecCommand play /tmp/recording.al
So that you can hit the record button to record, the stop button to stop recording, the play button to play the recording, and then again the stop button to stop playing.

11.3. Setting an Alarm

The openpsion kernel can be put in sleep mode and having an, e.g., daemon running (e.g., an ipaqalarm/uschedule (taken from ipaq, where it is no longer available) system) that will cause the psion to wake up and play a sound, e.g., for a morning alarm. A daemon is not actually needed to wake up the 5MX, the alarm for the real time clock has to be set. A utility for setting the real time clock alarm (with source code), and some example sounds in Psion format, can be downloaded here: alarms.tgz. See the section on the real time clock in this HOWTO.

A script, called e.g.,setalarm, that can be used to sound an alarm and then keep sounding the alarm until a key is pressed is setalarm. Execute with setalarm 8:30 to set an alarm for 8:30. As you can see after 20 plays of the sound file, the script gives up and assumes that either nobody is around (so don't keep playing sound until the batteries are dead), or you REALLY want to sleep in. One of the difficulties with setting an alarm like this is the so-called "midnight barrier", where if the time of the alarm is earlier than the current time the alarm will not sound - the rtc does not account for the change in day. The work around in the "setalarm" script is to wake up just before midnight, wait for midnight to pass, and then set the alarm for the correct wakeup time. Surprisingly difficult to debug.

11.4. Sound Details

The sound code does not use floating point, which was one suggestion as to why the sound driver could not handle *.wav files. Rather, the sound chip on 5mx expects A-law encoding, and the play utility (from sox) for some reason cannot recode linear PCM to A-law on the fly. So, to make the sound driver half-usable, 16-bit 8-kHz PCM mode and recoding procedures have been added, which seem to work fine.

The 5mx hardware (OKI MSM7717 and MSC1192) is not capable of adjusting the sound level, so to mimic EPOC functionality the samples are recalculated. Now, the default volume level of 50 means no adjustment, and samples are passed to codec as they were received.