Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-09

simple sound implementation

14 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

I've read in the docs for the crt-unit that the procedure "sound()" does not work on windows.

Since I'm searching for a portable way of playing simple tones (frequency & duration) I want to know if there is something as replacement for the crt unit or if it still needs to be done.

FreeBSD has a simple speaker-device and is able to use it for simple freqency and duration sounds via ioctl as well as playing musical notes a simple acsii-notation. Maybe Linux, MacOS and others have similar possibilities?

TIA,
Marc

Jonas Maebe
to Marc Santhoff
Marc Santhoff wrote 5 lines
FreeBSD has a simple speaker-device and is able to use it for simple freqency and duration sounds via ioctl as well as playing musical notes a simple acsii-notation. Maybe Linux, MacOS and others have similar possibilities?

Mac OS X doesn't. Linux doesn't either, afaik (we teach one lab sessions at the university where the goal is to write/complete a similar device driver for Linux).

Jonas

Daniël Mantione
to Jonas Maebe

Op Sun, 2 Sep 2007, schreef Jonas Maebe:

Show quoted text 11 lines
On 02 Sep 2007, at 07:58, Marc Santhoff wrote: > FreeBSD has a simple speaker-device and is able to use it for simple > freqency and duration sounds via ioctl as well as playing musical notes > a simple acsii-notation. Maybe Linux, MacOS and others have similar > possibilities? Mac OS X doesn't. Linux doesn't either, afaik (we teach one lab sessions at the university where the goal is to write/complete a similar device driver for Linux).

You can set the bell frequency using write(#27'10;freq') and the duration using write(#27'10;duration'), where freq is in Hz and duration in milliseconds. Then ctrl+g to ring the bell. It is possible to play music this way.

Of course, the PC-Speaker is not really high fidelty sound.

Daniël

Marc Santhoff
to Daniël Mantione
Daniël Mantione wrote 19 lines
Op Sun, 2 Sep 2007, schreef Jonas Maebe: > > On 02 Sep 2007, at 07:58, Marc Santhoff wrote: > > > FreeBSD has a simple speaker-device and is able to use it for simple > > freqency and duration sounds via ioctl as well as playing musical notes > > a simple acsii-notation. Maybe Linux, MacOS and others have similar > > possibilities? > > Mac OS X doesn't. Linux doesn't either, afaik (we teach one lab sessions at > the university where the goal is to write/complete a similar device driver for > Linux). You can set the bell frequency using write(#27'10;freq') and the duration using write(#27'10;duration'), where freq is in Hz and duration in milliseconds. Then ctrl+g to ring the bell. It is possible to play music this way.

Hey, I like control sequences for this task!

I understand this as controlling the noise a write(#07) makes, pretty easy. I'll try it.

Ahem, maybe you know how to control the volume, too?

Of course, the PC-Speaker is not really high fidelty sound.

:)

No problem here, I only need an acoustic feedback from a program reading values from a DMM, so the person using it doesn't has to look at the screen each time. But there have to be at least two or three different noises.

Many thanks,
Marc

Tomas Hajny
to Marc Santhoff: I've read in the docs for the crt-unit that the procedure "sound()" does not work on…

On 2 Sep 07, at 7:58, Marc Santhoff wrote:

Hi,

Show quoted text 11 lines
I've read in the docs for the crt-unit that the procedure "sound()" does not work on windows. Since I'm searching for a portable way of playing simple tones (frequency & duration) I want to know if there is something as replacement for the crt unit or if it still needs to be done. FreeBSD has a simple speaker-device and is able to use it for simple freqency and duration sounds via ioctl as well as playing musical notes a simple acsii-notation. Maybe Linux, MacOS and others have similar possibilities?

Most operating systems (i.e. the more advanced
ones than DOS, which was the original target of
the Crt unit) require you to pass both frequency
and duration at the same time rather than low
level control in the sense of "turn sound on with
frequency X", "wait", "turn sound off" assumed by
the Crt unit. I guess that we could alternatively
provide an overloaded Sound (Freq, Duration)
routine for most platforms, maybe that would be
useful situation similar to what you described in
your second e-mail...

Tomas

Daniël Mantione
to Marc Santhoff: Hey, I like control sequences for this task! I understand this as controlling the noise a…

Op Sun, 2 Sep 2007, schreef Marc Santhoff:

Show quoted text 13 lines
Am Sonntag, den 02.09.2007, 10:32 +0200 schrieb Daniël Mantione: > > You can set the bell frequency using write(#27'10;freq') and the duration > using write(#27'10;duration'), where freq is in Hz and duration in > milliseconds. Then ctrl+g to ring the bell. It is possible to play music > this way. Hey, I like control sequences for this task! I understand this as controlling the noise a write(#07) makes, pretty easy. I'll try it. Ahem, maybe you know how to control the volume, too?

In the original IBM PC the speaker was directly connected to the 8254 timer chip, therefore there exists no volume control.

In modern PCs, the PC-speaker is often rerouted through the sound card, where it can be controlled using the mixer. You use the OSS/ALSA mixer API in such case.

Daniël

Sebastian Günther
to Marc Santhoff: Hey, I like control sequences for this task! I understand this as controlling the noise a…
Ahem, maybe you know how to control the volume, too?

Naturally, this is not possible: The PC speaker is simply controlled by a timer, which creates a square wave (on/off). In ancient DOS times there was a trick by doing a frequency modulation, i.e. you turn the timer on and off quite fast. But on Linux etc. the drivers don't support such cheats.

- Sebastian

Mark Wood
to Sebastian Günther
Show quoted text 5 lines
Naturally, this is not possible: The PC speaker is simply controlled by a timer, which creates a square wave (on/off). In ancient DOS times there was a trick by doing a frequency modulation, i.e. you turn the timer on and off quite fast. But on Linux etc. the drivers don't support such cheats.

<scratches chin> Hmmm... could you use that old Turbo Pascal code to do an inline of the ASM for it? (talking completely through my hat having never attempted such a thing on a linux platform)

Cheers,
M.

Daniël Mantione
to Mark Wood

Op Sun, 2 Sep 2007, schreef Mark Wood:

Show quoted text 9 lines
> Naturally, this is not possible: The PC speaker is simply controlled by a > timer, which creates a square wave (on/off). In ancient DOS times there > was a trick by doing a frequency modulation, i.e. you turn the timer on > and off quite fast. But on Linux etc. the drivers don't support such > cheats. <scratches chin> Hmmm... could you use that old Turbo Pascal code to do an inline of the ASM for it? (talking completely through my hat having never attempted such a thing on a linux platform)

If you run as root, acquire I/O port access and run SCHED_FIFO (so you are not pre-empted), it might work.

However, as nowadays all PCs have a 16 bit audio possibility I don't see a reason to do such ugly tricks with the PC speaker.

Daniël

Marco van de Voort
to Mark Wood: <scratches chin> Hmmm... could you use that old Turbo Pascal code to do an inline of the…
Show quoted text 8 lines
> Naturally, this is not possible: The PC speaker is simply controlled > by a timer, which creates a square wave (on/off). In ancient DOS times > there was a trick by doing a frequency modulation, i.e. you turn the > timer on and off quite fast. But on Linux etc. the drivers don't > support such cheats. <scratches chin> Hmmm... could you use that old Turbo Pascal code to do an inline of the ASM for it? (talking completely through my hat having never attempted such a thing on a linux platform)

Not really. It is not the asm or not, it is simply no hardware access from programs in principle, one program not being able to lock the entire CPU to modulate the speaker.

Of course you can, but then you go into the realm of customizing linux.

Luca Olivetti
to Marco van de Voort

En/na Marco van de Voort ha escrit:

Show quoted text 14 lines
>> Naturally, this is not possible: The PC speaker is simply controlled >> by a timer, which creates a square wave (on/off). In ancient DOS times >> there was a trick by doing a frequency modulation, i.e. you turn the >> timer on and off quite fast. But on Linux etc. the drivers don't >> support such cheats. > <scratches chin> Hmmm... could you use that old Turbo Pascal code to do > an inline of the ASM for it? (talking completely through my hat having > never attempted such a thing on a linux platform) Not really. It is not the asm or not, it is simply no hardware access from programs in principle, one program not being able to lock the entire CPU to modulate the speaker. Of course you can, but then you go into the realm of customizing linux.

There's also the "pc-speaker" driver (though I never used it) that already does it:
http://www.geocities.com/stssppnn/pcsp.html

Bye

Luca
Marc Santhoff
to Sebastian Günther: Naturally, this is not possible: The PC speaker is simply controlled by a timer, which…
Sebastian Günther wrote 9 lines
Marc Santhoff schrieb: > > Ahem, maybe you know how to control the volume, too? Naturally, this is not possible: The PC speaker is simply controlled by a timer, which creates a square wave (on/off). In ancient DOS times there was a trick by doing a frequency modulation, i.e. you turn the timer on and off quite fast. But on Linux etc. the drivers don't support such cheats.

I understand.

And since the control-sequences-solution is linux console only I have to understand that there is no platform independent way of making distingishable beeps since the ancient times when the CPU was a 8086 at 4 or 6 MHz or so, too.

<mumbling curses censored/>

Thanks for explaning,
Marc

Marco van de Voort
to Daniël Mantione: Op Sun, 2 Sep 2007, schreef Mark Wood: If you run as root, acquire I/O port access and…
Show quoted text 7 lines
Op Sun, 2 Sep 2007, schreef Mark Wood: If you run as root, acquire I/O port access and run SCHED_FIFO (so you are not pre-empted), it might work. However, as nowadays all PCs have a 16 bit audio possibility I don't see a reason to do such ugly tricks with the PC speaker.

A standard machine comes with a PC-screamer and an audio card, but not with speakers FOR the audio card. Moreover they are usually external.

I can imagine messing with the speaker for cases for public PCs, which are mostly single tasking. But maybe even then it is wiser to conform, and look in some specialised vendor's catalogue for an internal speaker that connects to the audio card.

Mark Wood
to Daniël Mantione: Op Sun, 2 Sep 2007, schreef Mark Wood: If you run as root, acquire I/O port access and…

True. And at least some of us have now upgraded to Sound Blaster! :-D

Cheers,
M.

Daniël Mantione wrote 26 lines
Op Sun, 2 Sep 2007, schreef Mark Wood: >> Naturally, this is not possible: The PC speaker is simply controlled by a >> timer, which creates a square wave (on/off). In ancient DOS times there >> was a trick by doing a frequency modulation, i.e. you turn the timer on >> and off quite fast. But on Linux etc. the drivers don't support such >> cheats. >> > <scratches chin> Hmmm... could you use that old Turbo Pascal code to do an > inline of the ASM for it? (talking completely through my hat having never > attempted such a thing on a linux platform) > If you run as root, acquire I/O port access and run SCHED_FIFO (so you are not pre-empted), it might work. However, as nowadays all PCs have a 16 bit audio possibility I don't see a reason to do such ugly tricks with the PC speaker. Daniël ------------------------------------------------------------------------ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal