Sounds in Turbo pascal. How do they work?

1.3k views Asked by At

I've been trying for some time to learn how does sound work and how can i implement it to pascal. No succes. I started using 8 bit sound (i believe that they're 8 bit) and tried to copy some songs (like Mario song). I have some questions. 1. How can i use programs to play a song (a real song) 2. Is there any site that gives 8 bit songs but in code (frequency and duration) And one unrelated question.... is there any way to copy a code from a browser to free pascal....? I really new to free pascal.

1

There are 1 answers

0
Adam Mead On

TP hasn't been updated in 20 years, I'd suggest using Freepascal which is far better and constantly updated.

That aside though, in TP you won't be able to natively play a song (mp3, ogg) unless you write the code to do it yourself. You may find some old DOS mp3 playing programs out there that have source code, but good luck on that.

If you intend to play simple tones then sound() and delay() is all you need, but I guess you've already done this? Simply a case of reading a list of tones and durations. If you want to do other stuff in your code while this is happening you'll need to keep a check of time elapsed since the tone started and once it reaches the tone length or greater then switch to the next tone.

pseudo-code below:

var tlength : integer;
    starttime : integer;

procedure readtone; 
var tone: byte; 
begin   
  if (starttime+nowtime >= tlength) then 
  begin   
    tone:=read from file
    tlength:=read from file
    starttime:=now
    sound(tone)   
  end; 
end;

begin   
  repeat
    readtone;
    do something else   
  until done 
end.

In Freepascal you can take the easy route: http://wiki.freepascal.org/Multimedia_Programming