Realtime PCM file replayer for CDROM. 
 
Written by Henrik Gilvad. 
 
The problem with PCM files are that they get so HUGE and must  
have high samplefrequency to give a real nice quality. Before  
we have only had the "PCMPLAY.COM" from japan to play PCM  
files on the Turbo R and PSG. Sure there are other programs  
but they all suffer from the same things: 
 
* The whole file must be in ram before replaying can begin. 
* It takes a lot of time to load the file to ram. 
 
When I got access to CDROM on the MSX I quickly found a lot  
of PCM files: 
 
VOC   Soundblaster 
WAV   Windows 
AIF   Machintosh 
 
and some raw PCM files. 
 
I begun to copy these onto my harddisk and then play them  
with PCMPLAY.COM. Arrrghh ! 
 
One day I found a WAV file which was 10Mbytes big. I HAD to  
listen to it so I tried it on the PC. The result was really  
bad because it have to load all the time and the frequencies  
was not very accurate. I knew the MSX Turbo R could do better  
than this so I started to write my own PCM / CDROM routine. 
 
A special routine was invented which could run with the  
interrupt enabled and still read from the CDROM's weird  
sectors. Another routine was made to play the incomming data  
interruptdriven on the Turbo R PCM. The MIDI Timer was used  
to generate the interrupt as I have explained some years ago  
in this magazine. 
 
But how can I load and Play at the same time without getting  
into problems ? 
 
I had to use a technique called 'Double buffering PCM'. 
 
2 buffer of each 4 or 8 kbytes is used like this: 
 
1) Read data into buffer 1. 
2) Start replaying the 1.st buffer 
3) Read data into buffer 2. 
4) Wait until the replayer have emptied buffer 1 
5) Start replaying the 2.nd buffer 
6) Read data into buffer 1. 
7) Wait until the replayer have emptied buffer 2 
8) GOTO 1 
 
The whole routine was done with 64kbytes ram enabled to the  
Interrupt server could be specialised for a FAST PCM. 
 
 
Since only 8-16kbytes buffers are used then it doesnt matter  
how long the PCM files are on the CDROM. 
You start hearing the file after the first buffer is filled,  
that means that you dont have to wait. 
 
The first version was made only for 8bit mono sound but I  
quickly found out that many of the real exiting files was 16  
bit stereo and 22kHz or higher. Therefore I did some more  
variations of the routine. 
 
a) 8 bit mono, any frequency up to 300 kHz 
b) 8 bit stereo with Philips module, any frequency up to 150 
c) 16 bit mono, up to 150 kHz 
d) 16 bit stereo, up to 75 kHz 
 
The replaying frequencies are limited to the speed of the  
interface and the CDROM drive. A double spin CD drive can  
transfer 300 Kbytes / sec. My SCSI interface on the Turbo R  
can transfer at least 470 kbytes / sec. Therefore it is the  
CDROM drive which limits the speed. 
 
The 16 bit files are play as 8 bit only, of course. But when  
the OPL4 comes then perhaps 16 bit can be played ! 
 
Some of the files I heard was made on poor PC or aMIGA  
samplers so the quality was really bad even at 22kHz. Other  
files had crystal clear sound even at 11kHz because they was  
made on top-quality equipment. The Turbo R sampler gives  
clear sound at 16kHz because it have a good filter, I am not  
so sure about the 8kHz because I think the filter was  
designed for 16kHz only. 
 
 
The technique used in this routine can also be done for SCSI  
HARDDISKS if they have a high transferrate. With my interface  
on the Turbo R you can usually read 400-470kbytes when you  
write your own sector reader and loads directly to ram. But  
slower SCSI interfaces can also be used for low frequency  
mono files like 8 bit 8-22 kHz. and after all then that  
should be enough for most purposes if ONLY PCM is to be  
played and no CPU power is to be used on other things at the  
same time. If a high speed interface/harddisk is used then  
you can get more time free for graphics or other stuff at the  
same time. (But never disable interrupt !) The BUFFER size  
gives also a time-buffer. But it will still take some clever  
programming to do both PCM, SCSI and demo routines running at  
the 'same' time without glitches in sound and/or graphics. 
 
 
In ZANDVOORT 94 you might be able to hear some examples on  
the CDROM/PCM replayer as well as many other things. 
 
HG.
                                        