Re: how to interpret tell_off, and the right way to use sox_seek

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Jan!

Thanks for your mail.

On Mon, Nov 6, 2017 at 1:09 PM, Jan Stary <hans@xxxxxxxx> wrote:
> On Nov 06 12:14:59, dan.hitt@xxxxxxxxx wrote:
....... (cut)
>>
>>     #include <stdio.h>
>>     #include <stdlib.h>
>>     #include <sox.h>
>>
>>     int main( int argc, char** argv ) {
>>       if ( argc < 2 )  {
>>         fprintf(stderr,"Call with one arg, the name of a sound file.\n" );
>>         exit(1);
>>       }
>>       int istat = sox_init();
>>       if (istat != SOX_SUCCESS ) {
>>         fprintf(stderr, "Failed to initialize sox, error %d.\n", istat);
>>         exit(1);
>>       }
>>       char* infile = argv[1];
>>       sox_format_t* s = sox_open_read( infile, 0, 0, 0 );
>>       if ( ! s ) {
>>         fprintf(stderr,"Failed to open `%s' .\n", infile);
>>         exit(1);
>>       }
>>       int buf[1024];
>>       int count = 0;
>>       while ( 1 ) {
>>         int rcnt = sox_read( s, buf, 1024 );
>>         if ( rcnt <= 0 ) {
>>           printf( "Failed on read, attempt %d\n", count );
>>           exit( 0 );
>>         }
>>         int status = sox_seek( s, 0, SOX_SEEK_SET );
>>         if ( status ) {
>>           fprintf(stderr,"Failed on seek.\n" );
>>           exit(1);
>>         }
>>         count++;
>>       }
>>       return 0; // not reached
>>     }
>>
 .... (cut)
> If I am reading your code right, it does not seek at all.

It's in a loop.

First, it reads (which presumably moves the file pointer forwards),
then it seeks back to where it was.

I've verified in gdb that it actually does call sox_seek() (again and
again and again, but not forever).  I have also verified in gdb that
it is reading the same samples.

So sox_seek() is definitely being called, and definitely working.

But nevertheless, the reading done after the seeking eventually fails.

Certainly if you do analogous coding with calls to fread() and
fseek(), it would not terminate.

>
> I still suspect that it is first of all unnecessary to read the input
> again and again while seeking back again and again; but I can't be sure,
> because I still have no idea about what you are doing.

What i'm trying to do now is to determine the correct way to use
sox_seek() if i am using it incorrectly.  If i'm using it correctly,
then i would like confirmation of my characterization (that it has
some internal counter which is decremented until it hits zero).

(I did have a signal processing problem that i was considering
earlier, but that's not relevant now because i avoided the sox_seek
issue by rearranging the computation.  So i can do my dsp, but i do
wonder about correct usage of sox_seek.)

Anyhow, i do appreciate your investigation of this!!! :) :)

dan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Sox-users mailing list
Sox-users@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/sox-users



[Index of Archives]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux