Skip to content
Myr

stb_hexwave.h

This file

Path

stb_hexwave.h

680 lines · 26.8 KiB · C

Last changed by

stb_hexwave tweak commentSean Barrettbefore adoptionc9064e3

History of this file

Take it

1// stb_hexwave - v0.5 - public domain, initial release 2021-04-012//3// A flexible anti-aliased (bandlimited) digital audio oscillator.4//5// This library generates waveforms of a variety of shapes made of6// line segments. It does not do envelopes, LFO effects, etc.; it7// merely tries to solve the problem of generating an artifact-free8// morphable digital waveform with a variety of spectra, and leaves9// it to the user to rescale the waveform and mix multiple voices, etc.10//11// Compiling:12//13//   In one C/C++ file that #includes this file, do14//15//      #define STB_HEXWAVE_IMPLEMENTATION16//      #include "stb_hexwave.h"17//18//   Optionally, #define STB_HEXWAVE_STATIC before including19//   the header to cause the definitions to be private to the20//   implementation file (i.e. to be "static" instead of "extern").21//22// Notes:23//24//   Optionally performs memory allocation during initialization,25//   never allocates otherwise.26//27// License:28//29//   See end of file for license information.30//31// Usage:32//33//   Initialization:34//35//     hexwave_init(32,16,NULL); // read "header section" for alternatives36//37//   Create oscillator:38//39//     HexWave *osc = malloc(sizeof(*osc)); // or "new HexWave", or declare globally or on stack40//     hexwave_create(osc, reflect_flag, peak_time, half_height, zero_wait);41//       see "Waveform shapes" below for the meaning of these parameters42//43//   Generate audio:44//45//     hexwave_generate_samples(output, number_of_samples, osc, oscillator_freq)46//       where:47//         output is a buffer where the library will store floating point audio samples48//         number_of_samples is the number of audio samples to generate49//         osc is a pointer to a Hexwave50//         oscillator_freq is the frequency of the oscillator divided by the sample rate51//52//       The output samples will continue from where the samples generated by the53//       previous hexwave_generate_samples() on this oscillator ended.54//55//   Change oscillator waveform:56//57//     hexwave_change(osc, reflect_flag, peak_time, half_height, zero_wait);58//       can call in between calls to hexwave_generate_samples59//60// Waveform shapes:61//62//   All waveforms generated by hexwave are constructed from six line segments63//   characterized by 3 parameters.64//65//   See demonstration: https://www.youtube.com/watch?v=hsUCrAsDN-M66//67//                 reflect=0                          reflect=168//69//           0-----P---1                        0-----P---1    peak_time = P70//                 .     1                            .     171//                /\_    :                           /\_    :72//               /   \_  :                          /   \_  :73//              /      \.H                         /      \.H  half_height = H74//             /       | :                        /       | :75//       _____/        |_:___               _____/        | :       _____76//           .           :   \        |         .         | :      /77//           .           :    \       |         .         | :     /78//           .           :     \     _/         .         \_:    /79//           .           :      \  _/           .           :_  /80//           .          -1       \/             .          -1 \/81//       0 - Z - - - - 1                    0 - Z - - - - 1   zero_wait = Z82//83//    Classic waveforms:84//                               peak    half    zero85//                     reflect   time   height   wait86//      Sawtooth          1       0       0       087//      Square            1       0       1       088//      Triangle          1       0.5     0       089//90//    Some waveforms can be produced in multiple ways, which is useful when morphing91//    into other waveforms, and there are a few more notable shapes:92//93//                               peak    half    zero94//                     reflect   time   height   wait95//      Sawtooth          1       1      any      096//      Sawtooth (8va)    1       0      -1       097//      Triangle          1       0.5     0       098//      Square            1       0       1       099//      Square            0       0       1       0100//      Triangle          0       0.5     0       0101//      Triangle          0       0      -1       0102//      AlternatingSaw    0       0       0       0103//      AlternatingSaw    0       1      any      0104//      Stairs            0       0       1       0.5105//106//    The "Sawtooth (8va)" waveform is identical to a sawtooth wave with 2x the107//    frequency, but when morphed with other values, it becomes an overtone of108//    the base frequency.109//110//  Morphing waveforms:111//112//    Sweeping peak_time morphs the waveform while producing various spectra.113//    Sweeping half_height effectively crossfades between two waveforms; useful, but less exciting.114//    Sweeping zero_wait produces a similar effect no matter the reset of the waveform,115//        a sort of high-pass/PWM effect where the wave becomes silent at zero_wait=1.116//117//    You can trivially morph between any two waveforms from the above table118//    which only differ in one column.119//120//    Crossfade between classic waveforms:121//                                            peak     half    zero122//        Start         End         reflect   time    height   wait123//        -----         ---         -------   ----    ------   ----124//        Triangle      Square         0       0      -1..1    0125//        Saw           Square         1       0       0..1    0126//        Triangle      Saw            1       0.5     0..2    0127//128//    The last morph uses uses half-height values larger than 1, which means it will129//    be louder and the output should be scaled down by half to compensate, or better130//    by dynamically tracking the morph: volume_scale = 1 - half_height/4131//132//    Non-crossfade morph between classic waveforms, most require changing133//    two parameters at the same time:134//                                           peak     half    zero135//      Start         End         reflect    time    height   wait136//      -----         ---         -------    ----    ------   ----137//      Square        Triangle      any      0..0.5   1..0     0138//      Square        Saw            1       0..1     1..any   0139//      Triangle      Saw            1     0.5..1     0..-1    0140//141//    Other noteworthy morphs between simple shapes:142//                                                            peak     half    zero143//      Start           Halfway       End          reflect    time    height   wait144//      -----           ---------     ---          -------    ----    ------   ----145//      Saw (8va,neg)                Saw (pos)        1       0..1      -1      0146//      Saw (neg)                    Saw (pos)        1       0..1       0      0147//      Triangle                     AlternatingSaw   0       0..1      -1      0148//      AlternatingSaw  Triangle     AlternatingSaw   0       0..1       0      0149//      Square                       AlternatingSaw   0       0..1       1      0150//      Triangle        Triangle     AlternatingSaw   0       0..1    -1..1     0151//      Square                       AlternatingSaw   0       0..1     1..0     0152//      Saw (8va)       Triangle     Saw              1       0..1    -1..1     0153//      Saw (neg)                    Saw (pos)        1       0..1     0..1     0154//      AlternatingSaw               AlternatingSaw   0       0..1     0..any   0155//156//   The last entry is noteworthy because the morph from the halfway point to either157//   endpoint sounds very different. For example, an LFO sweeping back and forth over158//   the whole range will morph between the middle timbre and the AlternatingSaw159//   timbre in two different ways, alternating.160//161//   Entries with "any" for half_height are whole families of morphs, as you can pick162//   any value you want as the endpoint for half_height.163//164//   You can always morph between any two waveforms with the same value of 'reflect'165//   by just sweeping the parameters simultaneously. There will never be artifacts166//   and the result will always be useful, if not necessarily what you want.167//168//   You can vary the sound of two-parameter morphs by ramping them differently,169//   e.g. if the morph goes from t=0..1, then square-to-triangle looks like:170//        peak_time   = lerp(t, 0, 0.5)171//        half_height = lerp(t, 1, 0  )172//   but you can also do things like:173//        peak_time   = lerp(smoothstep(t), 0, 0.5)174//        half_height = cos(PI/2 * t)175//176// How it works:177//178//   hexwave use BLEP to bandlimit discontinuities and BLAMP179//   to bandlimit C1 discontinuities. This is not polyBLEP180//   (polynomial BLEP), it is table-driven BLEP. It is181//   also not minBLEP (minimum-phase BLEP), as that complicates182//   things for little benefit once BLAMP is involved.183//184//   The previous oscillator frequency is remembered, and when185//   the frequency changes, a BLAMP is generated to remove the186//   C1 discontinuity, which reduces artifacts for sweeps/LFO.187//188//   Changes to an oscillator timbre using hexwave_change() actually189//   wait until the oscillator finishes its current cycle. All190//   waveforms with non-zero "zero_wait" settings pass through 0191//   and have 0-slope at the start of a cycle, which means changing192//   the settings is artifact free at that time. (If zero_wait is 0,193//   the code still treats it as passing through 0 with 0-slope; it'll194//   apply the necessary fixups to make it artifact free as if it does195//   transition to 0 with 0-slope vs. the waveform at the end of196//   the cycle, then adds the fixups for a non-0 and non-0 slope197//   at the start of the cycle, which cancels out if zero_wait is 0,198//   and still does the right thing if zero_wait is 0 when the199//   settings are updated.)200//201//   BLEP/BLAMP normally requires overlapping buffers, but this202//   is hidden from the user by generating the waveform to a203//   temporary buffer and saving the overlap regions internally204//   between calls. (It is slightly more complicated; see code.)205//206//   By design all shapes have 0 DC offset; this is one reason207//   hexwave uses zero_wait instead of standard PWM.208//209//   The internals of hexwave could support any arbitrary shape210//   made of line segments, but I chose not to expose this211//   generality in favor of a simple, easy-to-use API.212213#ifndef STB_INCLUDE_STB_HEXWAVE_H214#define STB_INCLUDE_STB_HEXWAVE_H215216#ifndef STB_HEXWAVE_MAX_BLEP_LENGTH217#define STB_HEXWAVE_MAX_BLEP_LENGTH   64 // good enough for anybody218#endif219220#ifdef STB_HEXWAVE_STATIC221#define STB_HEXWAVE_DEF static222#else223#define STB_HEXWAVE_DEF extern224#endif225226typedef struct HexWave HexWave;227228STB_HEXWAVE_DEF void hexwave_init(int width, int oversample, float *user_buffer);229//         width: size of BLEP, from 4..64, larger is slower & more memory but less aliasing230//    oversample: 2+, number of subsample positions, larger uses more memory but less noise231//   user_buffer: optional, if provided the library will perform no allocations.232//                16*width*(oversample+1) bytes, must stay allocated as long as library is used233//                technically it only needs:   8*( width * (oversample  + 1))234//                                           + 8*((width *  oversample) + 1)  bytes235//236// width can be larger than 64 if you define STB_HEXWAVE_MAX_BLEP_LENGTH to a larger value237238STB_HEXWAVE_DEF void hexwave_shutdown(float *user_buffer);239//       user_buffer: pass in same parameter as passed to hexwave_init240241STB_HEXWAVE_DEF void hexwave_create(HexWave *hex, int reflect, float peak_time, float half_height, float zero_wait);242// see docs above for description243//244//   reflect is tested as 0 or non-zero245//   peak_time is clamped to 0..1246//   half_height is not clamped247//   zero_wait is clamped to 0..1248249STB_HEXWAVE_DEF void hexwave_change(HexWave *hex, int reflect, float peak_time, float half_height, float zero_wait);250// see docs251252STB_HEXWAVE_DEF void hexwave_generate_samples(float *output, int num_samples, HexWave *hex, float freq);253//            output: buffer where the library will store generated floating point audio samples254// number_of_samples: the number of audio samples to generate255//               osc: pointer to a Hexwave initialized with 'hexwave_create'256//   oscillator_freq: frequency of the oscillator divided by the sample rate257258// private:259typedef struct260{261   int   reflect;262   float peak_time;263   float zero_wait;264   float half_height;265} HexWaveParameters;266267struct HexWave268{269   float t, prev_dt;270   HexWaveParameters current, pending;271   int have_pending;272   float buffer[STB_HEXWAVE_MAX_BLEP_LENGTH];273}; 274#endif275276#ifdef STB_HEXWAVE_IMPLEMENTATION277278#ifndef STB_HEXWAVE_NO_ALLOCATION279#include <stdlib.h> // malloc,free280#endif281282#include <string.h> // memset,memcpy,memmove283#include <math.h>   // sin,cos,fabs284285#define hexwave_clamp(v,a,b)   ((v) < (a) ? (a) : (v) > (b) ? (b) : (v))286287STB_HEXWAVE_DEF void hexwave_change(HexWave *hex, int reflect, float peak_time, float half_height, float zero_wait)288{289   hex->pending.reflect     = reflect;290   hex->pending.peak_time   = hexwave_clamp(peak_time,0,1);291   hex->pending.half_height = half_height;292   hex->pending.zero_wait   = hexwave_clamp(zero_wait,0,1);293   // put a barrier here to allow changing from a different thread than the generator294   hex->have_pending        = 1;295}296297STB_HEXWAVE_DEF void hexwave_create(HexWave *hex, int reflect, float peak_time, float half_height, float zero_wait)298{299   memset(hex, 0, sizeof(*hex));300   hexwave_change(hex, reflect, peak_time, half_height, zero_wait);301   hex->current = hex->pending;302   hex->have_pending = 0;303   hex->t = 0;304   hex->prev_dt = 0;305}306307static struct308{309   int width;       // width of fixup in samples310   int oversample;  // number of oversampled versions (there's actually one more to allow lerpign)311   float *blep;312   float *blamp;313} hexblep;314315static void hex_add_oversampled_bleplike(float *output, float time_since_transition, float scale, float *data)316{317   float *d1,*d2;318   float lerpweight;319   int i, bw = hexblep.width;320321   int slot = (int) (time_since_transition * hexblep.oversample);322   if (slot >= hexblep.oversample)323      slot = hexblep.oversample-1; // clamp in case the floats overshoot324325   d1 = &data[ slot   *bw];326   d2 = &data[(slot+1)*bw];327328   lerpweight = time_since_transition * hexblep.oversample - slot;329   for (i=0; i < bw; ++i)330      output[i] += scale * (d1[i] + (d2[i]-d1[i])*lerpweight);331}332333static void hex_blep (float *output, float time_since_transition, float scale)334{335   hex_add_oversampled_bleplike(output, time_since_transition, scale, hexblep.blep);336}337338static void hex_blamp(float *output, float time_since_transition, float scale)339{340   hex_add_oversampled_bleplike(output, time_since_transition, scale, hexblep.blamp);341}342343typedef struct344{345   float t,v,s; // time, value, slope346} hexvert;347348// each half of the waveform needs 4 vertices to represent 3 line349// segments, plus 1 more for wraparound350static void hexwave_generate_linesegs(hexvert vert[9], HexWave *hex, float dt)351{352   int j;353   float min_len = dt / 256.0f;354355   vert[0].t = 0;356   vert[0].v = 0;357   vert[1].t = hex->current.zero_wait*0.5f;358   vert[1].v = 0;359   vert[2].t = 0.5f*hex->current.peak_time + vert[1].t*(1-hex->current.peak_time);360   vert[2].v = 1;361   vert[3].t = 0.5f;362   vert[3].v = hex->current.half_height;363364   if (hex->current.reflect) {365      for (j=4; j <= 7; ++j) {366         vert[j].t = 1 -  vert[7-j].t;367         vert[j].v =    - vert[7-j].v;368      }369   } else {370      for (j=4; j <= 7; ++j) {371         vert[j].t =  0.5f +  vert[j-4].t;372         vert[j].v =        - vert[j-4].v;373      }374   }375   vert[8].t = 1;376   vert[8].v = 0;377378   for (j=0; j < 8; ++j) {379      if (vert[j+1].t <= vert[j].t + min_len) {380          // if change takes place over less than a fraction of a sample treat as discontinuity381          //382          // otherwise the slope computation can blow up to arbitrarily large and we383          // try to generate a huge BLAMP and the result is wrong.384          // 385          // why does this happen if the math is right? i believe if done perfectly,386          // the two BLAMPs on either side of the slope would cancel out, but our387          // BLAMPs have only limited sub-sample precision and limited integration388          // accuracy. or maybe it's just the math blowing up w/ floating point precision389          // limits as we try to make x * (1/x) cancel out390          //391          // min_len verified artifact-free even near nyquist with only oversample=4392         vert[j+1].t = vert[j].t;393      }394   }395396   if (vert[8].t != 1.0f) {397      // if the above fixup moved the endpoint away from 1.0, move it back,398      // along with any other vertices that got moved to the same time399      float t = vert[8].t;400      for (j=5; j <= 8; ++j)401         if (vert[j].t == t)402            vert[j].t = 1.0f;403   }404405   // compute the exact slopes from the final fixed-up positions406   for (j=0; j < 8; ++j)407      if (vert[j+1].t == vert[j].t)408         vert[j].s = 0;409      else410         vert[j].s = (vert[j+1].v - vert[j].v) / (vert[j+1].t - vert[j].t);411412   // wraparound at end413   vert[8].t = 1;414   vert[8].v = vert[0].v;415   vert[8].s = vert[0].s;416}417418STB_HEXWAVE_DEF void hexwave_generate_samples(float *output, int num_samples, HexWave *hex, float freq)419{420   hexvert vert[9];421   int pass,i,j;422   float t = hex->t;423   float temp_output[2*STB_HEXWAVE_MAX_BLEP_LENGTH];424   int buffered_length = sizeof(float)*hexblep.width;425   float dt = (float) fabs(freq);426   float recip_dt = (dt == 0.0f) ? 0.0f : 1.0f / dt;427428   int halfw = hexblep.width/2;429   // all sample times are biased by halfw to leave room for BLEP/BLAMP to go back in time430431   if (num_samples <= 0)432      return;433434   // convert parameters to times and slopes435   hexwave_generate_linesegs(vert, hex, dt);436437   if (hex->prev_dt != dt) {438      // if frequency changes, add a fixup at the derivative discontinuity starting at now439      float slope;440      for (j=1; j < 6; ++j)441         if (t < vert[j].t)442            break;443      slope = vert[j].s;444      if (slope != 0)445         hex_blamp(output, 0, (dt - hex->prev_dt)*slope);446      hex->prev_dt = dt;447   }448449   // copy the buffered data from last call and clear the rest of the output array450   memset(output, 0, sizeof(float)*num_samples);451   memset(temp_output, 0, 2*hexblep.width*sizeof(float));452453   if (num_samples >= hexblep.width) {454      memcpy(output, hex->buffer, buffered_length);455   } else {456      // if the output is shorter than hexblep.width, we do all synthesis to temp_output457      memcpy(temp_output, hex->buffer, buffered_length);458   }459460   for (pass=0; pass < 2; ++pass) {461      int i0,i1;462      float *out;463464      // we want to simulate having one buffer that is num_output + hexblep.width465      // samples long, without putting that requirement on the user, and without466      // allocating a temp buffer that's as long as the whole thing. so we use two467      // overlapping buffers, one the user's buffer and one a fixed-length temp468      // buffer.469470      if (pass == 0) {471         if (num_samples < hexblep.width)472            continue;473         // run as far as we can without overwriting the end of the user's buffer 474         out = output;475         i0 = 0;476         i1 = num_samples - hexblep.width;477      } else {478         // generate the rest into a temp buffer479         out = temp_output;480         i0 = 0;481         if (num_samples >= hexblep.width)482            i1 = hexblep.width;483         else484            i1 = num_samples;485      }486487      // determine current segment488      for (j=0; j < 8; ++j)489         if (t < vert[j+1].t)                                  490            break;491492      i = i0;493      for(;;) {494         while (t < vert[j+1].t) {495            if (i == i1)496               goto done;497            out[i+halfw] += vert[j].v + vert[j].s*(t - vert[j].t);498            t += dt;499            ++i;500         }501         // transition from lineseg starting at j to lineseg starting at j+1502503         if (vert[j].t == vert[j+1].t)504            hex_blep(out+i, recip_dt*(t-vert[j+1].t), (vert[j+1].v - vert[j].v));505         hex_blamp(out+i, recip_dt*(t-vert[j+1].t), dt*(vert[j+1].s - vert[j].s));506         ++j;507508         if (j == 8) {509            // change to different waveform if there's a change pending510            j = 0;511            t -= 1.0; // t was >= 1.f if j==8512            if (hex->have_pending) {513               float prev_s0 = vert[j].s;514               float prev_v0 = vert[j].v;515               hex->current = hex->pending;516               hex->have_pending = 0;517               hexwave_generate_linesegs(vert, hex, dt);518               // the following never occurs with this oscillator, but it makes519               // the code work in more general cases520               if (vert[j].v != prev_v0)521                  hex_blep (out+i, recip_dt*t,    (vert[j].v - prev_v0));522               if (vert[j].s != prev_s0)523                  hex_blamp(out+i, recip_dt*t, dt*(vert[j].s - prev_s0));524            }525         }526      }527     done:528      ;529   }530531   // at this point, we've written output[] and temp_output[]532   if (num_samples >= hexblep.width) {533      // the first half of temp[] overlaps the end of output, the second half will be the new start overlap534      for (i=0; i < hexblep.width; ++i)535         output[num_samples-hexblep.width + i] += temp_output[i];536      memcpy(hex->buffer, temp_output+hexblep.width, buffered_length);537   } else {538      for (i=0; i < num_samples; ++i)539         output[i] = temp_output[i];540      memcpy(hex->buffer, temp_output+num_samples, buffered_length);541   }542543   hex->t = t;544}545546STB_HEXWAVE_DEF void hexwave_shutdown(float *user_buffer)547{548   #ifndef STB_HEXWAVE_NO_ALLOCATION549   if (user_buffer != 0) {550      free(hexblep.blep);551      free(hexblep.blamp);552   }553   #endif554}555556// buffer should be NULL or must be 4*(width*(oversample+1)*2 + 557STB_HEXWAVE_DEF void hexwave_init(int width, int oversample, float *user_buffer)558{559   int halfwidth = width/2;560   int half = halfwidth*oversample;561   int blep_buffer_count = width*(oversample+1);562   int n = 2*half+1;563#ifdef STB_HEXWAVE_NO_ALLOCATION564   float *buffers = user_buffer;565#else566   float *buffers = user_buffer ? user_buffer : (float *) malloc(sizeof(float) * n * 2);567#endif568   float *step    = buffers+0*n;569   float *ramp    = buffers+1*n;570   float *blep_buffer, *blamp_buffer;571   double integrate_impulse=0, integrate_step=0;572   int i,j;573574   if (width > STB_HEXWAVE_MAX_BLEP_LENGTH)575      width = STB_HEXWAVE_MAX_BLEP_LENGTH;576577   if (user_buffer == 0) {578      #ifndef STB_HEXWAVE_NO_ALLOCATION579      blep_buffer  = (float *) malloc(sizeof(float)*blep_buffer_count);580      blamp_buffer = (float *) malloc(sizeof(float)*blep_buffer_count);581      #endif582   } else {583      blep_buffer  = ramp+n;584      blamp_buffer = blep_buffer + blep_buffer_count;585   }586587   // compute BLEP and BLAMP by integerating windowed sinc588   for (i=0; i < n; ++i) {589      for (j=0; j < 16; ++j) {590         float sinc_t = 3.141592f* (i-half) / oversample;591         float sinc   = (i==half) ? 1.0f : (float) sin(sinc_t) / (sinc_t);592         float wt     = 2.0f*3.1415926f * i / (n-1);593         float window = (float) (0.355768 - 0.487396*cos(wt) + 0.144232*cos(2*wt) - 0.012604*cos(3*wt)); // Nuttall594         double value       =         window * sinc;595         integrate_impulse +=         value/16;596         integrate_step    +=         integrate_impulse/16;597      }598      step[i]            = (float) integrate_impulse;599      ramp[i]            = (float) integrate_step;600   }601602   // renormalize603   for (i=0; i < n; ++i) {604      step[i] = step[i] * (float) (1.0       / step[n-1]); // step needs to reach to 1.0605      ramp[i] = ramp[i] * (float) (halfwidth / ramp[n-1]); // ramp needs to become a slope of 1.0 after oversampling606   }607608   // deinterleave to allow efficient interpolation e.g. w/SIMD609   for (j=0; j <= oversample; ++j) {610      for (i=0; i < width; ++i) {611         blep_buffer [j*width+i] = step[j+i*oversample];612         blamp_buffer[j*width+i] = ramp[j+i*oversample];613      }614   }615616   // subtract out the naive waveform; note we can't do this to the raw data617   // above, because we want the discontinuity to be in a different locations618   // for j=0 and j=oversample (which exists to provide something to interpolate against)619   for (j=0; j <= oversample; ++j) {620      // subtract step621      for (i=halfwidth; i < width; ++i)622         blep_buffer [j*width+i] -= 1.0f;623      // subtract ramp624      for (i=halfwidth; i < width; ++i)625         blamp_buffer[j*width+i] -= (j+i*oversample-half)*(1.0f/oversample);626   }627628   hexblep.blep  = blep_buffer;629   hexblep.blamp = blamp_buffer;630   hexblep.width = width;631   hexblep.oversample = oversample;632633   #ifndef STB_HEXWAVE_NO_ALLOCATION634   if (user_buffer == 0)635      free(buffers);636   #endif637}638#endif // STB_HEXWAVE_IMPLEMENTATION639640/*641------------------------------------------------------------------------------642This software is available under 2 licenses -- choose whichever you prefer.643------------------------------------------------------------------------------644ALTERNATIVE A - MIT License645Copyright (c) 2017 Sean Barrett646Permission is hereby granted, free of charge, to any person obtaining a copy of647this software and associated documentation files (the "Software"), to deal in648the Software without restriction, including without limitation the rights to649use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies650of the Software, and to permit persons to whom the Software is furnished to do651so, subject to the following conditions:652The above copyright notice and this permission notice shall be included in all653copies or substantial portions of the Software.654THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR655IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,656FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE657AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER658LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,659OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE660SOFTWARE.661------------------------------------------------------------------------------662ALTERNATIVE B - Public Domain (www.unlicense.org)663This is free and unencumbered software released into the public domain.664Anyone is free to copy, modify, publish, use, compile, sell, or distribute this665software, either in source code form or as a compiled binary, for any purpose,666commercial or non-commercial, and by any means.667In jurisdictions that recognize copyright laws, the author or authors of this668software dedicate any and all copyright interest in the software to the public669domain. We make this dedication for the benefit of the public at large and to670the detriment of our heirs and successors. We intend this dedication to be an671overt act of relinquishment in perpetuity of all present and future rights to672this software under copyright law.673THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR674IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,675FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE676AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN677ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION678WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.679------------------------------------------------------------------------------680*/