[med-svn] [Git][med-team/edflib][upstream] New upstream version 1.18

Andreas Tille gitlab at salsa.debian.org
Sat Jul 4 08:50:13 BST 2020



Andreas Tille pushed to branch upstream at Debian Med / edflib


Commits:
7e143c3c by Andreas Tille at 2020-07-04T09:01:54+02:00
New upstream version 1.18
- - - - -


9 changed files:

- + LICENSE
- Makefile
- README.md
- edflib.c
- edflib.h
- sine_generator.c
- sweep_generator.c
- test_edflib.c
- test_generator.c


Changes:

=====================================
LICENSE
=====================================
@@ -0,0 +1,29 @@
+BSD 3-Clause License
+
+Copyright (c) 2009 - 2020 Teunis van Beelen
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+  contributors may be used to endorse or promote products derived from
+  this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


=====================================
Makefile
=====================================
@@ -1,5 +1,5 @@
 CC = gcc
-CFLAGS = -O2 -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE
+CFLAGS = -O3 -Wall -Wextra -Wshadow -Wformat-nonliteral -Wformat-security -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE
 LDLIBS = -lm
 
 programs = sine_generator sweep_generator test_edflib test_generator


=====================================
README.md
=====================================
@@ -83,7 +83,7 @@ The description/name of an EDF+ annotation on the other hand, is encoded in UTF-
 
 ## License
 
-Copyright (c) 2009 - 2019 Teunis van Beelen
+Copyright (c) 2009 - 2020 Teunis van Beelen
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without


=====================================
edflib.c
=====================================
@@ -1,7 +1,7 @@
 /*
 *****************************************************************************
 *
-* Copyright (c) 2009 - 2019 Teunis van Beelen
+* Copyright (c) 2009 - 2020 Teunis van Beelen
 * All rights reserved.
 *
 * Email: teuniz at protonmail.com
@@ -42,11 +42,11 @@
 #include "edflib.h"
 
 
-#define EDFLIB_VERSION 116
-#define EDFLIB_MAXFILES 64
+#define EDFLIB_VERSION  (118)
+#define EDFLIB_MAXFILES  (64)
 
 
-#if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__)
+#if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__) || defined(__HAIKU__)
 
 #define fopeno fopen
 
@@ -79,15 +79,15 @@
 
 
 /* max size of annotationtext */
-#define EDFLIB_WRITE_MAX_ANNOTATION_LEN 40
+#define EDFLIB_WRITE_MAX_ANNOTATION_LEN  (40)
 
 /* bytes in datarecord for EDF annotations, must be an integer multiple of three and two */
-#define EDFLIB_ANNOTATION_BYTES 114
+#define EDFLIB_ANNOTATION_BYTES  (114)
 
 /* for writing only */
-#define EDFLIB_MAX_ANNOTATION_CHANNELS 64
+#define EDFLIB_MAX_ANNOTATION_CHANNELS  (64)
 
-#define EDFLIB_ANNOT_MEMBLOCKSZ 1000
+#define EDFLIB_ANNOT_MEMBLOCKSZ  (1000)
 
 
 struct edfparamblock{
@@ -249,7 +249,7 @@ int edflib_get_handle(int file_number)
 }
 
 
-int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int read_annotations)
+int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int read_annotations_mode)
 {
   int i, j,
       channel,
@@ -260,14 +260,14 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
   struct edfhdrblock *hdr;
 
 
-  if(read_annotations<0)
+  if(read_annotations_mode<0)
   {
     edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE;
 
     return -1;
   }
 
-  if(read_annotations>2)
+  if(read_annotations_mode>2)
   {
     edfhdr->filetype = EDFLIB_INVALID_READ_ANNOTS_VALUE;
 
@@ -408,26 +408,25 @@ int edfopen_file_readonly(const char *path, struct edf_hdr_struct *edfhdr, int r
     edflib_strlcpy(edfhdr->equipment, hdr->plus_equipment, 81);
     edflib_strlcpy(edfhdr->recording_additional, hdr->plus_recording_additional, 81);
 
-    if((read_annotations==EDFLIB_READ_ANNOTATIONS)||(read_annotations==EDFLIB_READ_ALL_ANNOTATIONS))
+    if(edflib_get_annotations(hdr, edfhdr->handle, read_annotations_mode))
     {
-      if(edflib_get_annotations(hdr, edfhdr->handle, read_annotations))
-      {
-        edfhdr->filetype = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
+      edfhdr->filetype = EDFLIB_FILE_CONTAINS_FORMAT_ERRORS;
 
-        fclose(file);
+      fclose(file);
 
-        free(hdr->edfparam);
-        hdr->edfparam = NULL;
-        free(hdr);
-        hdr = NULL;
-        hdrlist[edfhdr->handle] = NULL;
-        free(annotationslist[edfhdr->handle]);
-        annotationslist[edfhdr->handle] = NULL;
+      free(hdr->edfparam);
+      hdr->edfparam = NULL;
+      free(hdr);
+      hdr = NULL;
+      hdrlist[edfhdr->handle] = NULL;
+      free(annotationslist[edfhdr->handle]);
+      annotationslist[edfhdr->handle] = NULL;
 
-        return -1;
-      }
+      return -1;
     }
 
+    edfhdr->starttime_subsecond = hdr->starttime_offset;
+
     edfhdr->annotations_in_file = hdr->annots_in_file;
   }
 
@@ -528,13 +527,13 @@ int edfclose_file(int handle)
       {
         annot2 = write_annotationslist[handle] + k;
 
-        p = edflib_fprint_ll_number_nonlocalized(hdr->file_hdl, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1);
+        p = edflib_fprint_ll_number_nonlocalized(hdr->file_hdl, (hdr->datarecords * hdr->long_data_record_duration + hdr->starttime_offset) / EDFLIB_TIME_DIMENSION, 0, 1);
 
-        if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+        if((hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION) || (hdr->starttime_offset))
         {
           fputc('.', hdr->file_hdl);
           p++;
-          p += edflib_fprint_ll_number_nonlocalized(hdr->file_hdl, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0);
+          p += edflib_fprint_ll_number_nonlocalized(hdr->file_hdl, (hdr->datarecords * hdr->long_data_record_duration + hdr->starttime_offset) % EDFLIB_TIME_DIMENSION, 7, 0);
         }
         fputc(20, hdr->file_hdl);
         fputc(20, hdr->file_hdl);
@@ -586,6 +585,8 @@ int edfclose_file(int handle)
     {
       annot2 = write_annotationslist[handle] + k;
 
+      annot2->onset += hdr->starttime_offset / 1000LL;
+
       p = 0;
 
       if(j==0)  // first annotation signal
@@ -595,12 +596,12 @@ int edfclose_file(int handle)
           break;
         }
 
-        p += edflib_snprint_ll_number_nonlocalized(str, (datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1, EDFLIB_ANNOTATION_BYTES * 2);
+        p += edflib_snprint_ll_number_nonlocalized(str, (datarecords * hdr->long_data_record_duration + hdr->starttime_offset) / EDFLIB_TIME_DIMENSION, 0, 1, EDFLIB_ANNOTATION_BYTES * 2);
 
-        if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+        if((hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION) || (hdr->starttime_offset))
         {
           str[p++] = '.';
-          n = edflib_snprint_ll_number_nonlocalized(str + p, (datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
+          n = edflib_snprint_ll_number_nonlocalized(str + p, (datarecords * hdr->long_data_record_duration + hdr->starttime_offset) % EDFLIB_TIME_DIMENSION, 7, 0, (EDFLIB_ANNOTATION_BYTES * 2) - p);
           p += n;
         }
         str[p++] = 20;
@@ -2866,7 +2867,7 @@ int edflib_version(void)
 }
 
 
-static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_annotations)
+static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_annotations_mode)
 {
   int i, j, k, p, r=0, n,
       edfsignals,
@@ -3055,7 +3056,7 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
               }
               else
               {
-                if(time_tmp>=EDFLIB_TIME_DIMENSION)
+                if((time_tmp>=EDFLIB_TIME_DIMENSION) || (time_tmp<0LL))
                 {
                   error = 2;
                   goto END;
@@ -3063,6 +3064,11 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
                 else
                 {
                   edfhdr->starttime_offset = time_tmp;
+                  if(read_annotations_mode==EDFLIB_DO_NOT_READ_ANNOTATIONS)
+                  {
+                    error = 0;
+                    goto END_OUT;
+                  }
                 }
               }
               elapsedtime = time_tmp;
@@ -3158,9 +3164,11 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
 
                 new_annotation->onset = edflib_get_long_time(time_in_txt);
 
+                new_annotation->onset -= edfhdr->starttime_offset;
+
                 edfhdr->annots_in_file++;
 
-                if(read_annotations==EDFLIB_READ_ANNOTATIONS)
+                if(read_annotations_mode==EDFLIB_READ_ANNOTATIONS)
                 {
                   if(!(strncmp(new_annotation->annotation, "Recording ends", 14)))
                   {
@@ -3238,6 +3246,8 @@ static int edflib_get_annotations(struct edfhdrblock *edfhdr, int hdl, int read_
     }
   }
 
+ END_OUT:
+
   free(cnv_buf);
   free(scratchpad);
   free(time_in_txt);
@@ -3937,6 +3947,44 @@ int edf_set_micro_datarecord_duration(int handle, int duration)
 }
 
 
+int edf_set_subsecond_starttime(int handle, int subsecond)
+{
+  if(handle<0)
+  {
+    return -1;
+  }
+
+  if(handle>=EDFLIB_MAXFILES)
+  {
+    return -1;
+  }
+
+  if(hdrlist[handle]==NULL)
+  {
+    return -1;
+  }
+
+  if(!(hdrlist[handle]->writemode))
+  {
+    return -1;
+  }
+
+  if(hdrlist[handle]->datarecords)
+  {
+    return -1;
+  }
+
+  if((subsecond < 0) || (subsecond > 9999999))
+  {
+    return -1;
+  }
+
+  hdrlist[handle]->starttime_offset = (long long)subsecond;
+
+  return 0;
+}
+
+
 int edfwrite_digital_short_samples(int handle, short *buf)
 {
   int  i,
@@ -7263,11 +7311,11 @@ static int edflib_write_tal(struct edfhdrblock *hdr, FILE *file)
 
   char str[EDFLIB_ANNOTATION_BYTES * (EDFLIB_MAX_ANNOTATION_CHANNELS + 1)];
 
-  p = edflib_snprint_ll_number_nonlocalized(str, (hdr->datarecords * hdr->long_data_record_duration) / EDFLIB_TIME_DIMENSION, 0, 1, EDFLIB_ANNOTATION_BYTES * (EDFLIB_MAX_ANNOTATION_CHANNELS + 1));
-  if(hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION)
+  p = edflib_snprint_ll_number_nonlocalized(str, (hdr->datarecords * hdr->long_data_record_duration + hdr->starttime_offset) / EDFLIB_TIME_DIMENSION, 0, 1, EDFLIB_ANNOTATION_BYTES * (EDFLIB_MAX_ANNOTATION_CHANNELS + 1));
+  if((hdr->long_data_record_duration % EDFLIB_TIME_DIMENSION) || (hdr->starttime_offset))
   {
     str[p++] = '.';
-    p += edflib_snprint_ll_number_nonlocalized(str + p, (hdr->datarecords * hdr->long_data_record_duration) % EDFLIB_TIME_DIMENSION, 7, 0, (EDFLIB_ANNOTATION_BYTES * (EDFLIB_MAX_ANNOTATION_CHANNELS + 1)) - p);
+    p += edflib_snprint_ll_number_nonlocalized(str + p, (hdr->datarecords * hdr->long_data_record_duration + hdr->starttime_offset) % EDFLIB_TIME_DIMENSION, 7, 0, (EDFLIB_ANNOTATION_BYTES * (EDFLIB_MAX_ANNOTATION_CHANNELS + 1)) - p);
   }
   str[p++] = 20;
   str[p++] = 20;


=====================================
edflib.h
=====================================
@@ -1,7 +1,7 @@
 /*
 *****************************************************************************
 *
-* Copyright (c) 2009 - 2019 Teunis van Beelen
+* Copyright (c) 2009 - 2020 Teunis van Beelen
 * All rights reserved.
 *
 * Email: teuniz at protonmail.com
@@ -48,51 +48,51 @@
 
 
 
-#define EDFLIB_TIME_DIMENSION (10000000LL)
-#define EDFLIB_MAXSIGNALS 640
-#define EDFLIB_MAX_ANNOTATION_LEN 512
+#define EDFLIB_TIME_DIMENSION     (10000000LL)
+#define EDFLIB_MAXSIGNALS                (640)
+#define EDFLIB_MAX_ANNOTATION_LEN        (512)
 
-#define EDFSEEK_SET 0
-#define EDFSEEK_CUR 1
-#define EDFSEEK_END 2
+#define EDFSEEK_SET  (0)
+#define EDFSEEK_CUR  (1)
+#define EDFSEEK_END  (2)
 
 
 
 /* the following defines are used in the member "filetype" of the edf_hdr_struct */
 /* and as return value for the function edfopen_file_readonly() */
-#define EDFLIB_FILETYPE_EDF                  0
-#define EDFLIB_FILETYPE_EDFPLUS              1
-#define EDFLIB_FILETYPE_BDF                  2
-#define EDFLIB_FILETYPE_BDFPLUS              3
-#define EDFLIB_MALLOC_ERROR                 -1
-#define EDFLIB_NO_SUCH_FILE_OR_DIRECTORY    -2
+#define EDFLIB_FILETYPE_EDF                  (0)
+#define EDFLIB_FILETYPE_EDFPLUS              (1)
+#define EDFLIB_FILETYPE_BDF                  (2)
+#define EDFLIB_FILETYPE_BDFPLUS              (3)
+#define EDFLIB_MALLOC_ERROR                 (-1)
+#define EDFLIB_NO_SUCH_FILE_OR_DIRECTORY    (-2)
 
 /* when this error occurs, try to open the file with EDFbrowser,
    it will give you full details about the cause of the error. */
 #define EDFLIB_FILE_CONTAINS_FORMAT_ERRORS  -3
 
-#define EDFLIB_MAXFILES_REACHED             -4
-#define EDFLIB_FILE_READ_ERROR              -5
-#define EDFLIB_FILE_ALREADY_OPENED          -6
-#define EDFLIB_FILETYPE_ERROR               -7
-#define EDFLIB_FILE_WRITE_ERROR             -8
-#define EDFLIB_NUMBER_OF_SIGNALS_INVALID    -9
-#define EDFLIB_FILE_IS_DISCONTINUOUS       -10
-#define EDFLIB_INVALID_READ_ANNOTS_VALUE   -11
+#define EDFLIB_MAXFILES_REACHED             (-4)
+#define EDFLIB_FILE_READ_ERROR              (-5)
+#define EDFLIB_FILE_ALREADY_OPENED          (-6)
+#define EDFLIB_FILETYPE_ERROR               (-7)
+#define EDFLIB_FILE_WRITE_ERROR             (-8)
+#define EDFLIB_NUMBER_OF_SIGNALS_INVALID    (-9)
+#define EDFLIB_FILE_IS_DISCONTINUOUS       (-10)
+#define EDFLIB_INVALID_READ_ANNOTS_VALUE   (-11)
 
 /* values for annotations */
-#define EDFLIB_DO_NOT_READ_ANNOTATIONS 0
-#define EDFLIB_READ_ANNOTATIONS        1
-#define EDFLIB_READ_ALL_ANNOTATIONS    2
+#define EDFLIB_DO_NOT_READ_ANNOTATIONS  (0)
+#define EDFLIB_READ_ANNOTATIONS         (1)
+#define EDFLIB_READ_ALL_ANNOTATIONS     (2)
 
 /* the following defines are possible errors returned by the first sample write action */
-#define EDFLIB_NO_SIGNALS                  -20
-#define EDFLIB_TOO_MANY_SIGNALS            -21
-#define EDFLIB_NO_SAMPLES_IN_RECORD        -22
-#define EDFLIB_DIGMIN_IS_DIGMAX            -23
-#define EDFLIB_DIGMAX_LOWER_THAN_DIGMIN    -24
-#define EDFLIB_PHYSMIN_IS_PHYSMAX          -25
-#define EDFLIB_DATARECORD_SIZE_TOO_BIG     -26
+#define EDFLIB_NO_SIGNALS                  (-20)
+#define EDFLIB_TOO_MANY_SIGNALS            (-21)
+#define EDFLIB_NO_SAMPLES_IN_RECORD        (-22)
+#define EDFLIB_DIGMIN_IS_DIGMAX            (-23)
+#define EDFLIB_DIGMAX_LOWER_THAN_DIGMIN    (-24)
+#define EDFLIB_PHYSMIN_IS_PHYSMAX          (-25)
+#define EDFLIB_DATARECORD_SIZE_TOO_BIG     (-26)
 
 
 
@@ -133,8 +133,10 @@ extern "C" {
  * This is not a concern anymore so the maximum datarecord size now is limited to 10MByte for EDF(+) and 15MByte for BDF(+). This helps to accommodate for higher samplingrates
  * used by modern Analog to Digital Converters.
  *
- * EDF header character encoding: The EDF specification says that only ASCII characters are allowed.
- * EDFlib will automatically convert characters with accents, umlauts, tilde, etc. to their "normal" equivalent without the accent/umlaut/tilde/etc.
+ * EDF header character encoding: The EDF specification says that only (printable) ASCII characters are allowed.
+ * When writing the header info, EDFlib will assume you are using Latin1 encoding and it will automatically convert
+ * characters with accents, umlauts, tilde, etc. to their "normal" equivalent without the accent/umlaut/tilde/etc.
+ * in order to create a valid EDF file.
  *
  * The description/name of an EDF+ annotation on the other hand, is encoded in UTF-8.
  *
@@ -156,7 +158,7 @@ struct edf_param_struct{         /* this structure contains all the relevant EDF
 
 
 struct edf_annotation_struct{                           /* this structure is used for annotations */
-        long long onset;                                /* onset time of the event, expressed in units of 100 nanoSeconds and relative to the starttime in the header */
+        long long onset;                                /* onset time of the event, expressed in units of 100 nanoSeconds and relative to the start of the file */
         char duration[16];                              /* duration time, this is a null-terminated ASCII text-string */
         char annotation[EDFLIB_MAX_ANNOTATION_LEN + 1]; /* description of the event in UTF-8, this is a null terminated string */
        };
@@ -419,7 +421,7 @@ int edf_set_physical_dimension(int handle, int edfsignal, const char *phys_dim);
 /* Sets the physical dimension (unit) of signal edfsignal. ("uV", "BPM", "mA", "Degr.", etc.) */
 /* phys_dim is a pointer to a NULL-terminated ASCII-string containing the physical dimension of the signal edfsignal */
 /* Returns 0 on success, otherwise -1 */
-/* This function is recommanded for every signal when you want to write a file */
+/* This function is recommended for every signal when you want to write a file */
 /* and can be called only after opening a file in writemode and before the first sample write action */
 
 
@@ -609,7 +611,7 @@ int edf_blockwrite_digital_samples(int handle, int *buf);
 int edfwrite_annotation_utf8(int handle, long long onset, long long duration, const char *description);
 
 /* writes an annotation/event to the file */
-/* onset is relative to the starttime and startdate of the file */
+/* onset is relative to the start of the file */
 /* onset and duration are in units of 100 microSeconds!     resolution is 0.0001 second! */
 /* for example: 34.071 seconds must be written as 340710 */
 /* if duration is unknown or not applicable: set a negative number (-1) */
@@ -621,7 +623,7 @@ int edfwrite_annotation_utf8(int handle, long long onset, long long duration, co
 int edfwrite_annotation_latin1(int handle, long long onset, long long duration, const char *description);
 
 /* writes an annotation/event to the file */
-/* onset is relative to the starttime and startdate of the file */
+/* onset is relative to the start of the file */
 /* onset and duration are in units of 100 microSeconds!     resolution is 0.0001 second! */
 /* for example: 34.071 seconds must be written as 340710 */
 /* if duration is unknown or not applicable: set a negative number (-1) */
@@ -676,6 +678,16 @@ int edf_set_number_of_annotation_signals(int handle, int annot_signals);
 /* Returns 0 on success, otherwise -1 */
 
 
+int edf_set_subsecond_starttime(int handle, int subsecond);
+/* Sets the subsecond starttime expressed in units of 100 nanoSeconds */
+/* Valid range is 0 to 9999999 inclusive. Default is 0 */
+/* This function is optional and can be called only after opening a file in writemode */
+/* and before the first sample write action */
+/* Returns 0 on success, otherwise -1 */
+/* It is strongly recommended to use a maximum resolution of no more than 100 micro-Seconds. */
+/* e.g. use 1234000  to set a starttime offset of 0.1234 seconds (instead of 1234567) */
+/* in other words, leave the last 3 digits at zero */
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif


=====================================
sine_generator.c
=====================================
@@ -39,7 +39,11 @@
 #include "edflib.h"
 
 
-#define SMP_FREQ 2048
+#define SMP_FREQ  (2048)
+
+#ifndef M_PI
+#define M_PI (3.14159265358979323846264338327)
+#endif
 
 
 


=====================================
sweep_generator.c
=====================================
@@ -40,6 +40,11 @@
 #include "edflib.h"
 
 
+#ifndef M_PI
+#define M_PI (3.14159265358979323846264338327)
+#endif
+
+#define SMP_FREQ   (8192)
 
 
 // Uncomment the next line to create a BSF+ file instead of EDF+:
@@ -56,11 +61,10 @@ int main(void)
   int i, j,
       hdl,
       chns=1,
-      smp_freq=8192,
       fileduration=300,
       linear=0;
 
-  double buf[smp_freq],
+  double buf[SMP_FREQ],
          q,
          sine_1,
          startfreq=10.0,
@@ -74,12 +78,6 @@ int main(void)
   char str[256];
 
 
-#if defined(__APPLE__) || defined(__MACH__) || defined(__APPLE_CC__)
-#define expo __exp10
-#else
-#define expo exp10
-#endif
-
 
 #ifdef BDF_FORMAT
   hdl = edfopen_file_writeonly("freq_sweep.bdf", EDFLIB_FILETYPE_BDFPLUS, chns);
@@ -96,7 +94,7 @@ int main(void)
 
   for(i=0; i<chns; i++)
   {
-    if(edf_set_samplefrequency(hdl, i, smp_freq))
+    if(edf_set_samplefrequency(hdl, i, SMP_FREQ))
     {
       printf("error: edf_set_samplefrequency()\n");
 
@@ -207,7 +205,7 @@ int main(void)
 
   sampleswritten = 0;
 
-  samples = fileduration * (long long)smp_freq;
+  samples = fileduration * (long long)SMP_FREQ;
 
   freqspan = stopfreq - startfreq;
 
@@ -217,16 +215,16 @@ int main(void)
   }
   else
   {
-    // freq = expo((((double)sampleswritten / (double)samples)) * log10(stopfreq));
-    freq = expo(((((startfreq / stopfreq) * ((stopfreq / freqspan) * samples)) + sampleswritten) / ((stopfreq / freqspan) * samples)) * log10(stopfreq));
+    // freq = pow(10, (((double)sampleswritten / (double)samples)) * log10(stopfreq));
+    freq = pow(10, ((((startfreq / stopfreq) * ((stopfreq / freqspan) * samples)) + sampleswritten) / ((stopfreq / freqspan) * samples)) * log10(stopfreq));
   }
 
   for(j=0; j<fileduration; j++)
   {
-    for(i=0; i<smp_freq; i++)
+    for(i=0; i<SMP_FREQ; i++)
     {
       q = M_PI * 2.0;
-      q /= (smp_freq / freq);
+      q /= (SMP_FREQ / freq);
       sine_1 += q;
       q = sin(sine_1);
       q *= 200.0;
@@ -237,8 +235,8 @@ int main(void)
       }
       else
       {
-        // freq = expo((((double)sampleswritten / (double)samples)) * log10(stopfreq));
-        freq = expo(((((startfreq / stopfreq) * ((stopfreq / freqspan) * samples)) + sampleswritten) / ((stopfreq / freqspan) * samples)) * log10(stopfreq));
+        // freq = pow(10, (((double)sampleswritten / (double)samples)) * log10(stopfreq));
+        freq = pow(10, ((((startfreq / stopfreq) * ((stopfreq / freqspan) * samples)) + sampleswritten) / ((stopfreq / freqspan) * samples)) * log10(stopfreq));
       }
       sampleswritten++;
     }


=====================================
test_edflib.c
=====================================
@@ -39,7 +39,7 @@
 
 
 
-
+#define SAMPLES_READ   (200)
 
 
 int main(int argc, char *argv[])
@@ -114,7 +114,11 @@ int main(int argc, char *argv[])
   printf("file duration: %lli seconds\n", hdr.file_duration / EDFLIB_TIME_DIMENSION);
 #endif
   printf("startdate: %i-%i-%i\n", hdr.startdate_day, hdr.startdate_month, hdr.startdate_year);
-  printf("starttime: %i:%02i:%02i\n", hdr.starttime_hour, hdr.starttime_minute, hdr.starttime_second);
+#ifdef WIN32
+  printf("starttime: %i:%02i:%02i.%07I64d\n", hdr.starttime_hour, hdr.starttime_minute, hdr.starttime_second, hdr.starttime_subsecond);
+#else
+  printf("starttime: %i:%02i:%02i.%07lli\n", hdr.starttime_hour, hdr.starttime_minute, hdr.starttime_second, hdr.starttime_subsecond);
+#endif
   printf("patient: %s\n", hdr.patient);
   printf("recording: %s\n", hdr.recording);
   printf("patientcode: %s\n", hdr.patientcode);
@@ -173,17 +177,16 @@ int main(int argc, char *argv[])
             annot.duration,
             annot.annotation);
 #else
-      printf("annotation: onset is %lli    duration is %s    description is %s\n",
+      printf("annotation: onset is %lli.%07lli sec    duration is %s    description is \"%s\"\n",
             annot.onset / EDFLIB_TIME_DIMENSION,
+            annot.onset % EDFLIB_TIME_DIMENSION,
             annot.duration,
             annot.annotation);
 #endif
     }
   }
 
-  n = 200; /* read n samples from the file */
-
-  buf = (double *)malloc(sizeof(double[n]));
+  buf = (double *)malloc(sizeof(double[SAMPLES_READ]));
   if(buf==NULL)
   {
     printf("\nmalloc error\n");
@@ -195,7 +198,7 @@ int main(int argc, char *argv[])
 
   edfseek(hdl, channel, (long long)((((double)x) / ((double)hdr.file_duration / (double)EDFLIB_TIME_DIMENSION)) * ((double)hdr.signalparam[channel].smp_in_file)), EDFSEEK_SET);
 
-  n = edfread_physical_samples(hdl, channel, n, buf);
+  n = edfread_physical_samples(hdl, channel, SAMPLES_READ, buf);
 
   if(n==(-1))
   {


=====================================
test_generator.c
=====================================
@@ -60,13 +60,17 @@
 
 
 
-#define SMP_FREQ 200
+#define SMP_FREQ  (200)
 
-#define SMP_FREQ_2 256
+#define SMP_FREQ_2  (256)
 
-#define SMP_FREQ_3 217
+#define SMP_FREQ_3  (217)
 
-#define FILE_DURATION 600
+#define FILE_DURATION  (600)
+
+#ifndef M_PI
+#define M_PI (3.14159265358979323846264338327)
+#endif
 
 
 // Uncomment the next line to create a BDF+ file instead of EDF+:



View it on GitLab: https://salsa.debian.org/med-team/edflib/-/commit/7e143c3c0e8194adb761d3583691c713896a9936

-- 
View it on GitLab: https://salsa.debian.org/med-team/edflib/-/commit/7e143c3c0e8194adb761d3583691c713896a9936
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20200704/f6880f07/attachment-0001.html>


More information about the debian-med-commit mailing list