cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Read wav from USB

emetians
Associate II

Hello everyone! I'm working on a project like Audio Playback. I have tried compile and run Audio_playback_and_record from ST's Firmware pack its working good.

I'm trying create my own project file, i'm stuck in read wave data from usb. I can get waveformat data but i cant get audio data.

I have tried debug results are bellow;

Audio_playback_and_record inside audio buffer data;

0690X00000AtQ57QAF.jpg

And my own project inside audio buffer data;

0690X00000AtQ5CQAV.jpg

As you can see there is always '/0' except 0-99 indexes(that's include audio format data like wave, riff.)

I attachted my project file. Please help me.

Best Regards.

8 REPLIES 8
Ozone
Lead II

> I'm trying create my own project file, i'm stuck in read wave data from usb. I can get waveformat data but i cant get audio data.

> I have tried debug results are bellow;

Not sure what you mean.

Opening a WAV file itself is the easier part. The file format is a bit more complex, originally copied from Amiga's AIFF.

It is a container format, consisting of declarative "chunks", and the actual data chunk(s).

In total, WAV supports about two dozen encoding formats, 16 bit PCM being the most widespread.

To get the audio data, you need to properly read and interpret the "WAVE" chunk, and read the actual data according to the encoding method.

https://en.wikipedia.org/wiki/WAV

I mean, i can get waveformat data from file(FileSize, Byterate, Samplerate.. etc) but when i want read audio data i getting just zeros

Have you checked the WAV file on the host platform ?

On quick glance, I couldn't detect any WAV interpreting code in your zip.

Can you read the file as plain binary in your application, especially the PCM data ?

There is a wav file in my usb stick. I'm working for interperting on Play() function in main.c file(with f_read, f_open).

By the way thanks for support :blue_heart:

Ah, I see.

However, the code is a bit brave, I think.

You read the WAV header first without checking the content and size.

And why do your rewind to read the audio data ? The data usually start after the header.

I can read header and i've tried read data after header, that doesn't work. The point is i get receive the same data continuously as '/0'

> I can read header and i've tried read data after header, that doesn't work. The point is i get receive the same data continuously as '/0'

I assume you compared with the actual file contents.

Have you checked the return value of f_read(), and the "bytesread" variable ? Your posted code does not.

I would check, perhaps in a debugger.

I had worked with older version of fatfs a while ago.