sox-users@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
From: Dan Hitt <dan.hitt@gmail.com>
To: sox-users@lists.sourceforge.net
Subject: Re: how to interpret tell_off, and the right way to use sox_seek
Date: Mon, 6 Nov 2017 13:47:28 -0800	[thread overview]
Message-ID: <CAOphizK+rP8mPuDS8ZFz3J=GHXuYm4+P5WV0PrKOOrY+k3vyFg@mail.gmail.com> (raw)
In-Reply-To: <20171106210932.GA41280@www.stare.cz>

Hi Jan!

Thanks for your mail.

On Mon, Nov 6, 2017 at 1:09 PM, Jan Stary <hans@stare.cz> wrote:
> On Nov 06 12:14:59, dan.hitt@gmail.com 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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users

  reply	other threads:[~2017-11-06 21:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-04  7:26 how to interpret tell_off, and the right way to use sox_seek Dan Hitt
2017-11-06 11:10 ` Jan Stary
2017-11-06 18:08   ` Dan Hitt
2017-11-06 19:06     ` Jan Stary
2017-11-06 20:14       ` Dan Hitt
2017-11-06 21:09         ` Jan Stary
2017-11-06 21:47           ` Dan Hitt [this message]
2017-11-07  8:50             ` Jan Stary
2017-11-07  9:01               ` Jan Stary
2017-11-07  9:13                 ` Jan Stary
2017-11-07  9:22                   ` Jan Stary

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-users

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOphizK+rP8mPuDS8ZFz3J=GHXuYm4+P5WV0PrKOOrY+k3vyFg@mail.gmail.com' \
    --to=sox-users@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).