Browse Source

fix handling of original sampsize in pvx files

richarddobson 3 years ago
parent
commit
825bb19627
2 changed files with 27 additions and 4 deletions
  1. 22 3
      dev/newsfsys/sfsys.c
  2. 5 1
      dev/newsfsys/snd.c

+ 22 - 3
dev/newsfsys/sfsys.c

@@ -4156,8 +4156,26 @@ int sfcreat_formatted(const char *name,  __int64 size,  __int64 *outsize,int cha
         return -1;
         return -1;
     }
     }
     if(gettypefromname98(name) == pvxfile){
     if(gettypefromname98(name) == pvxfile){
+        //need to get source (CDP) stype into file header
+        int pv_stype = STYPE_16;
         int rc = 0;
         int rc = 0;
         
         
+        switch(stype) {
+            case INT2424:
+            case INT2024:
+                pv_stype = STYPE_24;
+                break;
+            case INT2432:
+            case INT_32:
+                pv_stype = STYPE_32;
+                break;
+            case FLOAT32:
+                pv_stype = STYPE_IEEE_FLOAT;
+                break;
+            default:
+                break;
+        }
+        
         f->filetype = pvxfile;
         f->filetype = pvxfile;
         // setup property block
         // setup property block
 # ifdef _DEBUG
 # ifdef _DEBUG
@@ -4168,7 +4186,7 @@ int sfcreat_formatted(const char *name,  __int64 size,  __int64 *outsize,int cha
         f->proplim = 2000; /* bytes; arbitrary. each putprop call checks this */
         f->proplim = 2000; /* bytes; arbitrary. each putprop call checks this */
         f->pvxprops = calloc(1,sizeof(PVOCDATA));
         f->pvxprops = calloc(1,sizeof(PVOCDATA));
         // init what we can, rely on file close to complete header via SFPROPS etc
         // init what we can, rely on file close to complete header via SFPROPS etc
-        rc = pvoc_createfile(name,channels - 2,0,1,PVOC_AMP_FREQ,0,STYPE_IEEE_FLOAT, PVOC_HANN,0.0,NULL,0);
+        rc = pvoc_createfile(name,channels - 2,0,1,PVOC_AMP_FREQ,0,pv_stype, PVOC_HANN,0.0,NULL,0);
         if(rc < 0){
         if(rc < 0){
 # ifdef _DEBUG
 # ifdef _DEBUG
             fprintf(stderr,"sfsys: pvoc_createfile failed: %s\n", pvoc_errorstr());
             fprintf(stderr,"sfsys: pvoc_createfile failed: %s\n", pvoc_errorstr());
@@ -6018,6 +6036,7 @@ sfclose(int sfd)
 # ifdef _DEBUG
 # ifdef _DEBUG
             assert(f->pvxprops->nAnalysisBins > 0);
             assert(f->pvxprops->nAnalysisBins > 0);
 # endif
 # endif
+            //ERROR! for pvx we want to get this from Format.wBitsPerSample 
             res = sfgetprop(sfd,"original sampsize",(char*) &origsize,sizeof(int));
             res = sfgetprop(sfd,"original sampsize",(char*) &origsize,sizeof(int));
             if(res < 0){
             if(res < 0){
  # ifdef _DEBUG
  # ifdef _DEBUG
@@ -6073,7 +6092,7 @@ sfclose(int sfd)
 
 
             f->fmtchunkEx.Format.nSamplesPerSec = origrate;
             f->fmtchunkEx.Format.nSamplesPerSec = origrate;
             f->fmtchunkEx.Format.nChannels = 1;
             f->fmtchunkEx.Format.nChannels = 1;
-            f->fmtchunkEx.Format.wBitsPerSample = 32;
+//            f->fmtchunkEx.Format.wBitsPerSample = 32;
             f->fmtchunkEx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
             f->fmtchunkEx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
             f->fmtchunkEx.Format.nBlockAlign = f->fmtchunkEx.Format.nChannels * sizeof(float);
             f->fmtchunkEx.Format.nBlockAlign = f->fmtchunkEx.Format.nChannels * sizeof(float);
             f->fmtchunkEx.Format.nAvgBytesPerSec =f->fmtchunkEx.Format.nBlockAlign * f->fmtchunkEx.Format.nSamplesPerSec;
             f->fmtchunkEx.Format.nAvgBytesPerSec =f->fmtchunkEx.Format.nBlockAlign * f->fmtchunkEx.Format.nSamplesPerSec;
@@ -6559,7 +6578,7 @@ sfputprop(int sfd, char *propname, char *src, int size)
                 break;
                 break;
             case(SAMP_BYTE):
             case(SAMP_BYTE):
                 rsferrno = ESFBADPARAM;
                 rsferrno = ESFBADPARAM;
-                rsferrstr = "8-bit files not supportewd for writing";
+                rsferrstr = "8-bit files not supported for writing";
                 return -1;
                 return -1;
             default:
             default:
                 rsferrno = ESFBADPARAM;
                 rsferrno = ESFBADPARAM;

+ 5 - 1
dev/newsfsys/snd.c

@@ -512,6 +512,7 @@ sndopenEx(const char *fn,int auto_scale, int access)
 }
 }
 
 
 /* RWD PVX note: this is the form called by CDP for ANAL files */
 /* RWD PVX note: this is the form called by CDP for ANAL files */
+/* Also, NB stype  is according to the SAMP_* list, gets converted by sampsize[] for sf routines as here */
 int
 int
 sndcreat_formatted(const char *fn, int size, int stype,int channels,
 sndcreat_formatted(const char *fn, int size, int stype,int channels,
                                    int srate,cdp_create_mode mode)
                                    int srate,cdp_create_mode mode)
@@ -529,6 +530,9 @@ sndcreat_formatted(const char *fn, int size, int stype,int channels,
     sf->samptype = stype;
     sf->samptype = stype;
 
 
     /*RWD NB sampsize[]  - no slot for 24bit size yet*/
     /*RWD NB sampsize[]  - no slot for 24bit size yet*/
+    /* ALSO: at this stage, CDP still assumes 32bits if an analysis file, no "original sampsize" info yet -
+       we have to rely on sfputprop("original sampsize" being set by program
+     */
     /* if pvx file, sets sffile->pvxfileno (which may be 0 ), but returns sf id (which may be 1) */
     /* if pvx file, sets sffile->pvxfileno (which may be 0 ), but returns sf id (which may be 1) */
     if((sf->fd = sfcreat_formatted(fn, size*sampsize[stype], (__int64 *)0,channels,srate,
     if((sf->fd = sfcreat_formatted(fn, size*sampsize[stype], (__int64 *)0,channels,srate,
                     stype,mode)) < 0) {
                     stype,mode)) < 0) {
@@ -764,7 +768,7 @@ sndseekEx(int fd, int dist, int whence)
                 break;
                 break;
             //end: step back dist samps if negative. We do not allow setting beyond EOF.
             //end: step back dist samps if negative. We do not allow setting beyond EOF.
         case SEEK_END:
         case SEEK_END:
-                rc = pvoc_seek_mcframe(sf->fd - 1000, frameoffset,SEEK_END);
+                rc = pvoc_seek_mcframe(pvxid, frameoffset,SEEK_END);
                 if(rc < 0){
                 if(rc < 0){
                     return rc;
                     return rc;
                 }
                 }