Tridora-CPU/examples/pcmtest2.pas
slederer 536c0adde7 pcmaudio: set amplitude to biased zero at end
pcmtest2: small updates to the demo program
2025-10-12 22:52:17 +02:00

74 lines
1.1 KiB
ObjectPascal

{$H2560}
program pcmtest2;
uses pcmaudio;
var filename:string;
buf:SndBufPtr;
sampleRate:integer;
err:integer;
done:boolean;
c:char;
function readAudioFile(fname:string):SndBufPtr;
var i,size:integer;
c:char;
buf:SndBufPtr;
f:file;
begin
open(f, fname, ModeReadOnly);
size := FileSize(f);
new(buf, size);
buf^ := '';
write('Reading ', size, ' bytes...');
for i := 1 to size do
begin
read(f,c);
AppendChar(buf^,c);
end;
writeln;
close(f);
readAudioFile := buf;
end;
begin
if ParamCount > 0 then
filename := ParamStr(1)
else
begin
write('Filename> ');
readln(filename);
end;
err := 1;
if ParamCount > 1 then
val(ParamStr(2), sampleRate, err);
if err > 0 then
sampleRate := 32000;
buf := readAudioFile(filename);
SampleQStart(buf, sampleRate);
write('Press ESC to stop> ');
done := false;
while not done do
begin
read(c);
if c = #27 then
begin
done := true; writeln(';');
end
else
if c = '?' then
begin
writeln; writeln('Queue: ', SampleQSize);
end;
end;
SampleQStop;
dispose(buf);
end.