• ESP32FORTH: music, tones and test

    From Marc Petremann@21:1/5 to All on Fri Jul 22 02:30:55 2022
    Hello,
    New listing: https://github.com/MPETREMANN11/ESP32forth/blob/main/DAC/tones.txt

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Fri Jul 22 05:15:33 2022
    New listing: https://github.com/MPETREMANN11/ESP32forth/blob/main/DAC/tones.txt

    Yes, I'm aware that „The purpose of the article is not to make "good FORTH code" ” — but
    allow me, please, to propose changes at least for its wo... I mean: for its least good place;
    (line 125 onwards). What do you think about:

    : note ( n -- n+1 )
    dup 1- get.note CHANNEL0 swap ledcWriteTone drop sustain.note constant 1+ ;

    \ notes in english notation
    1 \ starting value
    note C
    note C#
    note D
    note D#
    note E
    note F
    note F#
    note G
    note G#
    note A
    note A#
    note B
    drop

    Also, please note, most probably „get.note” leaves some value on the stack?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Petremann@21:1/5 to All on Fri Jul 22 10:52:52 2022
    Le vendredi 22 juillet 2022 à 14:15:34 UTC+2, Zbig a écrit :
    New listing: https://github.com/MPETREMANN11/ESP32forth/blob/main/DAC/tones.txt

    Yes, I'm aware that „The purpose of the article is not to make "good FORTH code" ” — but
    allow me, please, to propose changes at least for its wo... I mean: for its least good place;
    (line 125 onwards). What do you think about:

    : note ( n -- n+1 )
    dup 1- get.note CHANNEL0 swap ledcWriteTone drop sustain.note constant 1+ ;

    \ notes in english notation
    1 \ starting value
    note C
    note C#
    note D
    note D#
    note E
    note F
    note F#
    note G
    note G#
    note A
    note A#
    note B
    drop

    Also, please note, most probably „get.note” leaves some value on the stack?

    Hello,
    Your code cannot work.
    You create a constant.....
    I think you didn't quite grasp the concept of the CREATE cup....DOES>
    The CREATE part defines the way we build the word, here we store a constant. But, at runtime, the DOES> part is executed by the word that is defined:

    : create-note
    \ compile position in octave
    create ( position -- )
    ,
    \ get note frequency in current octave
    does>
    @ 1- get.note
    CHANNEL0 swap ledcWriteTone drop
    sustain.note
    ;

    The word create-note creates a structure which appears to be equivalent to a constant.
    But when the word created by create-note is executed, it is the part of code located after DOES> which will be executed, but not during the creation of the word.
    Example:

    8 create-note G

    creates the word G in the music vocabulary.

    Then, you have to call the music vocabulary:

    forth also music also
    4 set.octave
    G D C# C# C G

    And there the notes are played.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Fri Jul 22 12:03:30 2022
    Your code cannot work.
    You create a constant.....

    You mean: your notes are of variable pitch? Must be some very modern
    music... :) indeed, I meant notes rather in traditional sense.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Petremann@21:1/5 to All on Fri Jul 22 14:06:19 2022
    Le vendredi 22 juillet 2022 à 21:03:32 UTC+2, Zbig a écrit :
    Your code cannot work.
    You create a constant.....
    You mean: your notes are of variable pitch? Must be some very modern music... :) indeed, I meant notes rather in traditional sense.

    Have you tested my code with ESP32FORTH?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Sat Jul 23 05:13:17 2022
    Your code cannot work.
    You create a constant.....
    You mean: your notes are of variable pitch? Must be some very modern music... :) indeed, I meant notes rather in traditional sense.
    Have you tested my code with ESP32FORTH?

    And have you tested my code with ESP32FORTH?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Zbig@21:1/5 to All on Mon May 15 13:25:15 2023
    OK, having ESP32 board working I can fix — months later — that code. Obviously I missed the fact, that the created note in fact doesn't
    calculate a value and then leave it on the stack — for that purpose
    the constant would do — but it does action instead: it plays the tone.
    That keeps CREATE .. DOES> here, still not denying my basic idea
    to make the code within 133-170 line range simpler and nicer:

    : note
    create dup 1+ swap ,
    does> @ 1- get.note CHANNEL0 swap ledcWriteTone drop sustain.note ;

    \ notes in english notation
    1 \ initial value
    note C
    note C#
    note D
    note D#
    note E
    note F
    note F#
    note G
    note G#
    note A
    note A#
    note B
    drop

    \ notes in french notation
    1 \ initial value
    note DO
    note DO#
    note RE
    note RE#
    note MI
    note FA
    note FA#
    note SOL
    note SOL#
    note LA
    note LA#
    note SI
    drop

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)