seeking in stb_vorbis (Dougall Johnson)
test program for seeking (stb)
This commit is contained in:
@ -63,7 +63,7 @@ Package=<4>
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "resize"=.\resize\resize.dsp - Package Owner=<4>
|
||||
Project: "resize"=.\resize.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
@ -123,6 +123,18 @@ Package=<4>
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "vorbseek"=.\vorbseek\vorbseek.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
|
105
tests/vorbseek/vorbseek.c
Normal file
105
tests/vorbseek/vorbseek.c
Normal file
@ -0,0 +1,105 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define STB_VORBIS_HEADER_ONLY
|
||||
#include "stb_vorbis.c"
|
||||
|
||||
#define SAMPLES_TO_TEST 3000
|
||||
|
||||
int test_count [5] = { 5000, 3000, 2000, 50000, 50000 };
|
||||
int test_spacing[5] = { 1, 111, 3337, 7779, 72717 };
|
||||
|
||||
int try_seeking(stb_vorbis *v, unsigned int pos, short *output, unsigned int num_samples)
|
||||
{
|
||||
int count;
|
||||
short samples[SAMPLES_TO_TEST*2];
|
||||
assert(pos <= num_samples);
|
||||
|
||||
if (!stb_vorbis_seek(v, pos)) {
|
||||
fprintf(stderr, "Seek to %u returned error from stb_vorbis\n", pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
count = stb_vorbis_get_samples_short_interleaved(v, 2, samples, SAMPLES_TO_TEST*2);
|
||||
|
||||
if (count > (int) (num_samples - pos)) {
|
||||
fprintf(stderr, "Seek to %u allowed decoding %d samples when only %d should have been valid.\n",
|
||||
pos, count, (int) (num_samples - pos));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (count < SAMPLES_TO_TEST && count < (int) (num_samples - pos)) {
|
||||
fprintf(stderr, "Seek to %u only decoded %d samples of %d attempted when at least %d should have been valid.\n",
|
||||
pos, count, SAMPLES_TO_TEST, num_samples - pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (0 != memcmp(samples, output + pos*2, count*2)) {
|
||||
int k;
|
||||
for (k=0; k < SAMPLES_TO_TEST*2; ++k) {
|
||||
if (samples[k] != output[k]) {
|
||||
fprintf(stderr, "Seek to %u produced incorrect samples starting at sample %u (short #%d in buffer).\n",
|
||||
pos, pos + (k/2), k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(k != SAMPLES_TO_TEST*2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int num_chan, samprate;
|
||||
int i, j, test, phase;
|
||||
short *output;
|
||||
if (argc == 1) {
|
||||
fprintf(stderr, "Usage: vorbseek {vorbisfile} [{vorbisfile]*]\n");
|
||||
fprintf(stderr, "Tests various seek offsets to make sure they're sample exact.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (j=1; j < argc; ++j) {
|
||||
unsigned int successes=0, attempts = 0;
|
||||
unsigned int num_samples = stb_vorbis_decode_filename(argv[j], &num_chan, &samprate, &output);
|
||||
|
||||
if (num_samples == 0xffffffff) {
|
||||
fprintf(stderr, "Error: couldn't open file or not vorbis file: %s\n", argv[j]);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (num_chan != 2) {
|
||||
fprintf(stderr, "vorbseek testing only works with files with 2 channels, %s has %d\n", argv[j], num_chan);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (test=0; test < 5; ++test) {
|
||||
int error;
|
||||
stb_vorbis *v = stb_vorbis_open_filename(argv[j], &error, NULL);
|
||||
if (v == NULL) {
|
||||
fprintf(stderr, "Couldn't re-open %s for test #%d\n", argv[j], test);
|
||||
goto fail;
|
||||
}
|
||||
for (phase=0; phase < 3; ++phase) {
|
||||
unsigned int base = phase == 0 ? 0 : phase == 1 ? num_samples - test_count[test]*test_spacing[test] : num_samples/3;
|
||||
for (i=0; i < test_count[test]; ++i) {
|
||||
unsigned int pos = base + i*test_spacing[test];
|
||||
if (pos > num_samples) // this also catches underflows
|
||||
continue;
|
||||
successes += try_seeking(v, pos, output, num_samples);
|
||||
attempts += 1;
|
||||
}
|
||||
}
|
||||
stb_vorbis_close(v);
|
||||
}
|
||||
printf("%d of %d seeks failed in %s (%d samples)\n", attempts-successes, attempts, argv[j], num_samples);
|
||||
free(output);
|
||||
}
|
||||
return 0;
|
||||
fail:
|
||||
return 1;
|
||||
}
|
96
tests/vorbseek/vorbseek.dsp
Normal file
96
tests/vorbseek/vorbseek.dsp
Normal file
@ -0,0 +1,96 @@
|
||||
# Microsoft Developer Studio Project File - Name="vorbseek" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=vorbseek - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "vorbseek.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "vorbseek.mak" CFG="vorbseek - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "vorbseek - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "vorbseek - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "vorbseek - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "vorbseek - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "vorbseek - Win32 Release"
|
||||
# Name "vorbseek - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
Reference in New Issue
Block a user