You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Oleg <ev...@gmail.com> on 2023/05/26 08:43:09 UTC
Question about Music Macro Language
Hi all,
While playing with generating audio tones (thanks for the manual
<https://www.youtube.com/watch?v=3U6OZaGnYcc>, Alan!), I wonder what I need
to write to /dev/tone to get constant signal, 100% PWM on the audio pin,
that is beep of maximum volume?
---
With best regards, Oleg.
Re: Question about Music Macro Language
Posted by Tomek CEDRO <to...@cedro.info>.
On Fri, May 26, 2023 at 11:34 AM Oleg wrote:
> Hi, Tomek.
> Yeah, I know how drivers in NuttX works. I already could play beeps, tones
> and melodies using the tone driver available in Nuttx. I understand that I
> could correct a driver for special needs.
Aaah there is a code for playing melodies in /dev/toneN already sorry
I thought you want to create one as an exercise :-)
You may like FM-Synthesized sound, like AdLib did in the good old days :-)
https://en.wikipedia.org/wiki/Frequency_modulation_synthesis
https://en.wikipedia.org/wiki/Ad_Lib,_Inc.
Here is the absolute masterpiece, Dune videogame soundtrack by Stéphane Picq :-)
https://www.youtube.com/watch?v=FjHon6yg-r8
> But currently I just wondered is there a possibility using current note
> language to make a single constant beep with highest volume (that is the
> same as if just set and keep HIGH to pin of the buzzer).
It depends on what and how the audio device is attached to the port..
usually this is done by setting PWM duty cycle 10..90% but if you
provide constant current you may smoke the device beware :-)
https://electronics.stackexchange.com/questions/239442/audio-using-pwm-what-is-the-principle-behind-it
Usually you want to have something in between the port and the speaker
that will amplify the volume. Take a look at this trick with PNP
transistor, it usually works well for the small piezo as it "doubles
the voltage":
https://electronics.stackexchange.com/questions/299998/how-to-make-a-piezoelectric-transducer-buzz-louder
Note that there is a difference between piezo and the speaker: they
have different equivalent circuits, and piezo has usually its own
resonant frequency (i.e. 1kHZ) that you will hear much better than the
others, while speaker is designed to have wider band (i.e. audio
20..20000Hz).
Also note that some piezo buzzers (especially the black ones) have
built in generator (although they may look exactly the same as the
ones without a generator), so you only provide DC voltage and it will
beep on its own.
--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
Re: Question about Music Macro Language
Posted by Oleg <ev...@gmail.com>.
Hi, Tomek.
Yeah, I know how drivers in NuttX works. I already could play beeps, tones
and melodies using the tone driver available in Nuttx. I understand that I
could correct a driver for special needs.
But currently I just wondered is there a possibility using current note
language to make a single constant beep with highest volume (that is the
same as if just set and keep HIGH to pin of the buzzer)
пт, 26 мая 2023 г. в 12:08, Tomek CEDRO <to...@cedro.info>:
> On Fri, May 26, 2023 at 10:43 AM Oleg wrote:
> > Hi all,
> > While playing with generating audio tones (thanks for the manual
> > <https://www.youtube.com/watch?v=3U6OZaGnYcc>, Alan!), I wonder what I
> need
> > to write to /dev/tone to get constant signal, 100% PWM on the audio pin,
> > that is beep of maximum volume?
>
> Hey there Oleg :-)
>
> Here is a documentation on how to create your own device driver and
> general description on how drivers work in NuttX:
>
> https://nuttx.apache.org/docs/latest/components/drivers/index.html
>
> On FreeBSD there is a /dev/speaker device handled by a kernel module
> that can text commands and convert them to a PC speaker tones. That
> could be a reference point too if you want to write a simple melody
> player :-)
>
> For instance this will play Star Trek tune:
> l2b.f+.p16a.c+.p l4mne8a2mspg+e8c+f+8b2
>
> https://man.freebsd.org/cgi/man.cgi?query=speaker
> https://github.com/freebsd/freebsd-src/blob/main/sys/dev/speaker/spkr.c
>
> Applications may call ioctl(2) on a speaker file descriptor to control
> the speaker driver directly; definitions for the ioctl(2)
> interface are
> in <dev/speaker/speaker.h>. The tone_t structure used in
> these calls has
> two fields, specifying a frequency (in Hz) and a duration
> (in 1/100ths of
> a second). A frequency of zero is interpreted as a rest.
>
> At present there are two such ioctl(2) calls. SPKRTONE
> accepts a pointer
> to a single tone structure as third argument and plays it.
> SPKRTUNE ac-
> cepts a pointer to the first of an array of tone structures and
> plays
> them in continuous sequence; this array must be terminated by a
> final
> member with a zero duration.
>
> The play-string language is modeled on the PLAY statement
> conventions of
> IBM Advanced BASIC 2.0. The MB, MF, and X primitives of PLAY
> are not
> useful in a timesharing environment and are omitted. The
> `octave-track-
> ing' feature and the slur mark are new.
>
> There are 84 accessible notes numbered 1-84 in 7 octaves, each running
> from C to B, numbered 0-6; the scale is equal-tempered A440 and
> octave 3
> starts with middle C. By default, the play function emits
> half-second
> notes with the last 1/16th second being `rest time'.
>
> Play strings are interpreted left to right as a series of play
> command
> groups; letter case is ignored. Play command groups are as follows:
>
> CDEFGAB Letters A through G cause the corresponding note to be
> played
> in the current octave. A note letter may optionally be fol-
> lowed by an "accidental sign", one of # + or -; the first
> two
> of these cause it to be sharped one half-tone, the last
> causes
> it to be flatted one half-tone. It may also be followed
> by a
> time value number and by sustain dots (see below). Time val-
> ues are interpreted as for the L command below.
>
> O n If n is numeric, this sets the current octave. n may
> also be
> one of L or N to enable or disable octave-tracking (it is dis-
> abled by default). When octave-tracking is on, interpretation
> of a pair of letter notes will change octaves if necessary in
> order to make the smallest possible jump between notes. Thus
> ``olbc'' will be played as ``olb>c'', and ``olcb'' as
> ``olc<b''. Octave locking is disabled for one letter note
> following >, < and O[0123456]. (The octave-locking feature is
> not supported in IBM BASIC.)
>
> > Bump the current octave up one.
>
> < Drop the current octave down one.
>
> N n Play note n, n being 1 to 84 or 0 for a rest of
> current time
> value. May be followed by sustain dots.
>
> L n Sets the current time value for notes. The default is L4,
> quarter or crotchet notes. The lowest possible value is
> 1;
> values up to 64 are accepted. L1 sets whole notes, L2 sets
> half notes, L4 sets quarter notes, etc.
>
> P n Pause (rest), with n interpreted as for L n. May be
> followed
> by sustain dots. May also be written ~.
>
> T n Sets the number of quarter notes per minute; default is
> 120.
> Musical names for common tempi are:
>
> Tempo Beats Per Minute
> very slow Larghissimo
> Largo 40-60
> Larghetto 60-66
> Grave
> Lento
> Adagio 66-76
> slow Adagietto
> Andante 76-108
> medium Andantino
> Moderato 108-120
> fast Allegretto
> Allegro 120-168
> Vivace
> Veloce
> Presto 168-208
> very fast Prestissimo
>
> M[LNS] Set articulation. MN (N for normal) is the default; the
> last
> 1/8th of the note's value is rest time. You can set ML for
> legato (no rest space) or MS for staccato (1/4 rest space).
>
> Notes (that is, CDEFGAB or N command character groups) may
> be followed by
> sustain dots. Each dot causes the note's value to be
> lengthened by one-
> half for each one. Thus, a note dotted once is held for 3/2 of
> its un-
> dotted value; dotted twice, it is held 9/4, and three times would give
> 27/8.
>
> A note and its sustain dots may also be followed by a slur
> mark (under-
> score). This causes the normal micro-rest after the note to be
> filled
> in, slurring it to the next one. (The slur feature is not
> supported in
> IBM BASIC.)
>
> Whitespace in play strings is simply skipped and may be
> used to separate
> melody sections.
>
>
> --
> CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
>
Re: Question about Music Macro Language
Posted by Tomek CEDRO <to...@cedro.info>.
On Fri, May 26, 2023 at 10:43 AM Oleg wrote:
> Hi all,
> While playing with generating audio tones (thanks for the manual
> <https://www.youtube.com/watch?v=3U6OZaGnYcc>, Alan!), I wonder what I need
> to write to /dev/tone to get constant signal, 100% PWM on the audio pin,
> that is beep of maximum volume?
Hey there Oleg :-)
Here is a documentation on how to create your own device driver and
general description on how drivers work in NuttX:
https://nuttx.apache.org/docs/latest/components/drivers/index.html
On FreeBSD there is a /dev/speaker device handled by a kernel module
that can text commands and convert them to a PC speaker tones. That
could be a reference point too if you want to write a simple melody
player :-)
For instance this will play Star Trek tune:
l2b.f+.p16a.c+.p l4mne8a2mspg+e8c+f+8b2
https://man.freebsd.org/cgi/man.cgi?query=speaker
https://github.com/freebsd/freebsd-src/blob/main/sys/dev/speaker/spkr.c
Applications may call ioctl(2) on a speaker file descriptor to control
the speaker driver directly; definitions for the ioctl(2) interface are
in <dev/speaker/speaker.h>. The tone_t structure used in
these calls has
two fields, specifying a frequency (in Hz) and a duration
(in 1/100ths of
a second). A frequency of zero is interpreted as a rest.
At present there are two such ioctl(2) calls. SPKRTONE
accepts a pointer
to a single tone structure as third argument and plays it.
SPKRTUNE ac-
cepts a pointer to the first of an array of tone structures and plays
them in continuous sequence; this array must be terminated by a final
member with a zero duration.
The play-string language is modeled on the PLAY statement conventions of
IBM Advanced BASIC 2.0. The MB, MF, and X primitives of PLAY are not
useful in a timesharing environment and are omitted. The `octave-track-
ing' feature and the slur mark are new.
There are 84 accessible notes numbered 1-84 in 7 octaves, each running
from C to B, numbered 0-6; the scale is equal-tempered A440 and octave 3
starts with middle C. By default, the play function emits
half-second
notes with the last 1/16th second being `rest time'.
Play strings are interpreted left to right as a series of play command
groups; letter case is ignored. Play command groups are as follows:
CDEFGAB Letters A through G cause the corresponding note to be played
in the current octave. A note letter may optionally be fol-
lowed by an "accidental sign", one of # + or -; the first two
of these cause it to be sharped one half-tone, the last causes
it to be flatted one half-tone. It may also be followed by a
time value number and by sustain dots (see below). Time val-
ues are interpreted as for the L command below.
O n If n is numeric, this sets the current octave. n may also be
one of L or N to enable or disable octave-tracking (it is dis-
abled by default). When octave-tracking is on, interpretation
of a pair of letter notes will change octaves if necessary in
order to make the smallest possible jump between notes. Thus
``olbc'' will be played as ``olb>c'', and ``olcb'' as
``olc<b''. Octave locking is disabled for one letter note
following >, < and O[0123456]. (The octave-locking feature is
not supported in IBM BASIC.)
> Bump the current octave up one.
< Drop the current octave down one.
N n Play note n, n being 1 to 84 or 0 for a rest of
current time
value. May be followed by sustain dots.
L n Sets the current time value for notes. The default is L4,
quarter or crotchet notes. The lowest possible value is 1;
values up to 64 are accepted. L1 sets whole notes, L2 sets
half notes, L4 sets quarter notes, etc.
P n Pause (rest), with n interpreted as for L n. May be followed
by sustain dots. May also be written ~.
T n Sets the number of quarter notes per minute; default is 120.
Musical names for common tempi are:
Tempo Beats Per Minute
very slow Larghissimo
Largo 40-60
Larghetto 60-66
Grave
Lento
Adagio 66-76
slow Adagietto
Andante 76-108
medium Andantino
Moderato 108-120
fast Allegretto
Allegro 120-168
Vivace
Veloce
Presto 168-208
very fast Prestissimo
M[LNS] Set articulation. MN (N for normal) is the default; the last
1/8th of the note's value is rest time. You can set ML for
legato (no rest space) or MS for staccato (1/4 rest space).
Notes (that is, CDEFGAB or N command character groups) may
be followed by
sustain dots. Each dot causes the note's value to be
lengthened by one-
half for each one. Thus, a note dotted once is held for 3/2 of its un-
dotted value; dotted twice, it is held 9/4, and three times would give
27/8.
A note and its sustain dots may also be followed by a slur
mark (under-
score). This causes the normal micro-rest after the note to be filled
in, slurring it to the next one. (The slur feature is not
supported in
IBM BASIC.)
Whitespace in play strings is simply skipped and may be
used to separate
melody sections.
--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
Re: Question about Music Macro Language
Posted by "Alan C. Assis" <ac...@gmail.com>.
Hi Oleg,
This audio tones uses same MML used by Microsoft in QBasic in the 80's
More info: https://acassis.wordpress.com/2016/08/16/playing-gorilla-bas-tune-on-nuttx/
This driver is a port of the audio tone created by PX4 project (I
think there it was a C++ application).
There are many ringtone formats, maybe an improvement to this driver
is replacing the MML format with Ringing Tone Text Transfer Language
(RTTTL).
If you want to do that, please let me know and I'll help you.
BR,
Alan
On 5/26/23, Oleg <ev...@gmail.com> wrote:
> Hi all,
>
> While playing with generating audio tones (thanks for the manual
> <https://www.youtube.com/watch?v=3U6OZaGnYcc>, Alan!), I wonder what I need
> to write to /dev/tone to get constant signal, 100% PWM on the audio pin,
> that is beep of maximum volume?
>
> ---
> With best regards, Oleg.
>