Skip to content

Commit

Permalink
Add missing file, fix bug in aufile_set_position.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsimmisch committed Nov 20, 2023
1 parent 1f86e2b commit c03a53e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rem/aufile/aufile.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ int aufile_set_position(struct aufile *af, const struct aufile_prm *prm,
off_t pos = (off_t)(prm->srate * aufmt_sample_size(prm->fmt)
* prm->channels * pos_ms / 1000);

pos = max((off_t)datasize, pos);
pos = min((off_t)datasize, pos);

if (fseek(af->f, pos, SEEK_CUR) < 0)
return errno;
Expand Down
46 changes: 46 additions & 0 deletions test/aupos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file src/aupos.c audio file setposition test
*
* Copyright (C) 2023 Lars Immisch
*/

#include <re.h>
#include <rem.h>
#include "test.h"


#define DEBUG_MODULE "auposition"
#define DEBUG_LEVEL 5
#include <re_dbg.h>


int test_auposition(void)
{
struct aufile *af = NULL;
struct aufile_prm prm;
char path[256];
uint8_t buffer[128];

re_snprintf(path, sizeof(path), "%s/beep.wav", test_datapath());

int err = aufile_open(&af, &prm, path, AUFILE_READ);
if (err)
TEST_ERR(err);

err = aufile_set_position(af, &prm, 67);
if (err)
TEST_ERR(err);

/* That file is 67 ms long, so we shouldn't read anything */
size_t size = sizeof(buffer);
err = aufile_read(af, buffer, &size);
if (err)
TEST_ERR(err);

TEST_EQUALS(0, size);

out:
mem_deref(af);

return err;
}

0 comments on commit c03a53e

Please sign in to comment.