1. 10 Nov, 2021 7 commits
    • Joel K. Pettersson's avatar
      Set version to v0.3.9. · c0c60578
      Joel K. Pettersson authored
      c0c60578
    • Joel K. Pettersson's avatar
      Refactor parseconv, voicegraph, utility modules. · 95c7623a
      Joel K. Pettersson authored
      Refactor parseconv and voicegraph, use mempool for all produced
      data. Rename ptrlist to ptrarr.
      
      Add and use "mpmemdup" methods for arrtype and ptrarr,
      replacing ordinary "memdup" and traversal for freeing.
      
      Change log:
       * 2020-10-08: Simplified reworking of part of v0.3.6 redesign.
             The old ptrlist module is used, and nodelist is ignored.
         Old branch:
          - 2019-12-31: Renaming and refactoring.
                Add and use arrtype "mpmemdup" for scriptconv
                and voicegraph arrays, removing all but one free.
          - 2020-01-01: Add and use ptrlist "mpmemdup"; simplify,
                turn SAU_ProgramEvent array into array of pointers.
          - 2020-01-03: Merge de-const-ify ptrlist void pointers.
          - 2020-01-04: Move down from later v0.3.6 commits.
          - 2020-02-27: Remove const from parameters for arrtype
                memdup functions.
          - 2020-07-26: ISC-relicense arrtype, ptrlist, nodelist.
       * 2020-10-09: Move down to sgensys v0.2-beta.
       * 2021-11-02: Move to saugns on top of new sgensys.
         Old branch:
          - 2020-10-09: Rename ptrlist to ptrarr.
      95c7623a
    • Joel K. Pettersson's avatar
      Use new time type. Flense generator, tidy up more. · dadfd85a
      Joel K. Pettersson authored
      Add SGS_Time type and flags, for script.h and
      program.h time_ms variables, and replace time
      default flag, and infinite time magic number.
      Also refactor a little further in the parser.
      
      Design idea from the 2020-06 "mgensys" changes.
      
      Flense generator, simplifying away most "event data"
      and using what's allocated at the previous stage. In
      the future, some data and code can be moved from the
      program types to the generator, ending up in-between
      the layers as part of pre-allocation code, e.g. move
      voicegraph.
      
      The basic main idea is very old, not new. Now the
      stubbornly kept premature abstraction of the past
      is gone in the generator.
      
      Compared to the flat 2020-06 "mgensys" design, reduces
      differences in part. But here, in a more multi-layered
      design, there's already specialized data types for the
      "updates" to be done, use those instead of duplicating
      data with the generator's own types.
      
      Now uses mempool for all allocation in generator.
      
      Change log:
       * 2020-10-18: Add SSG_Time type, time.h header,
             use in script.h and program.h types.
             Replace default time flag and use of
             SSG_TIME_INF (except the latter kept
             in the generator). Fix warnings in parser
             using saugns v0.3.4 change and refactor a
             little. Also move SSG_MS_IN_SAMPLES()
             from math.h to time.h.
       * 2020-10-19: Replace the old magic value in generator.
       * 2020-10-26: Add runalloc module (placeholder)
             and use in generator, as in 'old-dev_202006' branch.
       * 2020-10-27: Flense generator, simplifying away most
             "event data", and using what's allocated at the
             previous stage. Remove runalloc module for now,
             for simpler diff.
             Now use the mempool for all allocation in generator.
       * 2021-07-09: Merge time.h contents into program.h.
       * 2021-11-01: Move to saugns on top of new sgensys.
      dadfd85a
    • Joel K. Pettersson's avatar
      Add man page. Split README. Makefile changes. · 298f9242
      Joel K. Pettersson authored
      Add a saugns(1) man page for installation.
      
      Split README into README and doc/README.SAU,
      the latter installed under share/doc/saugns/.
      Install examples/* to share/examples/saugns,
      instead of share/saugns.
      
      Several possibilities exist for where the
      man page should be added/removed. Do something
      very simple and hopefully sensible:
       * If "man" exists under the install/uninstall
         prefix, use it.
       * Else, go with "share/man" under the prefix.
      
      Some systems (e.g. OpenBSD) do not use compressed
      man pages for official packages, while others do.
      Add simple check for this less significant detail:
       * If "/usr/share/man" exists,
         compress man page if and only if
         it contains compressed man page(s).
       * Else, compress man page if and only if
         install location contains compressed man page(s).
      
      Change log:
       * 2019-09-07: Add a man page for installation.
             Split README into README and doc/README.SAU.
             Install examples to share/examples/saugns,
             and doc to share/doc/saugns,
             instead of examples to share/saugns.
       * 2019-09-09: Clean up man page.
             Move saugns.1 file to man/.
             Handle man dir possibilities
             more portably in Makefile.
       * 2019-09-13: Update README.
       * 2019-12-14: Handle whether or not to gzip man page
             upon install (always done before),
             according to whether the install location
             or "/usr/share/man" (takes priority if found)
             contains gzipped man pages.
       * 2019-12-21: Update 'doc/README.SAU' on "@label".
       * 2020-02-09: Update man page for simplified usage notice.
       * 2020-07-23: Update man page.
       * 2020-09-19: Update 'doc/README.SAU' on channel mixing.
       * 2021-01-08: Update README to refer to website
             and mention permissive licensing of individual files.
       * 2021-01-22: Update man page for AUDIODEV environment.
       * 2021-11-01: Update 'doc/README.SAU' from new unified README.
       * 2021-11-08: Update man page.
      298f9242
    • Joel K. Pettersson's avatar
      Rename project to 'saugns' from 'sgensys'. · b869cdbd
      Joel K. Pettersson authored
      Rename the program from 'sgensys'
      to 'saugns' (Scriptable AUdio GeNeration System).
      Change SSG prefix to SAU throughout code.
      
      Rename scripts from *.sgs
      to *.sau, naming the language SAU (Scriptable AUdio).
      
      Update descriptions in README.
      
      Set version to v0.3-dev.
      
      Change log:
       * 2018-12-05: Rename to 'saugns'. Change SGS prefix to SAG.
       * 2019-01-21: Update for newer code. Change prefix to AGS.
       * 2019-01-22: Bump copyright years. Change prefix to SAU.
             Rename scripts from *.sgs to *.sau, polish README.
       * 2019-07-04: Update for newer code. Tag "v0.3.0".
       * 2019-08-18: Increase version suffix to 'b'.
       * 2019-12-25: Update for newer code.
       * 2020-01-03: Increase version suffix to 'c'.
       * 2020-02-09: Update for newer code. Tag "v0.3.6e-2".
       * 2020-07-26: Update for newer code. Set version to v0.3-dev.
       * 2021-11-10: Update to latest code.
      b869cdbd
    • Joel K. Pettersson's avatar
      Rework '#' & 'Q' comment syntax. Reorganize scripts. · af4029d4
      Joel K. Pettersson authored
      Syntax changes:
       - Change '#' line comment to '#!'.
       - Remove 'Q' (quit) keyword, re-add as '#Q'.
      
      Add and use '#'-override in parser. A start
      for implementing a simple preprocessor with
      '#' freed-up for further usage as a prefix.
      
      Update README and scripts.
      
      Move some more contents from devtests/,
      and prune and and clean up a little.
      
      Add examples/sounds/, reorganize scripts
      in examples/ a little.
      
      Change log:
       * 2019-08-21: Change '#'-handling, replace old 'Q'.
             Add and use SAU_File_end() for '#Q'.
             Update README and scripts.
       * 2019-08-22: Debug file module changes, tidy up.
       * 2019-08-24: Further refactor file module.
             Now use SAU_Scanner_close() for '#Q',
             as SAU_File_close() now behaves as expected.
             Set version to v0.3.2.
       * 2019-09-12: Move file module refactoring
             down to v0.2.13, with finishing touch.
             Increase version suffix to 'b'.
       * 2019-10-08: Increase version suffix to 'c'.
             (Rebased on top of new v0.2.14.)
       * 2019-11-04: Reorganize scripts.
       * 2021-07-12: Move down to new sgensys.
      af4029d4
    • Joel K. Pettersson's avatar
      Add '<>' test syntax. Refactor further. · 9542ed3c
      Joel K. Pettersson authored
      Syntax changes:
       * Allow use of '<>' as a generic subscope with few
         effects, similar to in older "mgensys" versions.
         Replaces the generic '[]' separate from the list
         parameters, added in v0.3.6 & removed in v0.3.8.
      
      Also fix parsing bug impacting strings like "Osin<f>"
      (without any space after the '<'), and tidy a little.
      
      Reject \num syntax when ParseLevel has a
      nest_list only. Remove now-unused parser
      flag PL_NESTED_SCOPE.
      
      Move setting of LATER_USED flags down to
      postparse_passes() code in a simpler way
      than in old versions (v0.3.5 to v0.3.8b)
      by adding a small SGS_ScriptOpObj object
      per op., with fields common to its refs.
      
      Change log:
       * 2021-11-08: Reject \num syntax based on ParseLevel
             having a nest_list only. Remove the old parser
             flag PL_NESTED_SCOPE.
       * 2021-11-09: Re-add undocumented '<>' test syntax
             as in v0.3.8 & v0.3.8b. Debug use with sub_f
             call immediately following a '<'.
         Old branch:
          - 2020-12-17: Add '<>' to replace generic '[]'.
          - 2020-12-19: Tidy changes for parser a little,
                ensure behavior the same after 12-17 change.
          - 2020-12-26: Fix scope checks after '<>'-addition.
       * 2021-11-10: Add SAU_ScriptOpObj to track last_ref
             and hold root_event and op_id. Redo moving of
             LATER_USED flags; add only that part to the
             postparse_passes() code in flattening pass.
             Move down to new sgensys.
      9542ed3c
  2. 01 Nov, 2021 30 commits
    • Joel K. Pettersson's avatar
      Tidy parser more, fix edge case. Revise mempool again. · 724e54d9
      Joel K. Pettersson authored
      Parser refactoring:
       * Clean up ParseLevel pointer usage. Pass around pointers
         to the main parser struct instead.
       * Simplify away the 'location' enum and DEFERRED_* flags.
       * Make parser produce a linked list of modulator sublists
         per parent node. Simple and more generic than using one
         pointer per tye of modualtor list.
      
      This fixes the test case of "devtests/ref-unused_node.sgs"
      where referring back to an orphaned node in a script makes
      the reference touch and modify the wrong node (because the
      orphaned node hadn't had its ID properly set). Previously,
      this was fixed by a larger change splitting the post-parse
      processing stage, but the modulator list change is enough.
      
      Except for a small performance boost, the mempool has been
      much the same since 2014, until now. Change to use dynamic
      sizing of memory blocks, double the size after every power
      of two block count reached. Use 512 as default start size.
      Performance seems basically unchanged running my old test.
      (Changes probably cancelled out as fewer blocks are made.)
      
      Change log:
       * 2021-01-10: Flatten types in mempool. Refactor to place
             new allocation pointer array for freeing separately
             and change sizing per block, inceasing it once each
             new power of two number of blocks has been reached.
       * 2021-01-12: Tweak mempool. Adjust mempool heuristic for
             skipping fully-used blocks to increase threshold if
             proportion below 2/3 of blocks and increase default
             block start size from 128 to 512. Simplify away the
             extra pointer per block and separate array, growing
             allocations downward instead.
       * 2021-07-12: Move down to new sgensys.
       * 2021-07-23: Tidy parser code a bit more. Make modulator
             lists from parser a list of sublists; shorter code.
             Move down "devtests/ref-unused_node.sgs" test case.
         Old branch:
          - 2019-12-22: Add 'devtests/ref-unused_node.sau'.
          - 2020-12-17: Simplify away the old "location" values,
                use a function pointer combining their role with
                the now-removed DEFERRED_* flags.
          - 2021-06-19: Tidy up parser function parameter use of
                ParseLevel/SAU_Parser.
       * 2021-07-24: Tidy parser yet more.
      724e54d9
    • Joel K. Pettersson's avatar
      Extend num. expr. syntax with built-in math function usage. · 1eb663a3
      Joel K. Pettersson authored
      Add "name(value)" function evaluation syntax for numbers
      in parser. Similarly to other named things, add an array
      of names, this time in math.h, and math.c defining names
      and corresponding functions (in function pointer array).
      
      Add "metallic value" SGS_met() to math.h. Can be used to
      get the golden ratio number by passing 1. Supports whole
      domain of double precision values as it seems useful and
      is free.
      
      For now, the following function names are recognized:
       - abs(x)  Absolute value.
       - exp(x)  Base-e exponential value.
       - log(x)  Natural logarithmic value.
       - sqrt(x) Square root.
       - met(x)  Metallic value.
      
      Numerical expressions still work the same basic way as before,
      the parser functioning as a calculator making recursive calls.
      
      Make parser warn on expressions that produce a NaN value
      somewhere, and not only on infinite values; matters more
      now that more things producing NaN are available. Better
      than the old behavior of silently discarding NaN result,
      ignoring NaN occurring earlier.
      
      The above changes done by 2021-10-27.
      1eb663a3
    • Joel K. Pettersson's avatar
      Add help module, expand -h with <topic>. More cli clean-up. · 9cff9c36
      Joel K. Pettersson authored
      Command-line behavior:
       * Change the -h option to list topics
         available with -h <topic>. For now,
         only other lists are available, the
         first built-in help consisting of a
         'wave' type list and a 'ramp' list.
       * Print -p info for each script just prior to
         generating audio for it if done, instead of
         printing for all before generating for all.
      
      Parser warnings now use the new code for
      listing valid items. But a meta-list, of
      the lists to be available with -h, needs
      manual extension in help.c when more are
      added. All lists are in the same format.
      
      Change cli argument parsing to allow a flag to be followed
      by its argument without a space in-between. Recognize "--"
      as meaning no further strings are flags. Uses SGS_getopt()
      derived from Christopher Wellons's public domain getopt().
      Should fix the old cli non-POSIX annoyances & limitations.
      
      Option flag enum and handling is moved to 'sgensys.h'
      and the 'loader/loader.c' and 'player/player.c' code.
      
      Change log:
       * 2020-01-18: Add help module, expand -h.
             Simple code for printing out name array,
             used for wave module. Easily extended to
             print out more lists in the same format.
       * 2020-07-23: Move to saugns
             from the 2020-06 "mgensys" experiment.
             Replace 'noise' help type with 'ramp'.
         Old branch:
          - 2020-02-10: Add noise module with noise names,
                and add help type.
       * 2020-11-12: Group -p info printing with
             other per-script output generation.
       * 2020-12-20: List 'help' help type in itself.
             Change -h to also list normal usage info
             unless a topic is named.
       * 2021-01-08: Add SSG_getopt() and use in ssndgen.c.
             Change common module license from ISC to 0BSD.
             Point the user to pass -h on cli option error.
       * 2021-07-21: Move down to new sgensys.
      9cff9c36
    • Joel K. Pettersson's avatar
      Change Makefile & ramp module for improved performance. · 1c4af8e1
      Joel K. Pettersson authored
      Makefile changes to selectively use -O3.
      Use -Os where it matters most, currently
      the parser, for avoidance of size bloat.
      
      Comparing saugns v0.3.8 and v0.3.8b this
      made a large difference (as noted in the
      v0.3.8b tag). Also tweak the ramp module
      and move mulbuf use and further clean up
      the code as part of performance changes.
      
      Always handle/allow NULL mulbuf in ramp.
      Further accept a NULL pos to skip ahead,
      making the target value the state value.
      
      Change log:
       * 2020-10-27: Make ramp SSG_Ramp_skip()
             skip all remaining values if pos is NULL.
             May remain unused without a new use-idea.
       * 2021-01-12: Makefile changes to selectively use -O3 and -Os.
             ramp: Move mulbuf use into fill functions, improving the
             performance with clang 10. SSG_Ramp_run() mulbuf NULL
             checks to allow calls with missing mulbuf in the future.
       * 2021-01-15: Add noinline attribute for SSG_Ramp_fill_hold(),
             document necessity with clang where inlining hurt x86
             performance (costing half the 10% speed-up on the laptop
             with i386 OpenBSD, fixed with the use of SSG__noinline).
       * 2021-01-16: Tidy ramp.c and correct the comment on clang.
       * 2021-07-21: Move down to new sgensys.
       * 2021-07-22: Reorder the Makefile dependencies
             in each line alphabetically, while at it.
      1c4af8e1
    • Joel K. Pettersson's avatar
      Do oscillator phase increment pre- rather than post-sample. · 41eb89be
      Joel K. Pettersson authored
      Un-delays oscillator output by one sample,
      and removes unit delay from the use of the
      frequency buffer. Fits newer phase-setting
      for best accuracy, but at ~10% speed cost.
      
      Change log:
       * 2021-07-20: Increment oscillator phase before using it.
       * 2021-07-26: Add #define USE_PILUT in osc.h.
      41eb89be
    • Joel K. Pettersson's avatar
      Simplify down voice handling & fix pan syntax bug. · 0a8ff134
      Joel K. Pettersson authored
      Move pan field from voice/event data to op data nodes
      (before the interp/prealloc types). In parser, only add
      one carrier per event. The changes combine to fix the
      pan bug giving several operators on the same line the
      same value, if in one go (setting it for one setting it
      for all). Thus, now truly works like mgensys 2020-06.
      
      Remove voice parameters, except in program.h types, where
      SGS_PVOP_GRAPH is left for possible further uses for now.
      There's more room to simplify code, and this may simplify
      changing the flatter sgensys design.
      
      Re-enable disabled call in parser to
      split an op. event after time shift.
      
      Change log: 2021-06-19, saugns draft
      backported, 2021-07-10, for sgensys.
      Also bring over a small refactoring.
      More tweaks 2021-07-23, tidier code.
      0a8ff134
    • Joel K. Pettersson's avatar
      Simplify parser & parseconv node lists and their use. · 72b0ea5d
      Joel K. Pettersson authored
      Remove use of ptrlist module in parser, and simply use
      the linked list node structure for everything, with an
      extension. Use mempool for the allocations. This means
      no memory leaks even though e.g. adding and clearing a
      list of operators in the same event leaves allocations
      unused/dangling for those operators for the most part.
      
      Removes the SGS_POPP_ADJCS flag and parameter. Replace
      the adjcs field and structure with one field for every
      modulator type, using the same type for carriers. Tidy
      up handling in parseconv a bit. Increases pointers, by
      a few, but otherwise tidies up a bit in generator too.
      
      Change log:
       * 2019-12-26: Remove SAU_POPP_ADJCS flag,
             replace checks using other information.
             Replace SAU_ProgramOpGraph and SAU_ProgramOpAdjcs
             types with SAU_ProgramOpList, simplify code.
       * 2020-10-07: Merge with changes from after new node list
             code was added and used, preserving old ptrlist usage.
       * 2021-07-17: New simpler work to use linked node lists from
             parser. Redone for "older" sgensys.
       * 2021-07-18: Debug and re-tidy, matching earlier clean-ups.
             Add 2020-12-04 devtests/pm-addremaddrem.sgs.
      72b0ea5d
    • Joel K. Pettersson's avatar
      Change panning/channel mixing syntax. Tidy parser a little. · ffe0c51c
      Joel K. Pettersson authored
      Syntax changes:
       * Replace panning 'P' keyword with channel mixing parameter
         'c' and 'S c' for default. The scale changes from 0.0-1.0
         left-right to (-1.0) left, 0.0 center, 1.0 right. And the
         letters 'C', 'L', and 'R' become named constants for 0.0,
         (-1.0), and 1.0.
      
      The panning or "channel mixing syntax" is now the same as in
      the 2020-06 "mgensys" version, replacing the 'P' (2011-12-13)
      syntax and earlier 'b' (2011-04-10) variant.
      
      Adjust SGS_Scanner_getd() to call a callback if provided for
      named constant reading, using this both for the new channel
      C/L/R constants and the old note syntax code after conversion.
      
      Update README.
      
      Change log:
       * 2020-08-25: Add, use parameter flag masks.
       * 2020-09-18: Rebase, tweak previous change.
       * 2020-09-19: Refactor parser scan_ramp() to
             handle both multi-value and state cases.
             Add callback to SAU_Scanner_getd() for named constants.
             Port 2020-06 "mgensys" channel mixing syntax.
             Move devtests/panning.sau to examples/tests/.
             Update README.
       * 2020-09-21: Tidy up changed scanner code.
             Add handling for sign before named constant.
             (Redone for consistency, not currently used.)
       * 2020-10-03: Make scanner always call numconst_f when given,
             simply check return length. Remove useless warning when
             note syntax callback called for non-note characters.
       * 2021-07-10: Move down to after scanner clean-up.
      ffe0c51c
    • Joel K. Pettersson's avatar
      Rework scanner, symtab, clean up parser a bit. · fc986a9d
      Joel K. Pettersson authored
      Redesign scanner, and use the new way of
      filtering whitespace in parser. Further
      testing of line and char position numbering
      needed, but now better than with the v0.3.0
      scanner design. Also use refactored symtab
      with no functional change.
       * Add whitespace filtering level setting.
         Setting the level replaces the whitespace filtering
         functions in the table for the scanner instance.
       * Remove "nospace" versions of get/try functions.
         Simplify get function. Remove old space-skipping
         inline functions.
      
      Change log:
       * 2019-07-07: scanner: Add ws filter level setting.
             Remove nospace versions of functions.
             Use next design. Consistent for filtering,
             even if changed. Clear up ws types naming,
             really fill in everything. Tidying.
       * 2019-07-09: Scanner flag fix.
             (Recommitted after fixing the fix.)
             Set version to v0.3.1.
       * 2019-07-11: Microflensing.
             scanner: Remove "RAW" (NULL-pointer) ws level,
             rename "PASS" to "ALL" and make it the default
             (instead of "RED1").
       * 2019-08-05: Place after new v0.3.0,
             with July syntax changes split out into v0.2.13.
       * 2019-08-17: Remove scanner ws levels between ALL and NONE.
             (Not needed in current program.)
       * 2019-10-31: (Rebased on top of new v0.2.15.)
       * 2019-12-24: Merge ramp and v0.2.5-related changes.
       * 2020-02-09: Refactor num.exp. parsing.
       * 2021-07-10: Move down redesign changes
             to after change to use the scanner
             and merge with symtab refactoring.
             Keep version at v0.2-dev.
         Old branch:
          - 2019-12-27: symtab: For varying TabItem size,
                use sizeof and key[] instead of offsetof and key[1].
                (Resulting object file identical.)
          - 2020-01-26: Import from saugns v0.3.6d.
                Remove symtab get/set functions,
                rename types, expose MGS_SymStr type - used directly
                in parser to simplify code. Also changes
                to append NULL pointer to pool_stra arrays.
          - 2020-11-14: Clean up name/ver in cli strings.
          - 2020-11-20: Upgrade symtab to 2020-06 "mgensys"
                version and adapt the parser.
       * 2021-07-12: Change more struct array [1] members to [].
       * 2021-07-24: Move down a little parser style changes.
      fc986a9d
    • Joel K. Pettersson's avatar
      Use the new scanner. Extend comment syntax. Clean-up. · 38dac806
      Joel K. Pettersson authored
      Make the test scanner functional for use in the parser
      and change the parser to use the scanner module.
      (The scanner is now also used in the test lexer,
      replacing much of it.)
      
      C-style and C++-style comments are now supported
      (in addition to '#' line comments and the use of 'Q').
      
      The parser's old PScanner and warning printouts are
      replaced. Warnings now provide not only line, but also
      character, numbering. Most direct use of the file module
      is replaced. String and number reading is also further
      refactored.
      
      Scanner design changes include:
       * Flesh out design for tracking line and character positions.
         A fixed number of multiple ungets in a row are supported,
         using a circular buffer for scan frames, advanced each get.
       * Add pointer parameter to warning/error message functions
         for optionally overriding position info. (E.g. copy earlier
         position, use it when warning after more scan calls.)
       * Add number-reading functions (wrappers around those of
         the file module).
       * Add further space-skipping reading functions.
      
      Further refactoring:
       * Always check for NULL pointer in type
         destroy_*() functions, remove checks where called.
       * Minor code style changes for consistency.
      
      Set version to v0.2-dev.
      
      Reindent parser.c (the only remaining file).
      
      Use new comment styles in scripts.
      
      Change log:
       * 2019-05-15: Use the new scanner.
             Initial merge after changes as of v0.4.4.
             Adapt: Preserve use of symtab in scanner,
             remove wrapper function around string reading
             in parser. Let scanner handle file opening,
             replacing v0.4.1 additions in builder.c.
             Some comment and code clean-ups.
         Old branch:
          - 2018-12-17: scanner: Some renaming and clean-ups.
                Add, use, flag for overwriting scan frame next get.
          - 2018-12-18: scanner: Add advance_frame(), used to
                handle scan frames for symbol string reading.
          - 2018-12-19: Use scanner module in parser.
                Add SGS_Scanner_geti(), SGS_Scanner_getd().
                Debug line and char numbering.
                Move symtab use from scanner to parser,
                move string buffer from scanner to parser,
                refactor string reading in parser.
                Rename SGS_Scanner_unget()
                back to SGS_Scanner_ungetc().
                Add quick handling for unfiltered characters
                to SGS_Scanner_tryc() and SGS_Scanner_tryc_nospace().
                Move reading of SGS_SCAN_C_LNBRK
                flag out from SGS_Scanner_tryc_nospace().
                Add scanner statistics printing #define
                to common.h and #if'd counters in scanner.c.
                Refactor parser time number scanning.
                Further clean-ups in parser.
          - 2018-12-21: Comment and other minor clean-ups.
                Update README.
          - 2019-01-05: Complete branch merging.
                Use SGS_Scanner_getc_nospace() in parser.
                Clean up printing of no label warning in parser,
                silencing warning about non-const format string.
                Refactor parser uses of scan_symafind(),
                moving warning printouts into it.
          - 2019-01-09: Use scanner in lexer.
                Add SGS_SCAN_S_QUIET flag, use in lexer
                for SGS_LEXER_QUIET compile-time mode.
                Note: File module needs design change
                for safe unget, crash preventing code
                added to scanner in the meantime.
                Complete branch merging.
          - 2019-01-10: Complete branch merging.
                Remove obsolete debug code in scanner
                (file module now fixed).
          - 2019-01-11: Set version to v0.6.0.
                Clean-up in lexer. Use SGS_Scanner_getc_nospace().
          - 2019-01-15: Restructure parser code to
                reduce differences with previous version.
                No functional change.
       * 2019-05-17: Some tidying for last branch merge.
       * 2019-05-19: parser: Avoid duplicating code for name of
             script for string as file, copy name from file object.
       * 2019-05-24: Set version to v0.5.1.
             scanner: Name changes.
             in general: Always check for NULL pointer in type
             destroy_*() functions, remove checks where called.
             Minor code style changes for consistency.
       * 2019-05-28: Merge refactoring.
             Reindent parser.c (and adjust comments).
         Old branch:
          - 2019-02-08: Refactor parser warnings for
                EOF before closing character, and closing
                character without opening character.
       * 2019-06-04: Move refactoring back to v0.5.1,
             use old version number.
       * 2019-06-05: Merge parser diff after v0.2.3 syntax change.
       * 2019-06-07: Update debug script for too-long label
             for new scanner (new max length is 255).
       * 2019-06-13: Set version to v0.3.1.
       * 2019-06-16: Adjust parser for new v0.2.4 syntax changes.
       * 2019-06-20: Set version to v0.3.0.
       * 2019-06-30: Place after the split-out v0.2.12.
             Update comment style used in scripts.
       * 2019-07-04: Update for v0.2.12 'r' syntax change.
       * 2019-08-05: Update for v0.2.13 syntax changes.
       * 2019-10-08: Place after new v0.2.14.
       * 2019-10-31: Place after new v0.2.15.
       * 2019-12-21: Merge 'S a' multiplier apply-to-ramp fix.
       * 2019-12-22: Merge composite timing fix.
       * 2019-12-24: Merge changes related to v0.2.5 & v0.2.13.
       * 2019-12-25: Merge ramp default time changes.
       * 2020-02-09: Merge num.exp. fix for successive subtractions.
       * 2020-07-23: Merge renaming in ramp module.
       * 2020-07-26: Set version to v0.2-dev.
       * 2021-07-10: Move down as in v0.3.3
             and merge new work before the skipped.
             (Fixes included, not the stage split.)
      38dac806
    • Joel K. Pettersson's avatar
      Change modulation syntax and ramp usage. Add scripts. · 52130b5a
      Joel K. Pettersson authored
      Syntax changes:
       * For AM and FM parameters, parse the second value
         after a ',' and the modulator list after an
         appended '~', rather than second value and/or
         modulator list after a leading '!'.
         (E.g., for FM, "fX,Y~[...]" instead of "fX f!Y[...]",
         where X and Y are numbers or numerical expressions.
         Any of X, Y, or [...] can be left out now as before.)
       * Allow value ramp values for the second frequency and
         amplitude. Make the syntax consistent in this regard.
       * Make the phase & PM syntax slightly more permissive.
         For consistency with the new AM & FM syntax, have 'p'
         allow phase followed by PM modulator list in one go.
      
      Add position-updating skip function for ramp,
      similar to run function except there's no output.
      Use to update second freq and amp ramps in generator
      without generating samples when no FM or AM is done.
      
      This resolved the "todo" regarding dynfreq/dynamp
      ratio flags.
      
      Update scripts and README.
      (On amplitude modulation, describe ring modulation,
      which is also supported since early 2011 versions.)
      
      Add 'examples/tests/long/sqr_am_2m.sgs',
      under new dir for long duration scripts.
      
      Add 'examples/tests/ixa_synth_vs_pm.sgs'
      (recreates IXA synthesis result using PM
      & RM with a triangle, sine, and square).
      
      Change log:
       * 2019-08-04: Set version to v0.2.13.
             Move syntax changes and parser fixes
             down from v0.3.1:
         Old branch:
          - 2019-07-18: Change AM & FM syntax.
                Make 'p' more permissive for consistency.
          - 2019-07-20: Use ramps for second freq, amp.
                TODO: Fill in the missing pieces in
                generator for fully consistent handling.
          - 2019-07-21: Simplify addition in generator.
                Remove incomplete and unneeded extra code.
                Clarify remaining added TODOs.
          - 2019-07-30: Add SAU_Ramp_skip(), use in generator.
                Remove now-resolved new TODOs.
       * 2019-08-06: parser: Add missing lines to backport
             (matching commits for later versions),
             v0.2.13 now functions as expected.
       * 2019-08-07: Move 08-06 Makefile -ffast-math portability fix
             to v0.2.3 and v0.2.4.
       * 2019-12-21: Merge 'S a' multiplier apply-to-ramp fix.
       * 2019-12-22: Fix missing default time adjustment
             for amp2 and freq2 ramps. Adjust details to
             avoid inf. time.
       * 2019-12-25: Merge clean-up and ramp changes as of 12-25.
         Old branch:
          - 2019-12-24: Move down clean-up change from v0.3.3b.
                Merge ramp default time changes.
       * 2020-01-03: Fix generator crash due to
             not counting FREQ2 and AMP2 values
             correctly, by merging the cleanup. (Remove counting.)
       * 2020-07-23: Merge renaming in ramp module.
       * 2020-07-26: Keep version at v0.2-beta.
             Change ramp module to ISC license, clean up comments.
         Old branch:
          - 2019-08-16: Re-order ramp run & skip function params.
       * 2021-06-18: Add 'sqr_am_2m.sgs' script (from 2021-01-14)
             under new dir examples/tests/long/ for long duration.
       * 2021-07-09: Merge osc changes. Tweak new script for phase
             differences (or roughly, by ear-taste) in new osc.
       * 2021-07-19: Tweak test script after 'sqr' phase fixed.
       * 2021-09-03: Add 'examples/tests/ixa_synth_vs_pm.sgs'.
       * 2021-09-10: Correct and expand README
             on amplitude modulation. Describe ring modulation
             which is also supported since early 2011 versions.
      52130b5a
    • Joel K. Pettersson's avatar
      Split voicegraph code. Refactor further. Change 'r' syntax. · 2c091ad7
      Joel K. Pettersson authored
      Syntax change: Disable multiplicative inverse for 'r',
      change description from "frequency ratio" to
      "relative frequency". It's more intuitive to handle
      n:m carrier-modulator frequency ratios as (m/n) values
      than (n/m) values, when actually adjusting them.
      (With multiplicative inverse, a higher value meant a
      lower frequency; now, a higher value means a higher
      frequency.) This reverses a change from 2011-03-04.
      
      Update README.
      
      Refactoring changes:
       * Further refactoring of the file module, part 2.
       * Small flag handling change for parser end of event.
       * Small mempool performance improvement.
         Remove its dependence on arrtype.
       * Modularize parseconv a bit. Split out some
         types into parseconv.h, move voice graph traversal
         code into voicegraph.c.
      
      Change log:
       * 2019-07-04: Merge down 'r' syntax change.
         Old branch:
          - 2019-07-04: v0.3.1-beta: Begin syntax tweaks.
                Disable multiplicative inverse for 'r'.
                Update scripts and README.
       * 2019-07-31: README typo fix & ramp.c comment fix.
       * 2019-08-03: Fix description of 'r' syntax wrt freq ratio.
       * 2020-01-04: Move down clean-ups:
         Old branch:
          - 2019-07-11: (From v0.3.1) Microflensing.
                parser: Remove unused mul_inv option from scan_num(),
                use a SAU__noinline to help clang keep size down.
       * 2020-07-23: Move in mempool update from 2020-06
             "mgensys" experiment. The mempool is now ISC-relicensed.
         Old branch:
          - 2020-02-04: Minor mempool performance improvement using
                a first_i start for binary search, increased
                past non-free blocks on each block addition.
                Add MGS_MEM_DEBUG flag to common.h and mempool.c,
                for debug-friendly memory handling. Makes mempool
                calloc every allocation. This allows full testing
                of memory use with e.g. OpenBSD "vm.malloc_conf=S".
       * 2020-08-21: Move down file module changes.
         Old branch:
          - 2019-09-12: Merge down 08-24 file module refactoring,
                with finishing touch.
          - 2020-01-03: Merge -pedantic change for file.c.
          - 2020-07-23: Change file module to ISC license.
       * 2020-08-22: Move down parseconv refactoring.
         Old branch:
          - 2019-12-31: Split voicegraph from scriptconv,
                also adding builder.h. Renaming and refactoring.
          - 2020-01-01: Add missing SAU_ prefix for VoiceGraph type.
          - 2020-01-04: Move down split voicegraph from scriptconv
                from v0.3.6d - making it a split from parseconv.
                Keep it simple and without functional change.
                Rename the new header parseconv.h instead.
      2c091ad7
    • Joel K. Pettersson's avatar
      Use oscillator differentiation for PM too. · 98a7b8dd
      Joel K. Pettersson authored
      Properly use the first order pre-int./diff. anti-aliasing
      for PM too, and now also use the new code for sine waves.
      
      Use doubles for intermediate values, including wave lerp,
      solving the earlier problem with occasional overshooting,
      where factoring PM into differentiation made rare samples
      abnormally large, apparently due to inadequate precision.
      
      The above changes done by 2021-07-08.
      98a7b8dd
    • Joel K. Pettersson's avatar
      Tweak new oscillator code to restore old features. · d963542e
      Joel K. Pettersson authored
      * Use simpler naive oscillator code for 'sin'.
        No point in doing otherwise without changing
        PM to be done within, instead of outside of,
        anti-aliasing. Add USE_NAIVE testing define.
      * Use normal LUT for output when no phase inc,
        e.g. 0 Hz. Allows both DC output and PM used
        to drive a 0 Hz oscillator, like naive code.
      * Tune start values to get non-zero output for
        PILUT use on starting when such is expected.
      
      Change log:
       * 2021-07-06: First version.
       * 2021-07-19: Refactor extra values for wave types,
             store one array of a struct with them instead
             of one array per value. Add phase shift value
             and use instead of extending LUTs for shifted
             phase.
      d963542e
    • Joel K. Pettersson's avatar
      Redo wave type anti-aliasing using pre-integration. · 210fb273
      Joel K. Pettersson authored
      Remove the 2019 LUT 'sqr' and 'saw' step rounding
      which was fixed, not adapted to the frequency, to
      start over with earlier naive wave shape LUTs.
      
      Use pre-integration to provide some anti-aliasing
      for wave types instead, extending the oscillator.
      Only first-order for now, all wave types provided
      with a new set of pre-integrated LUTs ("PILUTs"),
      and scaling and offset values to use them the way
      the old were. The old LUTs and code also remain.
      
      This improves quality for all aliased wave types,
      similarly to how the DPW (differentiated parabolic
      wave) trick affects sawtooth waves. Computational
      overhead is fairly small. Note that PM is applied
      outside the smoothing to avoid rare large values.
      
      * Change SGS_Wave_luts array to pointer array.
      * Refactor osc, move LUT selection into SGS_Osc_run*().
      * Extend sin LUT by placing -cosin quarter
        first, for use as 'sin' PILUT.
      * Ensure osc module allows clickless differentiation
        start when LUT and/or phase are (re)set.
      * Rip out old 'sqr' and 'saw' LUT shape rounding.
      * Extend tri LUT by placing phase-shifted
        "-cotri" first, for use as 'sqr' PILUT.
      * Parabolic wave in 'saw' PILUT for DPW-like result.
      * Extend SGS_Wave_print() code used while testing LUTs.
      * Add 'tri' PILUT.
      * Tweak 'saw' LUT.
      * Use new fill function for PILUTs to calculate the messier-
        looking 'ahs', 'hrs', 'srs', and 'ssr' ones from the LUTs.
      
      Inspired by T.Rochebois's article, "Anti Aliasing Oscillators
      and Distortions with Pre Integrated Wave Tables".
      
      Change log:
       * 2021-07-03: First version.
       * 2021-07-19: Correct 'sqr'; extend tri LUT, like sin,
             for the correct phase.
      210fb273
    • Joel K. Pettersson's avatar
      Basic ramp curve changes. Refactor more. · bc813037
      Joel K. Pettersson authored
      Ramp curve changes:
       * Rename the old 'exp' and 'log'
         to 'xpe' (exponential envelope) and
         to 'lge' (logarithmic envelope),
         respectively. (The 'xpe' type is the most
         natural-sounding for envelope-like uses.)
       * Add new 'exp' and 'log' which internally
         select one of 'xpe' or 'lge' depending on whether
         the curve rises or falls, in order to behave much
         more like people would expect
         from curves named 'exp' and 'log'.
       * Add 'cos' curve, which rises or falls like a cosine
         moves from bottom to top or top to bottom. (Rougher
         approximation than would be used for an oscillator,
         but 99% accuracy seems good enough for ramp curve.)
      
      Update scripts and README for changes,
      add "engine_rumble.sgs"
      and "hearingrange.sgs" (sweep from 20 Hz to 20 kHz), and
      move devtests/drum.sgs to examples/unnamed3.sgs.
      
      Refactoring changes:
       * Further refactoring of the file module, part 1.
       * Split the generator's mixing code
         into a mixer module (without functional change).
       * Use DJB2 hash (with length addition) in symtab.
         A little better than the old DIY hash.
         No significant functional change.
      
      Reindent generator.c.
      
      Change log:
       * 2019-05-28: Reindent generator.c.
       * 2019-06-16: Merge back refactoring,
             keep old buf size in generator.
         Old branch:
          - 2019-06-13: Split out mixer module from generator.c.
       * 2019-06-18: Update generator buf size to
             match new older version.
       * 2019-06-30: Merge down slope->ramp and curve changes,
             along with script updates and a symtab hash change.
             Set version to v0.2.12.
         Old branch:
          - 2019-06-22: Begin v0.3.1-beta.
          - 2019-06-27: Rename 'exp'/'log' slope types
                to 'esd'/'lsd', add new 'exp'/'log' types which
                select 'esd' or 'lsd' for increase/decrease.
                Update scripts for changes, add "engine_rumble.sau",
                move devtests/drum.sau to examples/unnamed3.sau, and
                add "freqrange.sau" (sweep from 20 Hz to 20 kHz).
          - 2019-06-28: Change "slope change type" to "curve type"
                in script naming and parser, for consistency.
                Use DJB2 hash (with length addition) in symtab.
                Set version to v0.3.1. Update comments in slope.c.
                Rename "freqrange.sau" to "hearingrange.sau".
          - 2019-06-30: Rename slope module to ramp.
       * 2019-08-07: Merge Makefile -ffast-math portability fix.
       * 2019-09-12: Move down clean-up change from v0.3.2.
         Old branch:
          - 2019-08-22: Break out SAU_File_end() function.
       * 2019-12-12: Fix indentation in generator.c.
       * 2019-12-25: Merge ramp default time changes.
       * 2020-01-03: Merge clean-up changes.
       * 2020-07-23: Merge ramp & generator changes.
       * 2020-07-26: Keep version at v0.2-beta.
       * 2020-08-21: Split out the above from
             'r' syntax changes and more.
       * 2021-06-27: Rename ramp 'esd' to 'xpe', 'lsd' to 'lge'.
       * 2021-09-07: Add 'cos' ramp curve.
      bc813037
    • Joel K. Pettersson's avatar
      Rework audio mixing. Refactor generator. Change wave types. · 4f069f03
      Joel K. Pettersson authored
      Use floating-point processing in generator
      internally, until writing 16-bit output,
      instead of mixing float and int buffers.
      For PM phase offsets, get 32-bit int values
      from float buffer, instead of 16-bit values.
      Rework mixing, add clipping for audio output.
      
      Move oscillator sample block fill code
      to osc.c (from generator.c). Move lut,
      coeff fields to SGS_Osc type, from the
      types in generator.c.
      
      Change wave types:
       * Rename wave type:
          - 'sha' -> 'ahs' (absolute half-frequency sine).
          - 'szh' -> 'hrs' (half-rectified sine).
          - 'ssr' -> 'srs' (square root of sine).
       * Add new wave type:
          - 'ssr' (squared & square root of sine).
      
      Change log:
       * 2018-11-09: Complete changing generator to use float
             internally. Rework mixing, clip output.
             Move script.h and ptrlist to builder/.
             Complete branch merging.
       * 2018-11-11: Minor refactoring in generator.
             Minor comment clean-up.
       * 2019-05-28: Merge refactoring.
         Old branch:
          - 2019-02-07: Move osc block running to osc.c
                (split from generator.c).
       * 2019-06-16: Merge bugfix for generator timing,
             for newer adjusted design.
       * 2020-07-23: Split out after ramp and other refactoring.
             Merge renaming in ramp module.
             Replace osc module with newer version
             from the 2020-06 "mgensys" experiment,
             refactoring generator for moving coeff
             and lut fields to SGS_Osc. Now wave is
             ISC-licensed, along with the new osc.
       * 2020-07-26: Keep version at v0.2-beta.
       * 2021-06-27: Rename wave type 'ssr' -> 'srm',
             add new 'ssr'.
       * 2021-06-28: Rename wave type 'sha' -> 'ahs',
             and 'szh' -> 'hrs'.
       * 2021-06-29: Rename wave type 'srm' -> 'srs'.
      4f069f03
    • Joel K. Pettersson's avatar
      Rework ramp module. Refactor uses and more. · 3bef3ab0
      Joel K. Pettersson authored
      Refactor ramp parameters and their uses:
       * Remove the old SGS_Ramp type,
         renaming the SGS_RampParam type to SGS_Ramp.
       * Separate the ramp fill functions from the
         type and its uses. (E.g. future envelope support
         could use the fill functions with a different
         data structure and surrounding logic.)
       * New SGS_Ramp_run() function fully replaces
         parameter running function in generator.c.
       * Remove voice & operator attr fields and flags;
         these are now fully replaced by the SGS_Ramp
         flags and code.
       * Cleaner code for handling ramp data in parser
         and generator.
      
      Todo: Since earlier, dynfreq/dynamp parameter
      ratio flags are ignored; to correct handling.
      For now, they are simply removed.
      
      Improve -p printout, extending info for 'f' parameter
      and adding it for 'a' on each main per-operator line.
      
      Also refactor more modules:
       * Make arrtype add method return pointer to item
         in current array allocation, for initialization.
         Rename arrtype SGS_UInt8Arr to SGS_ByteArr.
       * Refactor mempool using arrtype, and initialize
         allocated memory to zero bytes.
         Split SGS_MemPool_memdup() from SGS_MemPool_alloc().
       * De-const-ify ptrlist item void pointers.
       * Refactor symtab, without functional change.
      
      Change log:
       * 2018-11-08: Refactor mempool using arrtype.
             Move wave module to program/.
             Split SGS_MemPool_memdup()
             from SGS_MemPool_alloc().
             Fix Makefile.
       * 2019-01-14: Complete branch merging.
             Minor clean-up.
             Set version to v0.5.0.
       * 2019-05-10: Merge changes.
             Undo file moves.
       * 2019-05-13: Place after new v0.4.4.
       * 2019-05-17: Merge refactoring of slope parameter handling,
             and accompanying changes, with adjustments.
             Merge param module into slope module, and
             re-rename SGS_TimedParam type to SGS_Slope.
             Also refactor symtab, without functional change.
         Old branch:
          - 2018-11-27: Refactor timed param handling,
                replacing the SGS_Slope type with use of
                SGS_TimedParam, and more fully moving out
                code for parameter "running" from generator.
                Remove "attr" fields and flags.
                Improve -p printout (more 'f', added 'a', info).
          - 2018-12-01: Add SGS_TimedParam_ENABLED(),
                refactor parser and generator handling of flags.
       * 2019-05-28: Merge refactoring.
         Old branch:
          - 2019-02-10: Rename SAU_UInt8Arr to SAU_ByteArr.
       * 2019-06-05: Merge diff after v0.2.3 syntax change.
       * 2019-06-13: Set version to v0.3.0.
       * 2019-06-16: Adjust parser for new v0.2.4 syntax changes.
       * 2019-06-18: Split out v0.2.9, place after v0.2.10.
       * 2019-06-22: Comment clean-up in mempool.c.
             Set version to v0.2.11.
       * 2019-08-07: Merge Makefile -ffast-math portability fix.
       * 2019-09-12: Move down renaming of slope module to ramp.
       * 2019-12-21: Merge 'S a' multiplier apply-to-ramp fix.
       * 2019-12-24: Merge clean-up changes for v0.2.5.
             Adapt v0.2.5 changes to use 'S t' as
             default time placeholder for ramps.
       * 2019-12-25: Fix partial ramp update (using the new flag),
             after renaming it (flip to _SET instead of _DEFAULT).
       * 2020-01-03: Move down a few clean-up changes:
         Old branch:
          - 2020-01-01: Make arrtype add method return pointer to item
                in current array allocation, for initialization.
                In mempool, use new return value of arrtype add.
          - 2020-01-03: Compile with -pedantic, remove warnings.
                Minor style diff in mempool.c.
                Remove the generator value-by-value ramp copying.
                De-const-ify ptrlist item void pointers.
       * 2020-01-29: Build without -pedantic
             after fixing most warnings. System libraries
             and differing C versions make -pedantic and -std=c??
             generate spurious warnings on some systems.
       * 2020-07-22: Split out the above from
             generator changes for mixing and further modularization.
             Keep version at v0.2-beta.
             Redo naming in ramp module.
      3bef3ab0
    • Joel K. Pettersson's avatar
      Crudely anti-alias 'sqr' & 'saw' waves, remove 'shh'. · 16dd00d6
      Joel K. Pettersson authored
      Wave type changes:
       * 'sqr' - Improve square wave quality
         by using a rounded step, replacing values
         with tanh upscaled-sine values,
         with 4*32 = 128 of 2048 samples smoothed.
       * 'saw' - Use adjusted version of the same
         technique for anti-aliased sawtooth wave,
         taking up 2*(58+6) = 128 of 2048 samples.
         (First 1 and middle 11 samples zero-filled.)
         Change slope to decreasing, for
         consistency with other wave types;
         amp. or freq. can be negative
         in order to get an increasing saw.
       * 'shh' - Removed. Too similar to old 'saw',
         and no point in keeping it as-is.
      
      (Also remove commented-out 'szhhr' wave type.)
      
      The 'sqr' and 'saw' changes greatly reduce
      aliasing while keeping them sounding fairly
      bright (but no longer attempting to
      represent ideal squares and sawtooths).
      They now lack the ear-splitting "bite" of real
      square and sawtooth waves (but otherwise sound
      as expected) at low frequencies,
      while at medium ones sounding quite good.
      
      Change log:
       * 2019-09-11: wave: Replace square wave step
             with tanh upscaled-sine values.
       * 2019-09-12: wave: 'sqr' - Further tweaks and
             aliasing reduction with 4*32 values replaced
             in 2048 value sqr LUT. Keep square wave fairly bright.
             'saw' - Similarly use tanh upscaled-triangle
             values for a smooth 'saw' step, taking up
             1/32 of the saw LUT values.
             Change 'saw' slope to decreasing.
             Remove 'shh' wave.
             Remove commented-out 'szhhr' code.
             Set version to v0.3.3.
       * 2019-09-23: Change 'saw' to use tanh upscaled-sine
             for aliasing reduction after figuring out
             different adjustments which make it better.
       * 2019-10-03: Further tweaks to bring sawtooth
             anti-aliasing up to par with square wave.
             Double length and scaling as for square,
             but move one zero sample from the middle
             to the beginning (the trick needed).
       * 2019-10-08: Move down to after v0.2.13.
             Set version to v0.2.14.
       * 2020-07-23: Move down to before v0.2.11.
             Keep version at v0.2-beta.
      16dd00d6
    • Joel K. Pettersson's avatar
      Support AUDIODEV env variable. · fd485376
      Joel K. Pettersson authored
      Check for the AUDIODEV environment variable,
      using it to override the default device name
      regardless of which type (ALSA, OSS, ...) is
      used. Similar to handling in other software,
      e.g. SoX and SDL. Empty strings are ignored.
      
      For OSS only, also check OSS_AUDIODEV if the
      AUDIODEV variable wasn't used, or "default".
      
      Credit to Art Nikpal (@hyphop at GitHub) for
      the basic idea, and SoX code as a reference.
      
      Further refactor player/audiodev code a bit.
      fd485376
    • Joel K. Pettersson's avatar
      Fix -r 1 hang, make 96000 default. Reorganize code. · 3f37b1ee
      Joel K. Pettersson authored
      Move 'audiodev' and 'wavfile' modules to 'player/',
      move 'renderer.c' into 'player/' as 'player.c', and
      rename 'builder/' to 'loader/', move 'builder.c' to
      'loader/' as 'loader.c'. Rename keyword-like SGS__*
      macros to sgs* without functional change. Relicense
      'audiodev' and 'wavfile' files, from LGPL-3 to ISC.
      
      Rename 'test-builder' to 'test-scan' and name
      the Makefile target 'tests' instead of 'test'
      (and minimize its linkage file dependencies).
      
      Change default -r sample rate to 96000 Hz,
      undoing the 2012-02-10 change to 44100 Hz.
      
      Add minimum per-channel buffer length
      (currently 1 sample) in player.c, fix
      hang if/when -r 1 loops 0-length run.
      
      Expand 'IDEAS' file on design
      ideas, and rename 'IDEAS.md'.
      
      Change log:
       * 2019-12-15: Expand 'IDEAS' file, and rename 'IDEAS.md'.
       * 2020-07-22: Rename renderer part -> player
             and move the audiodev & wavfile files.
             Also includes renaming SGS__* defines,
             for consistency, to sgs* (more like in
             2020-06 "mgensys"), and relicensing of
             audiodev & wavfile from LGPL-3 to ISC.
       * 2020-07-26: Reduce diff with 2020-06 "mgensys" experiment,
             changing default sample rate to 96000 Hz (was 44100 Hz
             after 2012-02-10). Also use ISC license header for the
             common module and math.h, to keep permissive code free
             from dependencies on including non-permissive code.
       * 2020-11-09: Renaming in "player/player.c".
       * 2020-12-14: Ensure output buffer holds >= 1 sample, fix
             hang with -r 1 when 0 samples were ran in run loop.
       * 2021-07-25: Move builder.c into builder/.
             Rename "test-builder" to "test-scan".
       * 2021-10-26: Rename 'builder/', 'loader/'.
      3f37b1ee
    • Joel K. Pettersson's avatar
      Add 'hold' ramp curve. Refactor scanning & ramp params. · ba7ebc72
      Joel K. Pettersson authored
      Recognize 'hold' ramp curve in scripts.
      Use new SGS_RampParam type for ramp parameters
      in script.h and program.h types.
      
      Break out PScanner struct from SGS_Parser.
      Refactoring without functional change,
      in preparation for merge with test scanner.
       * Move line num changes into basic scan_* functions.
       * Rearrange code, placing PScanner above Parser.
       * Rename scan_char() to scan_getc(),
         add scan_stashc() for next_c logic.
       * Add ScanLookup struct, stored in parser and pointed
         to by its scanner; preparation for future redesign,
         where the parser needs to associate additional data
         with the scanner.
       * Replace parser string matching
         using new SGS_SymTab_pool_stra()
         and string pool pointer comparison.
      
      Redesign test scanner. A start for bridging the design
      gap for the parser:
       * Separate getc and nospace version of getc
         (both types will be needed by the parser).
       * Break out update_cframe() and set_prevc(),
         use in get functions.
       * Renaming and minor tweaks.
      
      Simplify the file module (and change SGS_File_AFTER_EOF()
      to work regardless of whether pos was masked).
      No functional change for uses.
      
      Change log:
       * 2018-11-09: Rename slope-using params and their flags.
       * 2018-11-14: Add builder/script/param.h with
             type SGS_TimedParam, use in script.h types.
             Add slope change type 'hold'
             (by enabling and renaming 'state').
       * 2018-11-22: Move builder/script/param.h to program/param.h.
             Use SGS_TimedParam in program.h types, handling
             conversion directly in generator (removing
             the small added function from parseconv).
             Remove obsolete *_SLOPE parameter flags,
             keeping attribute *_SLOPE flags for now.
             Complete branch merging.
       * 2018-11-23: Refactor scanning code in parser,
             in preparation for merge with test scanner.
       * 2019-05-10: Merge changes.
             Adjust parser refactoring for new file code
             (slightly simplifying it).
             Move out param.h from builder/.
       * 2019-05-13: Place before new v0.5.0.
             Increase version to v0.4.4.
             Merge further parser refactoring (and polish it),
             along with some test scanner changes.
         Old branch:
          - 2018-12-04: Replace parser string matching
                using new SGS_SymTab_pool_stra()
                and string pool pointer comparison.
                Complete branch merging.
          - 2018-12-06: scanner: Rename old SGS_Scanner_getc() to
                SGS_Scanner_getc_nospace(), adding a more
                space-preserving function with the old name.
                Some further renaming and tweaks.
          - 2018-12-13: scanner: Break out update_cframe() and
                set_prevc(), use in get functions,
                and further changes.
       * 2019-05-15: Merge param.h into program.h.
             Rename SGS_TimedParam to SGS_SlopeParam.
       * 2019-05-26: Merge file module clean-up back.
             Update comments, refactor a bit more.
         Old branch:
          - 2019-05-24: Simplify file module.
       * 2019-05-27: Avoid future problems by
             ensuring SGS_File_AFTER_EOF()
             works after mask applied to pos.
       * 2019-06-05: Merge parser diff after v0.2.3 syntax change.
       * 2019-06-13: Set version to v0.2.9.
       * 2019-06-16: Adjust parser for new v0.2.4 syntax changes.
       * 2019-06-18: Place after new v0.2.9, set version to v0.2.10.
       * 2019-09-12: Merge diff for renaming slope module to ramp.
             Further rename SGS_SlopeParam to SGS_RampParam.
       * 2019-12-21: Merge 'S a' multiplier apply-to-ramp fix.
       * 2019-12-24: Adapt v0.2.5 changes to
             use 'S t' as default time placeholder for ramps.
       * 2020-07-13: Keep version at v0.2-beta.
      ba7ebc72
    • Joel K. Pettersson's avatar
      Support running multiple scripts. Use larger output buffer. · 76ef7574
      Joel K. Pettersson authored
      Support multiple script files or strings per command-line
      invocation. Also make corresponding changes to the
      'test-builder' program. (Use SGS_PtrList in main module,
      builder, and renderer for lists. Combine the old behavior
      with running through a batch of things at each stage.)
      
      Use 256 ms of audio output buffering in renderer.
      Fixes stuttering on NetBSD 8 (which requires >= 128 ms
      of buffering for consistently smooth playback).
      The extra 128 ms is for the sake of portability.
      (All non-NetBSD systems I personally use have however
      worked fine with the old 1024 sample buffering.)
      
      While at it, also increase the generator's internal
      buffer length from the ancient value of 256 samples
      to 1024. (This is simply a performance vs. memory
      use trade-off. The number of buffers could potentially
      grow into the hundreds or thousands for extreme input.
      This increases memory use fairly conservatively.)
      
      Const-ify pointers to non-modified SGS_Program instances.
      
      Change log:
       * 2019-06-04: Move multiple script args support back
             to v0.5.0, use the old version number.
         Old branch:
          - 2019-02-10: Support multiple script paths per
                command-line invocation. Also make corresponding
                changes to the 'test-builder' program.
                Move ptrlist to main dir (out of builder/).
                Increase version to v0.6.1.
                Const-ify non-modified SAU_Program pointers.
          - 2019-05-28: Merge support for multiple script args,
                and refactoring. Combine with support
                for -e <string> in the simplest way.
                Set version to v0.5.2. Update README.
          - 2019-05-29: Tweak usage notice.
       * 2019-06-18: Merge audio buffering changes.
             Move it all back to after v0.2.8,
             set version to v0.2.9.
         Old branch:
          - 2019-06-13: Increase generator buffer length
                from 256 samples to 1024 samples.
          - 2019-06-14: Change renderer output buffer
                sizing to remove stuttering on NetBSD.
                (Use 256 ms instead of 1024 samples.)
                Refactor the code in the process.
                Increase version to v0.3.2.
       * 2019-02-09: Merge changes for renderer.c,
             fixing crash on opening several files when
             only some failed to open.
             Simplify usage notice.
         Old branch:
          - 2019-06-22: Minor refactoring in renderer.c.
          - 2020-02-03: Add missing NULL checks in renderer.c;
                check for NULL programs, as is supposed to be done.
       * 2020-07-13: Keep version at v0.2-beta.
      76ef7574
    • Joel K. Pettersson's avatar
      Use restrict keyword. Update test code & split out as program. · 2f5b86aa
      Joel K. Pettersson authored
      Use restrict keyword for pointer function parameters
      throughout code. For now, this is the only use.
      Makes for a minor size and speed improvement.
      The design has been checked for safety with this,
      though something could have been missed.
      
      Various smaller updates for test lexer and scanner code.
      
      Split out usage of the test lexer and test scanner
      into the separate 'test-builder' program,
      built with 'make test'.
      
      Also add install/uninstall targets to Makefile.
      
      Change log:
       * 2018-11-18: Reduce lexer char switch cases to values 0-127,
             use default for the identical rest.
             Reduce scanner char handler array to 128 values,
             use entry for 0 when char > 127.
       * 2018-11-19: Move test lexer use to
             separate 'test-builder' program,
             instead of conditionally compiling it into sgensys.
             Add (unused) SGS_Scanner_handle_char1comments()
             for first-character-only line comment openers.
       * 2018-11-22: Move test scanner use to
             'test-builder' program.
             Complete branch merging.
       * 2018-11-23: Add SGS_Scanner_close().
       * 2018-11-28: Use restrict keyword.
             For now, only add to function argument pointers.
             Reduces size of the binary somewhat,
             and produces very marginal speed-up.
       * 2019-05-06: Move back to after new v0.4.2.
             Increase version to v0.4.3.
             Change test scanner file handling,
             write new SGS_Scanner_open().
             Copy scanner file handling to lexer.
             Update test-builder for new code.
       * 2019-05-10: Tweak usage notice.
             Fix missing part of scanner.c merge.
       * 2019-06-13: Set version to v0.2.8. Re-merge tidying.
       * 2019-06-22: Makefile: add install/uninstall targets.
       * 2019-09-12: Merge diff for renaming slope module to ramp.
       * 2020-07-13: Keep version at v0.2-beta.
      2f5b86aa
    • Joel K. Pettersson's avatar
      Add -e string evaluation option. Add test scanner. · 5c1c51ed
      Joel K. Pettersson authored
      Support direct evaluation of a string argument with
      a new -e option. E.g., ./sgensys -e "Osin f643 t1"
      will run (play) a 643 Hz oscillator for 1 second.
      
      Add experimental test scanner, a reworking of
      the test lexer; a draft for future redesign,
      as in breaking up the tasks of the lexer
      and/or an intermediate parser redesign.
      
      Add file module string open/read/close code,
      and change sgensys, builder, parser, lexer to use it.
      Also add support to file for creating nested instances,
      in preparation for future nested file usage.
      
      Updates to the test lexer.
      
      Change log:
       * 2019-04-24: Add file module string open/read/close code.
       * 2019-04-25: Name changes in file.
       * 2019-04-29: Move back to after new v0.4.0.
       * 2019-04-30: Add -e string evaluation option.
             Also change file module to support nested (linked)
             instances, in preparation for future addition
             of nested file usage (prepend/predefine arg,
             file includes from file, etc.).
             Increase version to v0.4.1.
             Merge test lexer changes,
             with some final tweaks.
         Old branch:
          - 2018-11-04: Import updated test lexer code.
                (Drop new test scanner for now.)
          - 2018-11-09: Silence warnings in test lexer.
          - 2018-11-15: Use SGS_File_skipline() in test lexer.
          - 2018-11-16: Debug test lexer, also a few clean-ups
                and performance tweaks.
          - 2018-11-18: Minor fixes and tweaks for test lexer.
          - 2018-11-19: Minor clean-up in test lexer.
          - 2019-01-14: Use SGS_File_trynewline() in test lexer.
       * 2019-05-04: Add test scanner module,
             merging tidied up basic version.
         Old branch:
          - 2018-03-25: Add scanner module (incomplete)
                for use in parser (next) and lexer (later).
          - 2018-04-07: Some debugging and improvements
                for test scanner.
          - 2018-04-13: Improve test scanner design and
                add C-style comment support.
          - 2018-11-05: Complete branch merging.
                (Add the postponed test scanner.)
                Minor clean-up in test scanner.
          - 2018-11-09: Silence warnings in test scanner.
          - 2018-11-15: Use SGS_File_skipspace(),
                SGS_File_skipline(), in test scanner.
          - 2018-11-18: Properly check scanner EOF status for error.
          - 2018-11-19: Renaming and minor changes in test scanner.
                Use symtab in scanner symbol string reading.
          - 2019-01-14: Use SGS_File_trynewline() in test scanner.
       * 2019-05-08: Tweak usage notice.
       * 2019-05-10: Add -e quick test to README.
             Fix parser string matching when item
             ends with end of file marker
             (as happens with -e "Osin").
             Fix missing part of scanner.c merge.
       * 2019-06-13: Set version to v0.2.7.
             Merge minor code tidying for lexer.c, scanner.c.
       * 2020-02-09: Simplify usage notice.
       * 2020-07-13: Keep version at v0.2-beta.
      5c1c51ed
    • Joel K. Pettersson's avatar
      Add file module, use for scanning. · b91afaa1
      Joel K. Pettersson authored
      Rework scanning in the parser using new low-level code
      grown out of the work on the test lexer, and further changes:
       * Split out file reading code from the lexer,
         elaborating it into the new file module.
       * Replace character-level reading in the parser,
         while preserving the old structure;
         name functions directly using SGS_File read_*(),
         and scanning functions using SGS_Parser scan_*().
       * Use newer SGS_File functions for number reading
         (replacing quick-and-dirty old code).
       * Rework label string reading, and use
         SGS_File_skipstr() for truncated labels.
      
      Change log:
       * 2018-02-27: Split out reader module
             from lexer, also use in old parser.
       * 2018-03-01: Rename SGS_READ_*() macros to SGS_READER_*().
       * 2018-03-09: Add SGS_READER_TESTC()
             and SGS_READER_TESTCGET() macros
             replacing testc() and testgetc()
             functions in parser.c.
       * 2018-03-14: Rename reader module to fread.
       * 2018-03-17: Add SGS_FREAD_RETC(), minor parser refactoring.
       * 2018-10-23: Refactor fread, rename to file.
       * 2018-11-02: Re-add end marker logic to file module.
       * 2018-11-04: Add -v version number, initially at v0.5.0.
       * 2018-12-29: Complete branch merging.
             Minor naming adjustments for parser code.
             Move SGS_File buf array to end of struct,
             reducing the binary size.
       * 2019-01-10: Merge newer file module and more back.
             Reduce differences with newer version by replacing
             obsoleted functions in the parser. Also replace less
             functional dummy code with newer calls in the lexer.
         Old branch:
          - 2018-03-25: Rename reader TESTCGET macro to TRYC,
                add SETC/SETC_NOCHECK for use in test scanner.
          - 2018-04-07: Rework reader module
                into cbuf, stream, and streamf.
          - 2018-11-04: Merge file module
                with code from stream/streamf.
          - 2018-11-11: Add SGS_File_getstr()
                and SGS_File_getint(),
                use in scanning/parsing code.
          - 2018-11-16: Shorten SGS_File_get* function names.
                Add SGS_File_getd(), use in parser
                and refactor scanning of numbers.
                Refactor SGS_File_geti().
                Add SGS_File_skipspace(), SGS_File_skipline().
                Adjust SGS_File_gets() length param to match use.
          - 2018-11-19: Fix SGS_File_geti()
                edge case for reading negative int.
          - 2018-11-29: Refactor cbuf and file modules.
                Reduces binary size.
          - 2018-12-15: Merge cbuf module back
                into file module.
                Add and use SGS_File_skips().
          - 2018-12-21: Fix for changed file module code.
          - 2018-12-30: Change uint32_t to size_t
                for string lengths.
                Simplify SGS_File_AT/AFTER_EOF() macros.
          - 2019-01-08: Add SGS__noinline macro
                for GCC/clang noinline attribute,
                use to keep clang from inlining
                scan_warning() in parser (saving ~4KB).
                Add SGS_File_trynewline().
          - 2019-01-10: Change file module position handling.
                Wrap position to within buffer area boundary on each
                operation which checks the call position, before the
                call. Use wrapped call positions. Makes ungets safe.
       * 2019-01-11: Set version to v0.4.0.
             (Reserve higher for after improved audio mixing.)
             A few comment, macro improvements in file module.
       * 2019-05-04: Rename SGS_File_gets()/skips()
             to SGS_File_getstr()/skipstr().
             Use create/destroy functions in parser and lexer,
             fixing previous merge.
       * 2019-06-05: Merge parser diff after v0.2.3 syntax change.
       * 2019-06-13: Place after new v0.2.5, set version to v0.2.6.
       * 2019-06-16: Adjust parser for new v0.2.4 syntax changes.
       * 2019-09-12: Merge diff for renaming slope module to ramp.
       * 2019-12-24: Move clean-up change down from v0.2.12.
             Also remove junk "case '{'" from some prior rebasing.
         Old branch:
          - 2019-07-18: Use isinf() for infinite-number checks.
                Replace "fabs(x) == INFINITY" with "isinf(x)".
       * 2020-02-09: Merge num.exp. fix for successive subtractions.
       * 2020-07-13: Keep version at v0.2-beta.
      b91afaa1
    • Joel K. Pettersson's avatar
      Add ramp module, refactor parser & generator. Fixes. · 109850a1
      Joel K. Pettersson authored
      Bugfixes:
       * Adjust which flags the parser checks to
         allow/disallow nesting-dependent 'r' and 'i'
         syntax elements, correcting handling for
         label references. Also make the parser use
         flags to cleanly guard against wrong end_*()
         processing for nested ParseLevel instances.
       * Add checks in parser to reject infinite numbers
         and expressions containing them.
       * For ramp default time duration, carry over
         'S t' default time instead of using a fixed
         1 second default. Changes default time for
         panning, and for operator ramps where the
         operator previously had infinite time set.
      
      Clean-ups:
       * Turn Valit (VALue ITeration) types and code
         from program.h and generator.c into the new
         ramp module and SGS_Ramp type.
       * Simplify parse level SDPL_IN_* "location".
         Replace flags and macros with a simple enum state.
         No functional change, as only one flag was set at
         a time.
       * Use size_t for string and buffer lengths.
      
      Change wave LUTs from 16-bit int to float
      (refactoring osc & updating generator).
      No significant quality difference in the output,
      as mixing is still 16-bit.
      
      Change log:
       * 2019-06-13: Merge various clean-ups, and the change of
             wave LUTs from 16-bit int to float.
             Set version to v0.2.5.
         Old branch:
          - 2018-07-30: Change "http" to "https" in
                heading license comment.
          - 2018-11-06: Break out slope from program/generator.
                Change wave LUTs from int16_t to float.
                Refactor osc, update generator.
          - 2019-04-30: Place after new v0.4.1.
                Increase version to v0.4.2.
                Bring in README update.
          - 2018-12-29: Add check for infinite numbers in parser,
                refactor reading of multiplicative inverse numbers.
          - 2018-12-30: Change uint32_t to size_t for string lengths.
          - 2019-01-11: Complete merge of uint32_t -> size_t changes.
          - 2019-05-04: Add SGS__malloclike()
                to SGS_create_*() functions where missing.
          - 2019-05-17: Add missing #pragma once to slope.h.
          - 2019-06-05: Merge README diff after v0.2.3 syntax change.
       * 2019-08-07: Merge Makefile -ffast-math portability fix.
       * 2019-09-12: Rename slope module to ramp.
             (For cleaner diffs and old versions.)
       * 2019-12-21: Merge 'S a' multiplier apply-to-ramp fix.
       * 2019-12-22: Merge composite timing fix.
       * 2019-12-24: Move down clean-up changes
             from v0.2.6, v0.2.12, and v0.3.1d.
             Also change default time for ramp, using a flag
             instead of placeholder value, and using the 'S t'
             value instead of a fixed 1 second.
         Old branch:
          - 2018-12-29: Complete branch merging.
                Simplify parse level SDPL_IN_* "location",
                replacing flags and macros with a simple enum
                state, as only one flag was set at a time.
          - 2019-07-18: Use isinf() for infinite-number checks.
                Use isnan() for portable NAN checks in parser.
          - 2019-09-12: Merge down to v0.2.12.
          - 2019-12-21: Change which flags are checked to
                allow/disallow 'r' (rel. freq.) and 'i' (inf. time),
                fixing syntax for "@label" references. Update README.
                Change parser to use flags to cleanly guard
                against wrong end_*() processing for nested
                ParseLevel instances.
       * 2020-07-13: Keep version at v0.2-beta.
      109850a1
    • Joel K. Pettersson's avatar
      Add arrtype module, rework parseconv. Replace symtab. · 7063de0f
      Joel K. Pettersson authored
      Part 1 of redesigning parseconv and generator as
      planned in 2013. Traverse graph before generator,
      determining which operators to use and how to use
      them. Not complete, the generator still using the
      old recursive algorithm. Simplifies some code in
      generator.
      
      Do a clean-up rewrite of parseconv.c, using the
      new arrtype (generic array) module for its simple
      dynamically-sized arrays.
      
      Calculate duration of script/program and
      include in program struct.
      Duration now printed with -p option.
      
      Changes include:
       * Use an array of operator data instances per
         event, instead of splitting events with several.
       * Fully separate voice & operator parameter flags
         (which were already stored separately during
         parse), renaming enums. Also separate the enums
         for voice & operator "attr" values (which were
         already stored separately).
       * Rename various types, fields, and flags in program.h.
         Use SGS_P* names for all voice and operator constants.
       * Change time types to uint32_t from int32_t, setting
         SGS_TIME_INF to UINT32_MAX instead of -1. (Infinite
         time is handled as a special value for nested
         operators, as of 2012-01-23. This reverses the type
         change from unsigned to signed done then.)
       * Make voice and operator IDs unsigned, replacing the
         use of -1 for no ID with named enums.
      
      Also replace the old symtab placeholder with the new
      hash table, and update label handling in the parser.
      Remove obsolete parser string alloc/free code
      (reversing a 2012-01-12 change).
      
      Script syntax: Labels can now only contain
      alphanumeric characters and '_'. Any other character
      will end and follow the label.
      
      Change log:
       * 2018-10-29: Complete branch merging.
             Further program module changes.
             Use partially-done redesign in generator.
             Further rename flags and fields.
         Old branch:
          - 2013-08-05: Redesign sketch #1 (non-working)
                for program & generator.
          - 2014-10-05: Redesign sketch #2 (still non-working)
                for program.c, and minor change in parser.c.
          - 2018-02-14: Redesign sketch #3 (non-working),
                adding interpreter and turning
                new generator version into renderer
                for its results.
          - 2018-02-16: Style change for new interpreter.
          - 2018-02-24: Rename program module to builder,
                splitting header.
          - 2018-07-01: Add some code to interpreter.
                Also change builder to count op & voice
                data struct instances, for one-off
                allocation of corresponding result structs
                in interpreter.
          - 2018-07-02: Use unsigned values for time
                except when negative times are needed.
                Also make voice and operator IDs unsigned.
          - 2018-07-26: Undo renaming program to builder.
                Simplistically assign block IDs in
                interpreter module. Prepare for merge
                with program module.
          - 2018-07-27: Redesign sketch #4. Turn old program module
                into imp (intermediate program). Turn useful
                code from interpreter into new program
                module. Unlink renderer from build.
          - 2018-07-29: Build list of operator references (new type)
                per-voice in program module.
                Create garr (generic array) module,
                use in imp & program modules.
          - 2018-08-21: Merge imp back into program.
                General round of fixes and clean-ups.
                Use partially-done redesign in generator.
                Remove leftover files with redesign sketches.
          - 2018-08-23: Flense redesign sketch traces
                from generator.
       * 2018-10-31: Turn old GRAPH voice
             parameter into SDEV flag.
             Correct fix in mempool.c.
             Give -p printout prettier heading part.
             Refactor parser scan code.
       * 2018-11-02: Minor refactoring of parser scan code.
       * 2019-06-07: Merge minimal redesign changes from old v0.4.0.
             Adjust old parser code to work without new file module,
             and re-do trivial clean-up.
             Increase version to v0.3.2.
             Re-add bugfix for too-long label (max index was one
             too high), and add debug script for too-long label.
         Old branch:
          - 2018-03-14: Fully replace old symtab code with the new,
                and parser clean-ups.
          - 2018-06-30: Change string pointer type used in
                symtab calls from char to void, add length args.
          - 2018-08-29: Minor mempool clean-up.
          - 2018-09-11: Refactor garr (generic array) module.
          - 2018-10-23: Fix mempool bug introduced with refactoring.
          - 2018-10-27: Rename garr to arrtype. Correct README.
       * 2019-06-16: Adjust parser for new v0.2.4 syntax changes.
       * 2019-06-30: Update -p printout details
             to match June syntax changes.
       * 2020-07-13: Merge back as intermediate change.
             Keep version at v0.2-beta.
      7063de0f
    • Joel K. Pettersson's avatar
      Further syntax changes. More bugfixes. Reorganize code. · d8ec9664
      Joel K. Pettersson authored
      Script syntax changes:
       * Label referencing after defining:
         From ":label" to "@label".
       * Compound value (e.g. gradual value change,
         arg value with subvalues): From "[...]" to "{...}".
       * PM modulator list prefix: Change from "p*" to "p+".
         (I.e., a list uses "p+[]". More fitting, as PM amounts
         to adding the amplitude of modulator(s) to the phase.)
       * Add downscaling of output amplitude by voice count
         by default. Using "S a" disables it.
       * Allow 'a' (amplitude) parameter for AM and FM modulators.
         (Previously disallowed within "a![]" and "f![]"/"r![]".)
       * Multiple operator binding: From "{...}" to
         nesting syntax prefixed by '@', i.e. "@[...]".
       * Reject stray '{'s and '['s. Disallow '[]' lists separate
         from those assigned to list parameters. Was undocumented
         and useless and could cause crashes. A more general list
         could be added later; the removed syntax was a hold-over
         from an ancient "allow more free whitespace use" feature
         (broken by the time of the 2012 releases).
      
      Todo:
       * Make multiple operator binding functional.
         (It has been a "todo" since it was added.)
      
      Wave type changes:
       * Make 'saw' (saw wave) increasing instead of decreasing.
         (Negative frequency or amplitude gives a decreasing saw.)
      
      Reorganize code:
       * Move parser.c, program.c, and the lexer and symtab modules
         to builder/, splitting out builder.c and renaming files:
          - parser.h -> script.h (parser output).
          - program.c -> parseconv.c.
         Place conditionally-compiled test use of lexer in builder.c.
       * Move generator and osc to renderer/,
         splitting out renderer.c from sgensys.c.
       * Create common module, moving the old sgensys.h contents
         to common.h. Add and use utility functions:
          - SGS_warning(), SGS_error(): now used for warnings
            and errors (when the format is suitable).
          - SGS_memdup(), SGS_strdup(): moved from parser.c.
      
      Consistent type and function naming:
       * Rename each "SGSType" to "SGS_Type".
       * For function and macro names including a type,
         use same (mixed) case as in type.
      
      Further clean-ups:
       * Use size_t for event IDs, uint32_t for operator IDs,
         uint16_t for voice IDs.
       * Rename parser struct types, flags, and functions.
         Name types "SGS_Script*", flags "SGS_S*".
       * In parser result (SGS_Script),
         include options set in script and script name.
       * Add circular reference guard for operators in generator to
         avoid crashes due to incompletely supported features.
       * Refactor generator memory handling.
         Also somewhat simplify memory handling in program module.
       * Add -p option for printing script info after loading.
         No longer print the program "debug info" unless -p used.
      
      Change log:
       * 2018-04-13: Rename parser struct types and flags.
       * 2018-04-18: Simplify memory management in program
             and generator. Implement downscaling
             of amplitude by voice count by default.
       * 2018-06-02: Undo faulty simplification in parser code, and
             some further renaming. Add circular reference
             guard for operators in generator, and some
             further clean-ups.
       * 2018-06-30: Rename types from "SGSName" to "SGS_Name".
             Rename corresponding functions and macros
             to use same (mixed) case in included type
             name.
       * 2018-09-11: Create common module, refactor warnings and
             errors. Move memdup from parser to common.
       * 2018-10-04: Further renaming of parser structs and flags.
             Some additional tidying.
       * 2018-10-15: Reorganize code, moving parser.c, program.c,
             and symtab to builder/. Rename program.c to
             parseconv.c, split out builder module.
             Further flag renaming in parser.c.
             Add -p option for printing program info.
       * 2018-10-16: Move lexer to builder/. Update headers, comments.
             Move lexer test invocation to builder.c.
             Complete branch merging.
             Split out renderer module from sgensys.c.
             Move audiodev, wavfile, generator, and osc
             to renderer/.
             Some code tidying.
       * 2018-10-17: Move audiodev and wavfile out from renderer/.
             Make "saw" wave increasing instead of decreasing.
             Replace renderer.h and builder.h with
             combined sgensys.h.
       * 2018-10-18: Enable 'a' parameter for
             "f!<>"/"r!<>" and "a!<>".
       * 2018-10-23: Change PM list syntax from "p*<>" to "p+<>".
       * 2018-12-25: Remove extra linebreak from file open error.
       * 2019-06-05: Merge syntax changes.
             Increase version to v0.3.1.
             Clean up a few scripts.
       * 2019-06-13: Set version to v0.2.4.
       * 2019-06-16: Backport further simple syntax changes.
         Old branch:
          - 2019-02-08: Fix inconsistent indentation
                in a few scripts.
          - 2019-06-13: Three simple syntax changes.
                Label ref: from ":label" to "@label".
                Subvalues: from within "[...]" to "{...}".
                Mul. op.b: from within "{...}" to "@[...]".
       * 2019-06-30: Update -p printout details
             to match June syntax changes.
       * 2019-08-07: Move back Makefile -ffast-math portability fix.
             Also update unusable 'devtests/newconcept' script.
         Old branch:
          - 2019-08-06: Fix parsing when -ffast-math breaks isnan().
                Only build some files with -ffast-math.
       * 2020-07-13: Keep version at v0.2-beta.
       * 2021-06-26: Check for stray '{'s & '['s.
       * 2021-07-19: Merge fixes as of the earlier commits.
      d8ec9664
    • Joel K. Pettersson's avatar
      Debug num. expr. parsing. Debug timing code. Update devtests/. · f2368297
      Joel K. Pettersson authored
      Numerical expressions: Further change parsing
      for correctness and consistency.
       - Fix bug disallowing sign before a nested '(' after '('.
       - Fix result of several subtractions in succession.
       - Fix handling of '^' (to the power of) priority,
         truly binding it more closely than other operators.
       - Only allow arithmetic inside parentheses.
         (Previously allowed without parentheses when
         no whitespace separated parts of the expression.)
       - Only allow number sign within parentheses.
         (Previously '-' sign was allowed without parentheses.
         This frees up '-' for new future uses.)
       - Allow '+' as sign (not only as operator)
         in addition to '-'.
      
      Backport small-scale parser changes for timing to debug '|'
      (time separator) and default time duration handling. Simply
      adapt the start/end tracking for grouping without adding an
      extra node. defaulttime* test scripts (formerly script3.sgs
      and another) now have the correct timing for the operators.
      
      Further rename some devtests/ scripts. Also add notes/, and
      move IDEAS and "devtests/newconcept" there. Move down added
      "warning" devtest scripts from later commits, additionally.
      
      Change log:
       * 2020-12-28: Take care of the low-hanging fruit in
             fixing remaining timing bugs. Remove bug-inducing
             lines in group_events(), disable a call for \
             which doesn't work properly.
       * 2021-06-26: Redo the remaining debugging more simply.
             The key is the start/end tracking, and simple update
             approach. Also redo 2020-10-20 devtests/ cleanup.
       * 2021-07-17: Backport it further.
       * 2021-07-19: Move down num. expr. fixes.
         Old branch:
          - 2018-12-25: Further changes to numerical expression
                parsing for correctness and consistency.
                Add warning for '(' without closing ')'.
          - 2020-02-09: num.exp. parsing:
                Fix result of several subtractions in succession.
       * 2021-10-27: Rewrite README "Numerical expressions" part.
      f2368297
  3. 31 Dec, 2020 3 commits
    • Joel K. Pettersson's avatar
      Change scope nesting syntax. Parsing and other fixes. · 9a1f0afa
      Joel K. Pettersson authored
      Change scope nesting syntax from "<...>" to "[...]".
      ('<' and '>' are now unused. "[...]" is now used both for
      lists of objects, and arguments with several sub-values.)
      
      Bugfixes:
       * Numerical expression parsing:
         Fix really old bug which prevented evaluation
         of "Y" in an expression of the form "((X)Y)".
       * Parsing on systems where -ffast-math breaks NAN checks:
         Portability requires limiting the use of -ffast-math.
         (Only use -ffast-math for files with float-heavy code
         which needs performance and ignores non-finite values.)
       * WAV file output:
         Correct byte length in header,
         was channel-count times too large.
         (Avoid double multiplication.)
       * 'S a' (Set amplitude multiplier):
         Apply multiplier to amplitude valit/ramp target,
         not only the normal or initial value.
         (This was missed a long time ago.)
       * Fix edge case for composite event timing,
         adding and checking a flag for the existence of
         composite follow-ons before assigning infinite time.
      
      Add -v version number, initially at v0.2-beta.
      
      Change log:
       * 2018-12-21: Fix two outdated scripts in devtests/.
             Fix really old bug in parsing of numerical
             expressions with nested parentheses, which
             prevented "Y" in an expression of the form
             ((X)Y) from being evaluated.
       * 2019-06-05: Change scope nesting syntax
             from "<...>" to "[...]".
             Add -v version, initially at v0.3.0.
       * 2019-06-13: Set version to v0.2.3.
       * 2019-06-30: Update debug printout details
             to match June syntax changes.
       * 2019-08-07: Move back Makefile -ffast-math portability fix.
             Also update unusable 'devtests/newconcept' script.
         Old branch:
          - 2019-08-06: Fix parsing when -ffast-math breaks isnan().
                Only build some files with -ffast-math.
       * 2019-09-14: wavfile.c bugfix - avoid double multiplication:
             Correct byte length in header,
             was channel-count times too large. (Bug from 2012.)
       * 2019-12-21: Move back fix to apply 'S a' multiplier
             to valit/ramp target, not only initial value.
       * 2019-12-22: Add and check flag for composite event timing,
             to prevent assigning infinite time when a next composite
             exists.
       * 2020-07-13: Set version to v0.2-beta.
      9a1f0afa
    • Joel K. Pettersson's avatar
      Add/rename wave types. Change PM syntax. Reorganize scripts. · e4d10f3e
      Joel K. Pettersson authored
      Change PM modulator list syntax from "p!<>" to "p*<>".
      Since semantics differ for PM lists vs. AM and FM lists,
      make this clearer in the syntax.
      (For PM lists, modulator amplitudes are summed,
      while for AM and FM lists, they are multiplied.)
      
      Split osc module into osc and wave. Wave type changes:
       * Add 'sha' (half-frequency absolute sine).
       * Add 'szh' (half-zero'd sine).
       * Add 'shh' (first quarter of sine).
       * Rename 'srs' (square root of sine) to 'ssr'.
      
      Move wave type names from parser to wave module.
      
      Reorganize example and test scripts. Move some old and useful
      scripts from devtests/ to examples/tests/. Rename scripts,
      add descriptions to some of them, modify a few, remove a few
      which are useless, and add more wavetype testing.
      
      Change log:
       * 2018-04-18: Move wave type names to osc module, add new
                     'sab' wave type, rename 'srs' to 'ssr'.
                     Reorganize and update example and test scripts.
       * 2018-06-02: Add 'shw' and 'shr' wave types, and
                     further LUT init code changes.
       * 2018-06-30: Split osc module into wave and osc.
       * 2018-09-12: Rename wavetypes
                     ("sab"->"sah", "shw"->"szh", "shr"->"szhhr").
       * 2018-09-27: Rename wave type 'sah'->'sha',
                     add 'shh', comment out 'szhhr'.
       * 2018-09-29: Rename debug #define switches in sgensys.h.
       * 2018-10-16: Update headers, heading comments, for added code.
                     Complete branch merging.
       * 2018-10-19: Change PM list syntax from "p!<>" to "p*<>".
       * 2020-07-11: Re-split in current branch
                     to provide fuller history.
      e4d10f3e
    • Joel K. Pettersson's avatar
      Support sndio. Parser & "program" refactoring. · 9a45f109
      Joel K. Pettersson authored
      Support sndio and use on OpenBSD. Fixes audio on newer OpenBSD.
      (Remove OSS OpenBSD case and for NetBSD correct to /dev/audio.)
      Clean up the Linux audio code. Improve audiodev error messages.
      
      Program & parser changes:
       * Rework the SGSNodeList parser code into the SGSPtrList
         type, split out into the ptrlist module.
       * Return parser result in new SGSParserResult type. Add
         parser module method for destroying it, instead of it
         being implemented in program module. Add missing list
         clearing.
       * Rename voice and operator parameter flags
         from SGS_* to SGS_P_*.
      
      Further edit usage notice.
      
      Makefile changes: compile with -std=c99,
      add missing header dependencies.
      
      Change log:
       * 2018-02-16: Renamed voice and operator parameter flags
                     from SGS_* to SGS_P_*.
       * 2018-02-19: Split out ptrarr module from parser, reworking
                     node list code and its uses.
       * 2018-02-20: Makefile changes:
                     add -Werror=implicit-function-declaration,
                     list more header dependencies.
       * 2018-03-10: Change ptrarr to work more like old nodelist,
                     re-adding case for < 2 items and needed macros.
       * 2018-08-23: Makefile: use -std=c99. Adjust audiodev.
       * 2018-09-09: Add sndio support, use on OpenBSD.
                     Fixes audio on newer OpenBSD.
                     Move audiodev implementation files to audiodev/.
       * 2018-09-11: DragonFly portability fix:
                     On DragonFly, cannot build audiodev with
                     _POSIX_C_SOURCE defined (needed on Linux),
                     only define _POSIX_C_SOURCE on Linux,
                     in audiodev.c instead of in Makefile.
       * 2018-09-20: Replace ptrarr with cleaned-up ptrlist.
                     Fixes and clean-ups for parser, program,
                     as well as some addititional tidying.
       * 2018-10-12: audiodev code tidying, and
                     fix typo which broke Linux build.
                     Some further code tidying.
       * 2019-04-18: Re-split in current branch
                     to provide fuller history.
       * 2019-04-26: Remove useless uint typedef.
       * 2020-12-31: OSS on NetBSD: /dev/sound -> /dev/audio.
      9a45f109