Skip to content

Commit

Permalink
Add WIP (not working on X86) fixed-point implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymix007 committed Nov 18, 2021
1 parent 04f2982 commit 7b29b47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
26 changes: 15 additions & 11 deletions ldacdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <math.h>
#include <float.h>
#include <string.h>

#include <errno.h>

#include "ldacdec.h"

Expand All @@ -31,8 +31,8 @@ SNDFILE *openAudioFile( const char *fileName, int freq, int channels )
}


#define BUFFER_SIZE (680*2)
#define PCM_BUFFER_SIZE (256*2)
#define BUFFER_SIZE (680*2*2)
#define PCM_BUFFER_SIZE (256*2*2)

int main(int argc, char *args[] )
{
Expand Down Expand Up @@ -63,7 +63,7 @@ int main(int argc, char *args[] )

uint8_t buf[BUFFER_SIZE];
uint8_t *ptr = NULL;
int16_t pcm[PCM_BUFFER_SIZE] = { 0 };
int32_t pcm[PCM_BUFFER_SIZE] = { 0 };
size_t filePosition = 0;
//int blockId = 0;
int bytesInBuffer = 0;
Expand All @@ -74,11 +74,13 @@ int main(int argc, char *args[] )
if( ret < 0 )
break;
bytesInBuffer = fread( buf, 1, BUFFER_SIZE, in );

ptr = buf;
if( bytesInBuffer == 0 )
if( bytesInBuffer == 0 ){
break;
}
#if 1
if(ptr[1] == 0xAA)
while(ptr[0] != 0xAA)
{
ptr++;
filePosition++;
Expand All @@ -89,9 +91,10 @@ int main(int argc, char *args[] )

memset( pcm, 0, sizeof(pcm) );
LOG("count === %4d ===\n", blockId++ );
ret = ldacDecode( &dec, ptr, pcm, &bytesUsed );
if( ret < 0 )
ret = ldacDecode_type( &dec, ptr, pcm, &bytesUsed, 4);
if( ret < 0 ){
break;
}
LOG_ARRAY( pcm, "%4d, " );
if( out == NULL )
{
Expand All @@ -101,13 +104,14 @@ int main(int argc, char *args[] )
return EXIT_FAILURE;
}

sf_writef_short( out, pcm, dec.frame.frameSamples );
sf_writef_int( out, pcm, dec.frame.frameSamples );
filePosition += bytesUsed;
fflush(stdout);
}

printf("done.\n");
printf("Done!\n");

sf_close( out );
sf_close(out);
fclose(in);

return EXIT_SUCCESS;
Expand Down
5 changes: 4 additions & 1 deletion utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#define M_PI 3.14159265358979323846
#endif

#ifdef DOUBLE64
#if defined(DOUBLE64)
typedef double scalar;
#elif defined(FIXEDPOINT)
#include <stdfix.h>
typedef fract scalar;
#else
typedef float scalar;
#endif
Expand Down

0 comments on commit 7b29b47

Please sign in to comment.