Voice changer

What are you developing?
racemaniac
Posts: 414
Joined: Sat Nov 07, 2015 9:09 am

Re: Voice changer

Post by racemaniac » Sun Jun 12, 2016 7:20 am

RogerClark wrote:Thanks

I should be able to easily modify the code to use the DAC on the F103V
yup, remove the code initializing the i2c port, and where i send the 2 bytes to the i2c port, put the code for your DAC, and you're ready to go :)

User avatar
Pito
Posts: 1269
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Voice changer

Post by Pito » Sun Jun 12, 2016 11:20 am

There is FFT and IFFT.
1. you must have an antialiasing filter in front of ADC, as well as some filtering at the DAC output
2. the messing with spectra for that purposes works usually:
a) you have got a ping/pong buffers
b) you do ADC into the ping one (via DMA), while in parallel you mess with FFT etc in the pong one
c) when the ping is full, DMA switches automatically the ADC stream to the pong one
d) then you do FFT etc in the ping one
e) and vice versa in a loop.
That is only way how to produce a continual onfly operation of ADC->FFT->something_do_with_spectra->IFFT->DAC
This is how it works with dspic33F.. microcontrollers. I doubt it is possible with F103.. But maybe there is a trick how to do it..
With 5000Hz sampling rate for "speech" you get 0.2secs to do FFT->something_do_with_spectra->IFFT-DAC.
Quite a lot of time ;)
Last edited by Pito on Sun Jun 12, 2016 11:35 am, edited 2 times in total.
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 6130
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Voice changer

Post by RogerClark » Sun Jun 12, 2016 11:28 am

@pito

I agree.

I doubt the F103 is fast enough to use FFT for realtime audio processing.

Kinda' related...
I did a bit of research and found that STM have an application note about a vocoder using the F103, however I'm not sure they use the term vocoder to mean what I thought it meant.
The application note, discusses recording and compression of voice using the STM32

http://www.st.com/content/ccc/resource/ ... 204907.pdf

And I eventually found the example code, but it will not work with the libmaple core (or I suspect the HAL MX core) as it uses the STM32 standard peripheral lib

Anyway, just for the record here is the download page

http://www.stmcu.org/document/download/index/id-203822

User avatar
Pito
Posts: 1269
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Voice changer

Post by Pito » Sun Jun 12, 2016 11:38 am

Speex - It seems to be compression only.

But back to Voice changer>
As I mentioned above, you get 0.2secs for playing with FFT-IFFT (1024point FFT, 5000Hz sampling rate, 2.5kHz speech bandwidth, ham radio quality).
That is a lot of time.
You do 1024FFT in 3msecs, the same time you need for IFFT.
So there is 0.194secs for playing with the Spectra (filtering, reversing, etc..).
If you master the ping/pong method with F103, you can do it..
If the RAM would be insufficient with 1024FFT, do it with 512 or 256, no big difference in quality.
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 6130
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Voice changer

Post by RogerClark » Sun Jun 12, 2016 11:47 am

@Pito

I thought that the 1024 pt fft was being computed in 2mS

So FFT + IFFT would be 4mS for 1024 (I will round this to 5ms, but I know this is optimistic)

If this was cut down to perhaps 32 point FFT, and had corresponding decrease in time taken, it would yield perhaps 32/1024 x 5ms = 164uS
Round to 200uS perhaps....

Or did I get my maths wrong ?

User avatar
Pito
Posts: 1269
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Voice changer

Post by Pito » Sun Jun 12, 2016 11:56 am

Again:
When you sample ADC into the ping buffer, you need 204.8ms to fill it full (5KHz sampling rate, 1024samples).
That is the TIME you have got available for the whole FFT->messingwithspectra->IFFT->DAC process within the pong buffer.
(Because you sample the ADC via DMA into the ping AND mess with FFT in pong in parallel).
A plethora of time..
Then you reverse (when the ping buffer is full - that is signalized by DMA flag or interrupt) - you start sample ADC into the pong buffer and do FFT-IFFT in the ping - again: you have got 204.8ms for playing with FFT->messingwithspectra->IFFT->DAC process within the ping buffer.
Without loosing a single sample..
Therefore it is called Ping-Pong.

The time available for FFT->messingwithspectra->IFFT->DAC process with the Ping-Pong method is:
(1/ADC_sampling_rate) * Number_of_FFT_points
Example:
1/5000*1024 = 204.8msecs
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 6130
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Voice changer

Post by RogerClark » Sun Jun 12, 2016 12:29 pm

OK

So, we already run the ADC on DMA, and could use DMA to output to either I2C DAC or internal DAC ( on the F103RC and larger MCUs in the family)

And use 2 buffers, i.e one filling and one being processed the being output.

Yes... 200ms is loads of time.


It would be interesting, just to run such a system e.g. 1024 point fft at 5khz sampling, and listen to what the reconstructed audio, of normal speach sounds like.


To accumplish a pitch change, I presume you could just move the data so that what was in bin[n] gets moved to bin[n+ pitch_shift]
albeit this is granular.

User avatar
Pito
Posts: 1269
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Voice changer

Post by Pito » Sun Jun 12, 2016 12:38 pm

I can guarantee it will work :)
You can do with spectral lines what you want (with some limitations, subject to rocket science :) ).
You can make filters (by cutting the lines off - low, highpass, notch) or moving the lines up/down (to change the pitch], or reverse the spectra (to encrypt), or noise/denoise, mix, etc, etc. There are tons of books written about that matter :)
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 6130
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Voice changer

Post by RogerClark » Sun Jun 12, 2016 12:43 pm

@pito

Thanks

racemaniac
Posts: 414
Joined: Sat Nov 07, 2015 9:09 am

Re: Voice changer

Post by racemaniac » Sun Jun 12, 2016 6:48 pm

Pito wrote:Again:
When you sample ADC into the ping buffer, you need 204.8ms to fill it full (5KHz sampling rate, 1024samples).
How do you plan getting the sampling rate down to 5Khz?
without slowing the clock of the processor, i don't think it can be done. The code i gave is the slowest i know how to get it, and is about 35khz sampling rate, didn't find any other dividers or so i could use to get it even slower.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest