From: Jan Stary <hans@stare.cz>
To: sox-users@lists.sourceforge.net
Subject: Re: [SoX-users] how to interpret tell_off, and the right way to use sox_seek
Date: Tue, 7 Nov 2017 09:50:36 +0100 [thread overview]
Message-ID: <20171107085036.GA34760@www.stare.cz> (raw)
In-Reply-To: <CAOphizK+rP8mPuDS8ZFz3J=GHXuYm4+P5WV0PrKOOrY+k3vyFg@mail.gmail.com>
> 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.
Ah, I see what your problem is now.
> So sox_seek() is definitely being called, and definitely working.
> But nevertheless, the reading done after the seeking eventually fails.
Here is my slight rewrite of your example:
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <sox.h>
int
main(int argc, char **argv)
{
sox_format_t *s;
int32_t buf[1024];
ssize_t r;
int i;
if (argc < 2)
errx(1, "usage: ./soxseek input");
if (sox_init() != SOX_SUCCESS)
errx(1, "Cannot init libsox");
if ((s = sox_open_read(*++argv, 0, 0, 0)) == NULL)
errx(1, "Cannot open `%s'", *argv);
for (i = 1; (r = sox_read(s, buf, 1024)) > 0; i++) {
printf("[%04d] %zd samples, starting with %0x\n", i, r, *buf);
if (sox_seek(s, 0, SOX_SEEK_SET) != SOX_SUCCESS)
errx(1, "Cannot seek");
}
/* No way to test for sox_read() error */
return 0;
}
(Note how I don't use sox_site_t for the sox_read() return value,
because it does not exist, eventhough that's what libsox(3) documents.)
$ sox -n /tmp/file.wav synth trim 0 $((1024 * 1000))s
$ cc -o soxseek soxseek.c -lsox -I/usr/local/include/ -L/usr/local/lib
$ ./soxseek /tmp/file.wav
[0000] 1024 samples, starting with 0
[0001] 1024 samples, starting with 0
[....]
[0999] 1024 samples, starting with 0
[1000] 1024 samples, starting with 0
So I think you are right. It does seek back to the begining of the sine wave
(thus reporting 0 as the first sample value in the buffer), but it gets
exhausted at EOF anyway. I suspect now it is a bug in sox_seek()
if we are calling it right.
> Certainly if you do analogous coding with calls to fread() and
> fseek(), it would not terminate.
Yes, the following will read the same file forever:
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <err.h>
int
main(int argc, char **argv)
{
int fd;
int32_t buf[1024];
ssize_t r;
int i;
if (argc < 2)
errx(1, "usage: ./seek input");
if ((fd = open(*++argv, O_RDONLY)) == -1)
err(1, NULL);
for (i = 1; (r = read(fd, buf, 1024)) > 0; i++) {
printf("[%04d] %zd samples, starting with %0x\n", i, r, *buf);
if (lseek(fd, 0, SEEK_SET) == -1)
err(1, NULL);
}
return (r != 0);
}
> 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 share your suspition now.
> (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.)
Should we move this to sox-devel?
Jan
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel
prev parent reply other threads:[~2017-11-07 10:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAOphizLnrajpe-7TGuxyp2pt8+_ZbVU9yc9oemNAtrybbRNqRw@mail.gmail.com>
[not found] ` <20171106111001.GA80730@www.stare.cz>
[not found] ` <CAOphizKhERDQ-H_Xh0VSGPjKHnWBFgYc1UFQ7Ozk508WmDGTeg@mail.gmail.com>
[not found] ` <20171106190645.GA61378@www.stare.cz>
[not found] ` <CAOphizLLcY6LX=q3SZk0MwGq9SMeutbmLkMrhWyPStxu79hMZQ@mail.gmail.com>
[not found] ` <20171106210932.GA41280@www.stare.cz>
[not found] ` <CAOphizK+rP8mPuDS8ZFz3J=GHXuYm4+P5WV0PrKOOrY+k3vyFg@mail.gmail.com>
2017-11-07 8:50 ` [SoX-users] how to interpret tell_off, and the right way to use sox_seek Jan Stary
2017-11-07 8:50 ` Jan Stary [this message]
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-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171107085036.GA34760@www.stare.cz \
--to=sox-devel@lists.sourceforge.net \
--cc=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).