shithub: sox

Download patch

ref: ec5cdbd619a7a16be33ec3f84166b41a5d5c95d3
parent: 4c6e35d20fcca0017b630bcfaf1df7ffef6df3eb
author: cbagwell <cbagwell>
date: Mon Sep 26 21:58:51 EDT 2005

Documenting new user interface to libst.

--- a/src/sox.c
+++ b/src/sox.c
@@ -91,7 +91,6 @@
     char *filename;
     char *filetype;
     st_signalinfo_t info;
-    char swap;
     double volume;
     char uservolume;
     char *comment;
@@ -245,8 +244,7 @@
 #endif
         file_desc[i] = st_open_input(file_opts[i]->filename,
                                      &file_opts[i]->info, 
-                                     file_opts[i]->filetype,
-                                     file_opts[i]->swap);
+                                     file_opts[i]->filetype);
         if (!file_desc[i])
         {
             /* st_open_input() will call st_warn for most errors.
@@ -377,7 +375,7 @@
                 break;
 
             case 'x':
-                fo->swap = 1;
+                fo->info.swap = 1;
                 break;
 
             case 'V':
@@ -479,15 +477,43 @@
 
     if (writing)
     {
+        st_loopinfo_t loops[ST_MAX_NLOOPS];
+        double factor;
+        int i;
+
+        if (file_opts[file_count-1]->info.rate == 0)
+            file_opts[file_count-1]->info.rate = file_desc[0]->info.rate;
+        if (file_opts[file_count-1]->info.size == -1)
+            file_opts[file_count-1]->info.size = file_desc[0]->info.size;
+        if (file_opts[file_count-1]->info.encoding == -1)
+            file_opts[file_count-1]->info.encoding = 
+                file_desc[0]->info.encoding;
+        if (file_opts[file_count-1]->info.channels == -1)
+            file_opts[file_count-1]->info.channels = 
+                file_desc[0]->info.channels;
+
+        /*
+         * copy loop info, resizing appropriately
+         * it's in samples, so # channels don't matter
+         * FIXME: This doesn't work for multi-file processing or
+         * effects that change file length.
+         */
+        factor = (double) file_opts[file_count-1]->info.rate / (double) 
+            file_desc[0]->info.rate;
+        for(i = 0; i < ST_MAX_NLOOPS; i++) {
+            loops[i].start = file_desc[0]->loops[i].start * factor;
+            loops[i].length = file_desc[0]->loops[i].length * factor;
+            loops[i].count = file_desc[0]->loops[i].count;
+            loops[i].type = file_desc[0]->loops[i].type;
+        }
+
         file_desc[file_count-1] = 
             st_open_output(file_opts[file_count-1]->filename,
                            &file_opts[file_count-1]->info, 
-                           &file_desc[0]->info,
                            file_desc[0]->comment,
-                           file_desc[0]->loops,
+                           loops,
                            &file_desc[0]->instr,
-                           file_opts[file_count-1]->filetype,
-                           file_opts[file_count-1]->swap);
+                           file_opts[file_count-1]->filetype);
 
         if (!file_desc[file_count-1])
         {
--- a/src/st.h
+++ b/src/st.h
@@ -67,10 +67,11 @@
 
 typedef struct  st_signalinfo
 {
-    st_rate_t rate;         /* sampling rate */
+    st_rate_t rate;       /* sampling rate */
     signed char size;     /* word length of data */
     signed char encoding; /* format of sample numbers */
     signed char channels; /* number of sound channels */
+    char swap;            /* do byte- or word-swap */
 } st_signalinfo_t;
 
 /* Loop parameters */
@@ -255,12 +256,11 @@
 extern st_effect_t st_effects[]; /* declared in handlers.c */
 
 extern ft_t st_open_input(const char *path, const st_signalinfo_t *info, 
-                          const char *filetype, char swap);
+                          const char *filetype);
 extern ft_t st_open_output(const char *path, const st_signalinfo_t *info,
-                           const st_signalinfo_t *input_info,
                            const char *comment, const st_loopinfo_t *loops,
                            const st_instrinfo_t *instr,
-                           const char *filetype, char swap);
+                           const char *filetype);
 extern st_ssize_t st_read(ft_t ft, st_sample_t *buf, st_ssize_t len);
 extern st_ssize_t st_write(ft_t ft, st_sample_t *buf, st_ssize_t len);
 extern int st_close(ft_t ft);
--- a/src/stio.c
+++ b/src/stio.c
@@ -72,7 +72,7 @@
 }
 
 ft_t st_open_input(const char *path, const st_signalinfo_t *info,
-                   const char *filetype, char swap)
+                   const char *filetype)
 {
     ft_t ft;
 
@@ -103,8 +103,10 @@
     ft->info.size = -1;
     ft->info.encoding = -1;
     ft->info.channels = -1;
-    ft->info = *info;
-    ft->swap = swap;
+    if (info)
+        ft->info = *info;
+    /* FIXME: Remove ft->swap from code */
+    ft->swap = ft->info.swap;
     ft->mode = 'r';
 
     if (!(ft->h->flags & ST_FILE_NOSTDIO))
@@ -164,49 +166,14 @@
 #define LASTCHAR '/'
 #endif
 
-static void st_copyformat(ft_t ft, const st_signalinfo_t *info,
-                          const char *comment, const st_loopinfo_t *loops,
-                          const st_instrinfo_t *instr)
-{
-    int i;
-    double factor;
-
-    if (ft->info.rate == 0)
-        ft->info.rate = info->rate;
-    if (ft->info.size == -1)
-        ft->info.size = info->size;
-    if (ft->info.encoding == -1)
-        ft->info.encoding = info->encoding;
-    if (ft->info.channels == -1)
-        ft->info.channels = info->channels;
-
-    if (ft->comment == NULL && comment != NULL)
-        ft->comment = strdup(comment);
-    else
-        ft->comment = strdup("Processed by SoX");
-
-    /*
-     * copy loop info, resizing appropriately
-     * it's in samples, so # channels don't matter
-     */
-    factor = (double) ft->info.rate / (double) info->rate;
-    for(i = 0; i < ST_MAX_NLOOPS; i++) {
-        ft->loops[i].start = loops[i].start * factor;
-        ft->loops[i].length = loops[i].length * factor;
-        ft->loops[i].count = loops[i].count;
-        ft->loops[i].type = loops[i].type;
-    }
-    /* leave SMPTE # alone since it's absolute */
-    ft->instr = *instr;
-}
-
 ft_t st_open_output(const char *path, const st_signalinfo_t *info,
-                    const st_signalinfo_t *input_info,
                     const char *comment, const st_loopinfo_t *loops,
                     const st_instrinfo_t *instr,
-                    const char *filetype, char swap)
+                    const char *filetype)
 {
     ft_t ft;
+    int i;
+
     ft = (ft_t)calloc(sizeof(struct st_soundstream), 1);
 
     if (!ft )
@@ -253,8 +220,8 @@
     ft->info.size = -1;
     ft->info.encoding = -1;
     ft->info.channels = -1;
-    ft->info = *info;
-    ft->swap = swap;
+    if (info)
+        ft->info = *info;
     ft->mode = 'w';
 
     if (!(ft->h->flags & ST_FILE_NOSTDIO))
@@ -287,7 +254,21 @@
         ft->seekable = is_seekable(ft);
     }
 
-    st_copyformat(ft, input_info, comment, loops, instr);
+    if (ft->comment == NULL && comment != NULL)
+        ft->comment = strdup(comment);
+    else
+        ft->comment = strdup("Processed by SoX");
+
+    for (i = 0; i < ST_MAX_NLOOPS; i++)
+    {
+        ft->loops[i] = loops[i];
+    }
+
+    /* leave SMPTE # alone since it's absolute */
+    ft->instr = *instr;
+
+    /* FIXME: Remove ft->swap from code */
+    ft->swap = ft->info.swap;
 
     /* Read and write starters can change their formats. */
     if ((*ft->h->startwrite)(ft) != ST_SUCCESS)