Store Audio Samples on Esp

partyfriend
Posts: 1
Joined: Thu Jul 06, 2017 12:44 pm

Store Audio Samples on Esp

Postby partyfriend » Thu Jul 06, 2017 12:55 pm

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
Attachments
Volume.c
(36.06 KiB) Downloaded 1109 times

kurtzweber
Posts: 64
Joined: Tue Jan 10, 2017 1:09 pm

Re: Store Audio Samples on Esp

Postby kurtzweber » Thu Jul 06, 2017 3:40 pm

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

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Store Audio Samples on Esp

Postby ESP_igrr » Fri Jul 07, 2017 2:25 am

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.

User avatar
andriy
Posts: 11
Joined: Mon Dec 07, 2015 9:14 pm

Re: Store Audio Samples on Esp

Postby andriy » Thu Jul 13, 2017 3:48 am

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!

RHanda02
Posts: 3
Joined: Thu Jul 19, 2018 8:43 am

Re: Store Audio Samples on Esp

Postby RHanda02 » Fri Jul 20, 2018 2:42 pm

Can you please share your code for recording audio.

Who is online

Users browsing this forum: Usama Masood and 65 guests