-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rem/aufile: test and fix aufile_set_position nread (#1010)
Also fix a bug: wav files can contain data after the data chunk. If we don't update nread in aufile_set_position, we can read invalid data.
- Loading branch information
1 parent
e097b7f
commit 544b1db
Showing
6 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ set(SRCS | |
aubuf.c | ||
aulength.c | ||
aulevel.c | ||
aupos.c | ||
auresamp.c | ||
av1.c | ||
base64.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @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[512]; | ||
|
||
re_snprintf(path, sizeof(path), "%s/beep.wav", test_datapath()); | ||
|
||
int err = aufile_open(&af, &prm, path, AUFILE_READ); | ||
TEST_ERR(err); | ||
|
||
err = aufile_set_position(af, &prm, 67); | ||
TEST_ERR(err); | ||
|
||
/* That file is exactly 67 ms long, so we shouldn't read anything */ | ||
size_t size = sizeof(buffer); | ||
err = aufile_read(af, buffer, &size); | ||
TEST_ERR(err); | ||
|
||
/* It's possible we read data up to a ms */ | ||
TEST_ASSERT(size < 16); | ||
|
||
af = mem_deref(af); | ||
|
||
err = aufile_open(&af, &prm, path, AUFILE_READ); | ||
TEST_ERR(err); | ||
|
||
err = aufile_set_position(af, &prm, 37); | ||
TEST_ERR(err); | ||
|
||
size = sizeof(buffer); | ||
err = aufile_read(af, buffer, &size); | ||
TEST_ERR(err); | ||
|
||
/* 30 ms should be left, at 8000Hz/s, one channels and 16 bit samples | ||
that's 480 bytes */ | ||
TEST_ASSERT(size - 480 < 16); | ||
|
||
|
||
out: | ||
mem_deref(af); | ||
|
||
return err; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters