Play wav file from QSPI partition

Hello fellas!
I have put some wav file in the qspi partition (around 13Mb).
It works fine if I don't use the loop to write the buff to the dac like this: dac0.write(buf);
But once I put it in the loop it crashes and I have no idea why.
The code is the same of the official arduino web site here the link https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-audio/

I just removed the access to USB and add this in the setup, to use the qspi storage:

  mbed::BlockDevice* raw_qspi = mbed::BlockDevice::get_default_instance();
  mbed::FATFileSystem ota("ota");
  mbed::MBRBlockDevice ota_data(raw_qspi, 2);
  ota.mount(&ota_data);

It works fine I can read and write files or list them, indeed the next line is :

  file = fopen("/ota/ready.wav", "rb");
  if (file == nullptr) {
    Serial.print("Error opening audio file: ");
    Serial.println(strerror(errno));
    return;

Then there is the code like the example in the link, but if I put this at the end of the setup I can hear the wav playing nice:

while (!feof(file) && dac0.available()) {

    uint16_t sample_data[256] = { 0 };
    fread(sample_data, sample_size, 256, file);
    SampleBuffer buf = dac0.dequeue();
    for (size_t i = 0; i < buf.size(); i++) {
      uint16_t const dac_val = ((static_cast<unsigned int>(sample_data[i]) + 32768) >> 4) & 0x0fff;
      buf[i] = dac_val;
    }
    dac0.write(buf);
  }

But if I remove the while loop to use the main loop() like this, it does not work:

void loop() {
  if (!feof(file) && dac0.available()) {
    /* Read data from file. */
    uint16_t sample_data[256] = { 0 };
    fread(sample_data, sample_size, 256, file);
    Serial.println("Stemp1");
    /* Get a free buffer for writing. */
    SampleBuffer buf = dac0.dequeue();
    Serial.println("Step2");
    /* Write data to buffer. */
    for (size_t i = 0; i < buf.size(); i++) {
      /* Scale down to 12 bit. */
      uint16_t const dac_val = ((static_cast<unsigned int>(sample_data[i]) + 32768) >> 4) & 0x0fff;
      buf[i] = dac_val;
    }
    Serial.println("Step3");
    /* Write the buffer to DAC. */
    dac0.write(buf);
  }
}

In the log it seems it crashes at the second time it goes inside the if. I got this in the log:

Step1
Step2
Step3
And then Crash