Skip to content

Commit

Permalink
Address feedback, add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsimmisch committed Nov 20, 2023
1 parent d40d1d7 commit f9cb679
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rem/aufile/aufile.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,18 @@ size_t aufile_get_length(struct aufile *af, const struct aufile_prm *prm)
switch (prm->fmt) {
case AUFMT_PCMA:
case AUFMT_PCMU:
return af->datasize / prm->channels * 1000
/ prm->srate;
return af->datasize * 1000 /
(prm->channels * prm->srate);
case AUFMT_S16LE:
return af->datasize / 2 / prm->channels * 1000
/ prm->srate;
return af->datasize * 1000 /
(prm->channels * prm->srate * 2);
case AUFMT_S24_3LE:
return af->datasize / 3 / prm->channels * 1000
/ prm->srate;
return af->datasize * 1000 /
(prm->channels * prm->srate * 3);
case AUFMT_S32LE:
case AUFMT_FLOAT:
return af->datasize / 4 / prm->channels * 1000
/ prm->srate;
return af->datasize * 1000 /
(prm->channels * prm->srate * 4);
default:
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ set(SRCS
aes.c
async.c
aubuf.c
aulength.c
aulevel.c
auresamp.c
av1.c
Expand Down
36 changes: 36 additions & 0 deletions test/aulength.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @file src/aulength.c audio file duration test
*
* Copyright (C) 2023 Lars Immisch
*/

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


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


int test_aulength(void)
{
struct aufile *af;
struct aufile_prm prm;
char path[256];

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

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

size_t length = aufile_get_length(af, &prm);
TEST_EQUALS(67, length);

out:
mem_deref(af);

return err;
}
Binary file added test/data/beep.wav
Binary file not shown.
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static const struct test tests[] = {
TEST(test_aes),
TEST(test_aes_gcm),
TEST(test_aubuf),
TEST(test_aulength),
TEST(test_aulevel),
TEST(test_auresamp),
TEST(test_async),
Expand Down
1 change: 1 addition & 0 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ int test_aes(void);
int test_aes_gcm(void);
int test_aubuf(void);
int test_aulevel(void);
int test_aulength(void);
int test_auresamp(void);
int test_async(void);
int test_av1(void);
Expand Down

0 comments on commit f9cb679

Please sign in to comment.