Page 1 of 1

Store Audio Samples on Esp

Posted: Thu Jul 06, 2017 12:55 pm
by partyfriend
Hello,

I already record and playback audio with i2s.

I now want to store a 16 Bit pcm sample encoded file from what i can read from. I dropped the file in the same folder my .c file is located.
but excecuteing this code:

Code: Select all

  printf("Start reading file\n\n\n");
  FILE *f = fopen("Test.raw", "rb");
  fseek(f, 0, SEEK_END);
  long fsize = ftell(f);
  fseek(f, 0, SEEK_SET);  //same as rewind(f);
  printf("%d is size of file\n\n\n", (int) fsize);
  char *volumesample = malloc(fsize + 1);
  fread(volumesample, fsize, 1, f);
  fclose(f);
lets the ESP32 crash trying to read the file.
Start reading file


Guru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 0x400e406c PS : 0x00060430 A0 : 0x800e4031 A1 : 0x3ffd2720
0x400e406c: _fseeko_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fseeko.c:141

A2 : 0x3ffd2a08 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000002
A6 : 0x3ff96458 A7 : 0x7ff2bf1d A8 : 0x8008425e A9 : 0x3ffd2750
A10 : 0x3ffd29a4 A11 : 0x3f406654 A12 : 0x00000000 A13 : 0x000001b6
A14 : 0x00000800 A15 : 0x0000002b SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000064 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffd

Backtrace: 0x400e406c:0x3ffd2720 0x400e4031:0x3ffd2790 0x400f5e30:0x3ffd27b0
0x400e406c: _fseeko_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fseeko.c:141

0x400e4031: fseek at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fseek.c:126

0x400f5e30: audio at C:/msys32/home/wellmp/esp/VIVO/soc/components/audio/audio.c:103


Rebooting...
Is it even possible to do it this way?
What is the most convenient way to store this sample?

Im new to the ESP32 and have not so much programming skills :O

I attached the Volume.raw file ( as Volume.c to upload it)

mfG Philip

Re: Store Audio Samples on Esp

Posted: Thu Jul 06, 2017 3:40 pm
by kurtzweber
Hi

probably the easiest way is to leverage the binary data embedding feature of the build system:
http://esp-idf.readthedocs.io/en/latest ... ystem.html

it is used for example here to include the SSL certificate:
https://github.com/espressif/esp-idf/tr ... ps_request

Re: Store Audio Samples on Esp

Posted: Fri Jul 07, 2017 2:25 am
by ESP_igrr
The crash happens because fopen is returning NULL (can't open the file), and you are not checking the return value.

Files added to the project do not automatically get uploaded to the device. The embedding feature suggested by kurtzweber is indeed the easiest way to achieve what you need, provided that the file is not very large (less than ~3Mb).

Another option is to use a filesystem. Search this forum for the SPIFFS example by loboris, which provides means of uploading files to a filesystem on the ESP32.

Re: Store Audio Samples on Esp

Posted: Thu Jul 13, 2017 3:48 am
by andriy
partyfriend wrote:Hello,

I already record and playback audio with i2s.

I now want to store a 16 Bit pcm sample encoded file from what i can read from. I dropped the file in the same folder my .c file is located.
but excecuteing this code:

Code: Select all

  printf("Start reading file\n\n\n");
  FILE *f = fopen("Test.raw", "rb");
  fseek(f, 0, SEEK_END);
  long fsize = ftell(f);
  fseek(f, 0, SEEK_SET);  //same as rewind(f);
  printf("%d is size of file\n\n\n", (int) fsize);
  char *volumesample = malloc(fsize + 1);
  fread(volumesample, fsize, 1, f);
  fclose(f);
lets the ESP32 crash trying to read the file.
Start reading file


Guru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 0x400e406c PS : 0x00060430 A0 : 0x800e4031 A1 : 0x3ffd2720
0x400e406c: _fseeko_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fseeko.c:141

A2 : 0x3ffd2a08 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000002
A6 : 0x3ff96458 A7 : 0x7ff2bf1d A8 : 0x8008425e A9 : 0x3ffd2750
A10 : 0x3ffd29a4 A11 : 0x3f406654 A12 : 0x00000000 A13 : 0x000001b6
A14 : 0x00000800 A15 : 0x0000002b SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000064 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffd

Backtrace: 0x400e406c:0x3ffd2720 0x400e4031:0x3ffd2790 0x400f5e30:0x3ffd27b0
0x400e406c: _fseeko_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fseeko.c:141

0x400e4031: fseek at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fseek.c:126

0x400f5e30: audio at C:/msys32/home/wellmp/esp/VIVO/soc/components/audio/audio.c:103


Rebooting...
Is it even possible to do it this way?
What is the most convenient way to store this sample?

Im new to the ESP32 and have not so much programming skills :O

I attached the Volume.raw file ( as Volume.c to upload it)

mfG Philip
Could you kindly share your code for recording using I2S?

Thanks!

Re: Store Audio Samples on Esp

Posted: Fri Jul 20, 2018 2:42 pm
by RHanda02
Can you please share your code for recording audio.