SDL_Sound or SDL_Mixer sound generation question

Hi All,
Someone on the JEDI-SDL mailing list was asking how they could use
SDL_Mixer or SDL_Sound to create Commodore PET sounds. I am not much of
a sound person I thought I would ask here.

Any C code or suggestions that could point us in the right direction
would be most usefull.

The original message follows…

Thanks…> ----- Original Message -----

I am trying to write Delphi JEDI SDL code that will produce sound effects
similar to those produced on the Commodore PET 4032 computers (told you it
was off topic). Anyway, attached below is an explanation of sorts called
"HOW DO I MAKE SOUND ON MY PET?" from the URL listed (below). I found the
explanation very difficult to understand. (And yes, I used to own a
Commodore PET computer over 20 years ago and I did program it for sound
effects, way back then, but to be frank… the explanation below does not
make a lot of sense to me.)

I have copied some lines of code from the relevant parts of a PET Basic
program which does sound effects I am trying to convert. If you are
interested, then would you like to comment on (possibly) the Delphi JEDI
SDL equivalent of these sounds (or how that might be achieved).

// This next line initializes the computer for sound effects
// and defines q (used throughout the program)
poke59467,16:poke 59466,11:q=59464:poke q,0

// a little sound effect
500 poke q,6:poke q,0

// Here are some lines for a sound effect in a loop
// x is set to one of: 6,12 or 18
x =6 //(or x=12 or x=18 )
// then we do a for loop
for a=1 to x
{
// and do some sound followed by a delay (another for loop)
[…] poke q,a*4 [… includes small delay ]
}
// then turn off the sound
poke q,0

// this line is similar to the ones above
// go through a loop “beeping” a particular tone … then turns it off
1220 for z=200 to 100 step-5:poke q,z:next:poke q,0

// again similar… but poking a real number ?!? (the PET probably just
truncated it ?!?)
1230 for z=150 to 250 step .2 : poke q,z:next:poke q,0

Note: q is set at 59464 and the poke q,0 switches off sound.

*** What I am really after is how to I calculated the equivalent (or close)
frequencies and what commands do I use to produce the sounds using
SDL_Sound??? Does anyone have any SDL_Sound Demos???

Regards,
— Peter W. :-)))


From: http://www.zimmers.net/cbmpics/cbm/PETx/petfaq.html

HOW DO I MAKE SOUND ON MY PET?

This process sets the PET's shift register in a free-running  state

where the
signal is used for sound generation. By adjusting the pattern of
the output
and the frequency you can produce a wide variety of sounds, and even
music!

Three pokes are required to make sound:
  POKE 59467,16 (turn on port for sound output use 0 to turn it off*)
  POKE 59466,octave (octave number, see below)
  POKE 59464,frequency (0 for no sound)

After setting 59467 you can adjust 59466 and 59464 to get any sort 

of sound,
but to get music you need to set them with specific values, here is a
three-octave note table:

Note Table:

       octave=15     octave=51     octave=85
Note  Oct.0 Oct.1 ! Oct.1 Oct.2 ! Oct.2 Oct.3
Freq  ------------+-------------+--------------
 B     251   125  !  251   125  !  251   125
 C     238   118  !  238   118  !  238   118
 C#    224   110  !  224   110  !  224   110
 D     210   104  !  210   104  !  210   104
 D#    199    99  !  199    99  !  199    99
 E     188    93  !  188    93  !  188    93
 F     177    88  !  177    88  !  177    88
 F#    168    83  !  168    83  !  168    83
 G     158    78  !  158    78  !  158    78
 G#    149    74  !  149    74  !  149    74
 A     140    69  !  140    69  !  140    69
 A#    133    65  !  133    65  !  133    65

Set 59466 with octave range desired and play notes by setting the 

frequency
in 59464. To stop any sound use POKE 59464,0.

* Note, due to a hardware bug, leaving the shift register in free 

running
mode will cause problems when attempting to use the datasette so
always
POKE 59467,0 before attempting to use any tape commands.

The process for using and playing sound can also be done on the 

64/128 and
VIC-20 the same connector pins are involved but the POKEs are different:

  Instead of 59467, 59466, and 59464 for the PET use these:
    on the VIC-20:     37147, 37146, and 37144
    on the 64 or 128:  56587, 56586, and 56584

Regards,
Peter W.

pewill at optusnet.com.au


http://www.DelphiGamer.com := for all your Object Pascal game
development needs;
http://www.delphi-jedi.org/Jedi:TEAM_SDL_HOME := Home of JEDI-SDL;
Cross-platform game development with Pascal, has never been easier.

Someone on the JEDI-SDL mailing list was asking how they could use
SDL_Mixer or SDL_Sound to create Commodore PET sounds. I am not much of
a sound person I thought I would ask here.

Wow…this guy should be using the SDL audio callback directly.

It might be interesting to have a sound file format that basically
contains a list of instructions (bytes that say “play this tone at this
pitch for n milliseconds”), but we don’t have such a beast.

Also, the BASIC code he listed uses poke (which writes to specific
addresses in memory) to control the PET sound chip. What he would do on a
modern OS is write those tones as PCM data instead (which is not very
hard, it just involves more memory bandwidth than the PET version does).
This PCM waveform is then fed to the sound card via the audio callback.

–ryan.

Someone on the JEDI-SDL mailing list was asking how they could use
SDL_Mixer or SDL_Sound to create Commodore PET sounds. I am not much of
a sound person I thought I would ask here.

Wow…this guy should be using the SDL audio callback directly.

It might be interesting to have a sound file format that basically
contains a list of instructions (bytes that say “play this tone at this
pitch for n milliseconds”), but we don’t have such a beast.

Also, the BASIC code he listed uses poke (which writes to specific
addresses in memory) to control the PET sound chip. What he would do on a
modern OS is write those tones as PCM data instead (which is not very
hard, it just involves more memory bandwidth than the PET version does).
This PCM waveform is then fed to the sound card via the audio callback.

–ryan.

Find an emualtor of Commodore with sources. Borrow sound code (if autors
allow you to do it). It has to generate the PCM wave (like ryan said).

I have an Atari XE (please no flame war…:slight_smile:
And I’m going to use sound code from atari800.sf.net, it’s GPL so…
I suppose there will be no problem.

There is a easy way too. Just launch an emulator and write sound to WAVs :)–
Pawel Rozanski

(Sorry about the delay. Chaos. Basically no keyboard contact in several
weeks…)On Saturday 20 July 2002 13:32, Dominique Louis wrote:

Hi All,
Someone on the JEDI-SDL mailing list was asking how they could use
SDL_Mixer or SDL_Sound to create Commodore PET sounds. I am not much of
a sound person I thought I would ask here.

Any C code or suggestions that could point us in the right direction
would be most usefull.

The original message follows…

Thanks…

-------- Original Message --------
I am trying to write Delphi JEDI SDL code that will produce sound
effects similar to those produced on the Commodore PET 4032 computers
(told you it was off topic). Anyway, attached below is an explanation
of sorts called “HOW DO I MAKE SOUND ON MY PET?” from the URL listed
(below). I found the explanation very difficult to understand. (And
yes, I used to own a Commodore PET computer over 20 years ago and I did
program it for sound effects, way back then, but to be frank… the
explanation below does not make a lot of sense to me.)

Well, you could have a look at the “speaker” hack at

http://olofson.net/mixed.html

It’s actually a PC speaker emulator (and “driver” for the real speaker
via Linux console and X bell - nothing you need to care about), which
means that there’s only one square wave voice and no volume control. (The
PC speaker is simply driven by the “amplified” output from a programmable
timer.)

Just add more voices, other waveforms, per voice volume control, filters
and whatnot… :slight_smile: The simple “sequencer” (ported with demo sounds from
Project Spitfire/DOS) might be useful as well, with some new commands
and/or multiple “tracks”.

(Oh, there is the old Pascal code as well, but that doesn’t include the
actual speaker emulator part, as it was using the real PC speaker. You’re
probably better off looking at the C version and hacking your own anyway.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -’