simple sound implementation

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

simple sound implementation

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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Jonas Maebe-2

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).


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Bugzilla from daniel.mantione@freepascal.org


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.

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

Daniël
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Marc Santhoff
Am Sonntag, den 02.09.2007, 10:32 +0200 schrieb Daniël Mantione:

>
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Tomas Hajny
In reply to this post by Marc Santhoff
On 2 Sep 07, at 7:58, Marc Santhoff wrote:


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?

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Bugzilla from daniel.mantione@freepascal.org
In reply to this post by Marc Santhoff


Op Sun, 2 Sep 2007, schreef Marc Santhoff:

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Sebastian Günther
In reply to this post by Marc Santhoff
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.


- Sebastian
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

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)

Cheers,
     M.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Bugzilla from daniel.mantione@freepascal.org


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  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Marco van de Voort
In reply to this post by 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)

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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Luca Olivetti-2
En/na Marco van de Voort ha escrit:

>>> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Marc Santhoff
In reply to this post by Sebastian Günther
Am Sonntag, den 02.09.2007, 16:56 +0200 schrieb Sebastian Günther:
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Marco van de Voort
In reply to this post by Bugzilla from daniel.mantione@freepascal.org
> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: simple sound implementation

Mark Wood
In reply to this post by Bugzilla from daniel.mantione@freepascal.org
True. And at least some of us have now upgraded to Sound Blaster! :-D

Cheers,
     M.


Daniël Mantione wrote:
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 - [hidden email] http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal