Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help playing audio on STM32F4

Status
Not open for further replies.

shredder929

Junior Member level 3
Junior Member level 3
Joined
Jul 1, 2019
Messages
27
Helped
1
Reputation
2
Reaction score
2
Trophy points
3
Location
Massachusetts
Activity points
408
I'm trying to play audio using the ST32F407 Discovery board. I'm working off this app note.

The source files are located here under Tools & Software, named "STSW-STM32068". Project is the Audio playback & record, Flash configuration.

The sample audio is a short clip that's stored in hex on audio_sample.c. What I'm trying to do is change that to the audio I want (my cat's meow).

I've converted the mp3 I have to a 16-bit PCM, 16kHz sample rate wav file, and then used Octave to turn that into a string of hex values that I can copy paste into audio_sample.c. When I load this onto the board, all that comes out is a short, sharp squeak.

I then tried going the other way around. I took the hex data from the source file, and used Octave to write it to a wave file. The result was just a bunch of clicks.

The size difference is enormous too. My cat's meow sample is 2 seconds long, while the included audio sample is roughly 6 seconds. The text for the first is 169KB while the other is 3.6MB. What am I missing here? It seems like it should be really simple but there's some sort of mismatch I'm not getting.
 

Hi,

A lot of text, but not much facts we can work with.

16bit, 16kHz --> means 2 bytes per sample. And thus 32kBytes per second.
2 seconds make 64kBytes.
Currently we don't know whether the audio data are single channel or stereo.
(2 seconds, stereo, 16kHz, 16 bit make 128kBytes).

We don't know the data format of what you call "text file".

Then you talk about a "short, sharp squeak". How long is "short"? Is it in the range of 2 seconds or not?

We don't know about endianness.
We don't know about signed/unsigned.
16kHz is quite unusual as samling frequency (but surely possible)
********

Why don't you generate just a 1 second 1kHz signal file? Even Excel could be used.
Then you could check
* playback time
* playback sound
* playback frequency
* playback waveform ... with a scope.
It is way more informative

And you could show us the results, like a snippet from the "text file".
And a couple of scope pictures...one over the whole pkayback time, one zoomed in to see the waveform.
(hard facts)

Klaus
 

short, sharp squeak.
...
bunch of clicks.

Yes, typical results when I too experimented with digital sound processing.
Don't feel bad, it's complicated. There are 5 or so parameters (several mentioned in post #2). The parameters which are present in your file need to be identical to parameters in your playback.

Does your software allow you to examine settings? Can you change parameters before creating the recording or playing back? Test good sound files with various settings. There is more than one chance for things to be mismatch: 1) when creating the file, and 2) when setting playback parameters.
Chance of mismatch is doubled if you create the file using different software than you play it back.
 

Okay so I've made it further along, it was just a sampling frequency mismatch. I changed it from 44.1kHz to 16kHz and now it plays correctly.

However, I'm having another issue now where it plays the data I want, but then continues playing the audio that was already on-board. There's a AUDIO_MAX_FILE macro to set how many bytes need to be streamed, and I have that set correctly. I even cut that in half to test it, and instead it plays the first half of the clip, and then strangely the same amount of samples of the original audio. The original audio is still sitting there in flash, but that shouldn't matter, it's given a set number of samples to play, it should trigger the interrupt when its reached that end.

The library code in question is:

Code:
uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size)
{
  /* Set the total number of data to be played (count in half-word) */
  AudioTotalSize = Size;

  /* Call the audio Codec Play function */
  Codec_Play();
 
  /* Update the Media layer and enable it for play */ 
  Audio_MAL_Play((uint32_t)pBuffer, (uint32_t)(DMA_MAX(Size/4)));
 
  /* Update the remaining number of data to be played */
  AudioRemSize = (Size/2) - DMA_MAX(AudioTotalSize);
 
  /* Update the current audio pointer position */
  CurrentPos = pBuffer + DMA_MAX(AudioTotalSize);
 
  return 0;
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top