cancel
Showing results for 
Search instead for 
Did you mean: 

Digital Audio Effects - Wave file issue

dbilancione
Associate II
Posted on August 12, 2013 at 04:06

dear all. I hope this finds you well. I am trying to implement digital audio effects on a development board featuring a STM32F407ZG processor. I have never used it before but I managed to build the driver for the audio codec, the usb and 512KB SRAM looking at the firmware examples provided by ST. so far, so good ... and it gets better ... I can read a wave file from the usb and play the actual PCM raw data (2 channels, 48kHz sample rate, 16-bit per sample). the DMA controller transfers the data from the memory to the audio codec (just like the Audio playback and recording using the STM32F4DISCOVERY - AN3997): two buffer are read from the wave file so while the DMA controller transfer buffer1, I can work on buffer2 and vice versa. now, the PCM raw data from the wave file are 16-bit samples, 2's-complement signed integers, ranging from -32768 to 32767. I normalize this range between -1 and 1 as I wish to do some filtering but simply converting the samples and then converting them back to the 2's-complement signed integer range thus playing back the resulting audio data and I get a noisy signal. I can still hear the audio but it's noisy. Is there something I have missed? Thank you!

#wave-playback
18 REPLIES 18
saviphagura
Associate II
Posted on April 20, 2014 at 03:40

I've been using the Audio Playback and Recording example, and normal playback works fine. However I am trying to implement a couple of processing methods to the signal (bandpass, stuttering, etc).

If I set every other value in the buffers (buffer1 and buffer2) to 32768, I can have audio going to only one channel. However, if I take that value and do anything else to it (divide it in half for example), I just hear a lot of static noise and the original audio as well, and it sounds the same whether I divide that value or clip it at certain points, etc.. This is the first time I've tried anything with audio, so my understanding of the topic is very low, but I really need to get this done and have been completely stuck here all week.

uint16_t buffer1[_MAX_SS] = {0x00};
uint16_t buffer2[_MAX_SS] = {0x00};
f_read (&fileR, buffer1, _MAX_SS, &BytesRead);
// I am trying to edit the values in buffer1 and buffer 2 here, before Audio_MAL_Play function
// Something simple as a for loop, setting buffer1[i] = buffer1[i] / 2;
// This just causes a lot of static like noise output
Audio_MAL_Play((uint32_t)buffer1, _MAX_SS);

Any suggestions would be greatly appreciated. I really need to get this done and I just can't get past this part.
Posted on April 20, 2014 at 03:57

Are you sure that f_read() is doing what you want? Seems to me that it's reading _MAX_SS BYTEs not WORDs

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
saviphagura
Associate II
Posted on April 20, 2014 at 04:16

Obviously I missed that... I have been reading on the properties of a .wav file, but it's still very fuzzy to me.

If it's reading bytes and not words, I am still uncertain of

how to iterate through those buffers and convert the bytes to PCM data  ( given a stereo audio file, at 11025Hz). I will research more into that, but if you can point me in the right direction or can walk me through it, that would help so much!

Posted on April 20, 2014 at 07:01

Wave files come in many formats, what exactly is the format of the one you're using? What is the sample size?

Stereo files have the left and right channels interleaved.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
saviphagura
Associate II
Posted on April 20, 2014 at 09:06

It's a 16-bit PCM .wav file, at 11.0 kHz. I have double checked that with Audacity. It's actually been difficult to find an audio file in the correct format which is long enough to demo; either it's not in PCM format, or not long enough, etc. 

The channels are interleaved; as I mentioned, if I set every other value in the buffers to 32768, that seems to almost zero out one channel (though there is still very low sound from that channel). It's whenever I change the buffer values in other method that I get a lot of static and such. 

Just to clarify what I mean by changing the buffer values, I try something such as looping through the buffer and setting ''buffer1[i] = buffer[1] / 2;'' That causes a VERY noisy output, where as I would expect the output to be possibly quieter but not full of static noise. 

I may just be approaching the values in the buffer completely wrong, and misunderstanding what they actually represent and how I should process the audio, but again I have no experience working with audio and am beyond worried about getting my project completed on time.

zzdz2
Associate II
Posted on April 20, 2014 at 09:15

uint16_t buffer1[_MAX_SS] = {0x00};
uint16_t buffer2[_MAX_SS] = {0x00};

These should be signed integers.
saviphagura
Associate II
Posted on April 20, 2014 at 11:00

That's how the example provided by ST had them as. I will try changing those to signed.

Posted on April 20, 2014 at 14:23

That's how the example provided by ST had them as. I will try changing those to signed.

That is probably for the purpose of managing the buffer, but the number space within the audio is signed. This differs with 8-bit values which are offset, rather than 2's complement.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bougarech
Associate II
Posted on April 05, 2015 at 11:44

Hi clive. It seems that I have the same problem with audio PlayBack and record ST application. I'm trying to filtring an audio signal using this demo so I implement Filtring Function in waveplayer.c and i call it between f_read (&fileR, buffer2, _MAX_SS, &BytesRead) and Audio_MAL_Play((uint32_t)Fsignal, _MAX_SS);

the output signal is very noisy and with a considered delay. the delay may be explain by the structure of the filter as I implement an IIR with direct form structure but this cannot explain the noise. I wonder if I had to call the filtring function in DMA interrupt routine but I can't find it in the demo application.