diff --git a/components/libmp3lame/include/config.h b/components/libmp3lame/include/config.h index 9d7ed6e..0927cc1 100644 --- a/components/libmp3lame/include/config.h +++ b/components/libmp3lame/include/config.h @@ -1,86 +1,86 @@ -/* expat_config.h. Generated from expat_config.h.in by configure. */ -/* expat_config.h.in. Generated from configure.ac by autoheader. */ - -/* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */ -#define BYTEORDER 1234 - -/* Define to 1 if you have the `bcopy' function. */ -#define HAVE_BCOPY 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the `getpagesize' function. */ -#define HAVE_GETPAGESIZE 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have a working `mmap' system call. */ -#define HAVE_MMAP 1 - -#define HAVE_ERRNO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_PARAM_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* whether byteorder is bigendian */ -/* #undef WORDS_BIGENDIAN */ - - - -/* Define to __FUNCTION__ or "" if `__func__' does not conform to ANSI C. */ -/* #undef __func__ */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `long int' if does not define. */ -/* #undef off_t */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ - -#undef HAVE_NASM -#undef HAVE_MPGLIB -#undef HAVE_XMMINTRIN_H - -#undef TAKEHIRO_IEEE754_HACK +/* expat_config.h. Generated from expat_config.h.in by configure. */ +/* expat_config.h.in. Generated from configure.ac by autoheader. */ + +/* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */ +#define BYTEORDER 1234 + +/* Define to 1 if you have the `bcopy' function. */ +#define HAVE_BCOPY 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have a working `mmap' system call. */ +#define HAVE_MMAP 1 + +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* whether byteorder is bigendian */ +/* #undef WORDS_BIGENDIAN */ + + + +/* Define to __FUNCTION__ or "" if `__func__' does not conform to ANSI C. */ +/* #undef __func__ */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +#undef HAVE_NASM +#undef HAVE_MPGLIB +#undef HAVE_XMMINTRIN_H + +#undef TAKEHIRO_IEEE754_HACK diff --git a/components/libmp3lame/library/gain_analysis.c b/components/libmp3lame/library/gain_analysis.c index 279afbf..24c4aee 100644 --- a/components/libmp3lame/library/gain_analysis.c +++ b/components/libmp3lame/library/gain_analysis.c @@ -286,7 +286,13 @@ ResetSampleFrequency(replaygain_t * rgData, long samplefreq) rgData->totsamp = 0; //memset(rgData->A, 0, sizeof(rgData->A)); - memset(rgData->A, 0, 12000*sizeof(sizeof(uint32_t))); + //memset(rgData->A, 0, 12000*sizeof(uint32_t)); + + for (int i=0; i<12000; i++) + { + gfc->sv_rpg.rgdata->A[i]=0; + } + return INIT_GAIN_ANALYSIS_OK; } @@ -306,7 +312,12 @@ InitGainAnalysis(replaygain_t * rgData, long samplefreq) rgData->rout = rgData->routbuf + MAX_ORDER; //memset(rgData->B, 0, sizeof(rgData->B)); - memset(rgData->B, 0, 12000*sizeof(sizeof(uint32_t))); + //memset(rgData->B, 0, 12000*sizeof(uint32_t)); + + for (int i=0; i<12000; i++) + { + gfc->sv_rpg.rgdata->B[i]=0; + } return INIT_GAIN_ANALYSIS_OK; } diff --git a/components/libmp3lame/library/lame.c b/components/libmp3lame/library/lame.c index 78df339..8418201 100644 --- a/components/libmp3lame/library/lame.c +++ b/components/libmp3lame/library/lame.c @@ -597,10 +597,10 @@ lame_init_params(lame_global_flags * gfp) // gfc->sv_rpg.rgdata->A = calloc (12000, sizeof(uint32_t)); gfc->sv_rpg.rgdata->A = pvPortMallocCaps(12000*sizeof(uint32_t), MALLOC_CAP_32BIT); -// memset(gfc->sv_rpg.rgdata->A, 0, 12000*sizeof(sizeof(uint32_t))); +// memset(gfc->sv_rpg.rgdata->A, 0, 12000*sizeof(uint32_t)); // gfc->sv_rpg.rgdata->B = calloc (12000, sizeof(uint32_t)); gfc->sv_rpg.rgdata->B = pvPortMallocCaps(12000*sizeof(uint32_t), MALLOC_CAP_32BIT); -// memset(gfc->sv_rpg.rgdata->B, 0, 12000*sizeof(sizeof(uint32_t))); +// memset(gfc->sv_rpg.rgdata->B, 0, 12000*sizeof(uint32_t)); for (int i=0; i<12000; i++) { diff --git a/main/lame_test.c b/main/lame_test.c index 7cbde75..307fca7 100644 --- a/main/lame_test.c +++ b/main/lame_test.c @@ -1,136 +1,136 @@ -#include "lame.h" -#include "lame_test.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_system.h" -#include -#include -#include -#include "rom/ets_sys.h" -#include "esp_heap_alloc_caps.h" -#include -#include - -extern const uint8_t Sample16kHz_raw_start[] asm("_binary_Sample16kHz_raw_start"); -extern const uint8_t Sample16kHz_raw_end[] asm("_binary_Sample16kHz_raw_end"); - -void lameTest() -{ - lame_t lame; - unsigned int sampleRate = 16000; - short int *pcm_samples; - int framesize = 0; - int num_samples_encoded = 0; - size_t free8start, free32start; - const int nsamples=1152; - unsigned char *mp3buf; - const int mp3buf_size=2000; - - free8start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_8BIT); - free32start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_32BIT); - printf("pre lame_init() free mem8bit: %d mem32bit: %d\n",free8start,free32start); - - mp3buf=malloc(mp3buf_size); - - /* Init lame flags.*/ - lame = lame_init(); - - free8start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_8BIT); - free32start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_32BIT); - printf("post lame_init() free mem8bit: %d mem32bit: %d\n",free8start,free32start); - - if(!lame) { - printf("Unable to initialize lame object.\n"); - } else { - printf("Able to initialize lame object.\n"); - } - - /* set other parameters.*/ - lame_set_VBR(lame, vbr_default); - lame_set_num_channels(lame, 2); - lame_set_in_samplerate(lame, sampleRate); - lame_set_quality(lame, 7); /* set for high speed and good quality. */ - lame_set_mode(lame, JOINT_STEREO); /* audio is joint stereo */ - -// lame_set_out_samplerate(lame, sampleRate); - printf("Able to set a number of parameters too.\n"); - - - /* set more internal variables. check for failure.*/ - int initRet = lame_init_params(lame); - if(initRet < 0) printf("Fail in setting internal parameters with code=%d\n",initRet); - else printf("OK setting internal parameters\n"); - - - free8start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_8BIT); - printf("post lame_init_params() free mem: %d\n",free8start); - -// lame_print_config(lame); -// lame_print_internals(lame); - - framesize = lame_get_framesize(lame); - printf("Framesize = %d\n", framesize); -// assert(framesize <= 1152); - -/* - printf("Sample16kHz.raw start: %p", Sample16kHz_raw_start); - printf(" end: %p", Sample16kHz_raw_end); - printf(" with size: %d\n", Sample16kHz_raw_end-Sample16kHz_raw_start); -*/ - - pcm_samples = (short int *)Sample16kHz_raw_start; - - for (int j=0;j<10;j++) - { - printf("\n=============== lame_encode_buffer_interleaved================ \n"); - - /* encode samples. */ - - num_samples_encoded = lame_encode_buffer_interleaved(lame, pcm_samples, nsamples, mp3buf, mp3buf_size); - - printf("number of samples encoded = %d\n", num_samples_encoded); - - /* check for value returned.*/ - if(num_samples_encoded > 1) { - printf("It seems the conversion was successful.\n"); - } else if(num_samples_encoded == -1) { - printf("mp3buf was too small\n"); - return ; - } else if(num_samples_encoded == -2) { - printf("There was a malloc problem.\n"); - return ; - } else if(num_samples_encoded == -3) { - printf("lame_init_params() not called.\n"); - return ; - } else if(num_samples_encoded == -4) { - printf("Psycho acoustic problems.\n"); - return ; - } else if(num_samples_encoded == -11) { - printf("McM test\n"); - return ; - } else { - printf("The conversion was not successful.\n"); - return ; - } - - - printf("Contents of mp3buffer = "); - for(int i = 0; i < num_samples_encoded; i++) { - printf("%d ", mp3buf[i]); - } - - pcm_samples += (nsamples*2); - - } - - -// ========================================================= - - - lame_close(lame); - printf("\nClose\n"); - - while (1) vTaskDelay(500 / portTICK_RATE_MS); - - return; -} +#include "lame.h" +#include "lame_test.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_system.h" +#include +#include +#include +#include "rom/ets_sys.h" +#include "esp_heap_alloc_caps.h" +#include +#include + +extern const uint8_t Sample16kHz_raw_start[] asm("_binary_Sample16kHz_raw_start"); +extern const uint8_t Sample16kHz_raw_end[] asm("_binary_Sample16kHz_raw_end"); + +void lameTest() +{ + lame_t lame; + unsigned int sampleRate = 16000; + short int *pcm_samples; + int framesize = 0; + int num_samples_encoded = 0; + size_t free8start, free32start; + const int nsamples=1152; + unsigned char *mp3buf; + const int mp3buf_size=2000; + + free8start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_8BIT); + free32start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_32BIT); + printf("pre lame_init() free mem8bit: %d mem32bit: %d\n",free8start,free32start); + + mp3buf=malloc(mp3buf_size); + + /* Init lame flags.*/ + lame = lame_init(); + + free8start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_8BIT); + free32start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_32BIT); + printf("post lame_init() free mem8bit: %d mem32bit: %d\n",free8start,free32start); + + if(!lame) { + printf("Unable to initialize lame object.\n"); + } else { + printf("Able to initialize lame object.\n"); + } + + /* set other parameters.*/ + lame_set_VBR(lame, vbr_default); + lame_set_num_channels(lame, 2); + lame_set_in_samplerate(lame, sampleRate); + lame_set_quality(lame, 7); /* set for high speed and good quality. */ + lame_set_mode(lame, JOINT_STEREO); /* audio is joint stereo */ + +// lame_set_out_samplerate(lame, sampleRate); + printf("Able to set a number of parameters too.\n"); + + + /* set more internal variables. check for failure.*/ + int initRet = lame_init_params(lame); + if(initRet < 0) printf("Fail in setting internal parameters with code=%d\n",initRet); + else printf("OK setting internal parameters\n"); + + + free8start=xPortGetFreeHeapSizeCaps(MALLOC_CAP_8BIT); + printf("post lame_init_params() free mem: %d\n",free8start); + +// lame_print_config(lame); +// lame_print_internals(lame); + + framesize = lame_get_framesize(lame); + printf("Framesize = %d\n", framesize); +// assert(framesize <= 1152); + +/* + printf("Sample16kHz.raw start: %p", Sample16kHz_raw_start); + printf(" end: %p", Sample16kHz_raw_end); + printf(" with size: %d\n", Sample16kHz_raw_end-Sample16kHz_raw_start); +*/ + + pcm_samples = (short int *)Sample16kHz_raw_start; + + for (int j=0;j<10;j++) + { + printf("\n=============== lame_encode_buffer_interleaved================ \n"); + + /* encode samples. */ + + num_samples_encoded = lame_encode_buffer_interleaved(lame, pcm_samples, nsamples, mp3buf, mp3buf_size); + + printf("number of samples encoded = %d\n", num_samples_encoded); + + /* check for value returned.*/ + if(num_samples_encoded > 1) { + printf("It seems the conversion was successful.\n"); + } else if(num_samples_encoded == -1) { + printf("mp3buf was too small\n"); + return ; + } else if(num_samples_encoded == -2) { + printf("There was a malloc problem.\n"); + return ; + } else if(num_samples_encoded == -3) { + printf("lame_init_params() not called.\n"); + return ; + } else if(num_samples_encoded == -4) { + printf("Psycho acoustic problems.\n"); + return ; + } else if(num_samples_encoded == -11) { + printf("McM test\n"); + return ; + } else { + printf("The conversion was not successful.\n"); + return ; + } + + + printf("Contents of mp3buffer = "); + for(int i = 0; i < num_samples_encoded; i++) { + printf("%d ", mp3buf[i]); + } + + pcm_samples += (nsamples*2); + + } + + +// ========================================================= + + + lame_close(lame); + printf("\nClose\n"); + + while (1) vTaskDelay(500 / portTICK_RATE_MS); + + return; +}