1
$\begingroup$

I have an MP3 decoder running on a ESP32, and I'd like to change the pitch of the streaming audio in real time.

I plan to build a little toy that streams Amazon Alexa and changes her voice so that it is higher pitched. So no pro audio requirements at all, it is just supposed to be a funny effect.

I was thinking maybe I can operate on the raw DCT data? Or is there another way that is fast enough for that chip? I cannot use time compression/dilation because the audio is streamed.

I'm using the MAD fixed point decoder.

A description of (or a link to) an algorithm working on DCT or PCM data would be fine, but code or pseudo-code in whatever language would be very welcome.

$\endgroup$
10
  • $\begingroup$ Are you wishing to preserve harmonic relationships between points in the spectrum or just shift up or down the whole lot by x? $\endgroup$
    – Andy aka
    Jan 19, 2017 at 9:14
  • 1
    $\begingroup$ explaining why Andy aka is asking: shifting in the frequency domain (i.e. adding an offset) can be done very easily by mixing with a sinusoidal (but that doesn't preserve the harmonic relationships). Compressing/streching the frequency domain would preserve harmonic relationships but takes much more effort (FFT and IFFT) . $\endgroup$
    – Curd
    Jan 19, 2017 at 9:39
  • $\begingroup$ I have a hard time answering that question because I don't really understand the differences or drawbacks. I suspect doing an FFT/IFFT would be too expensive, and basically I just want it to sound funny - if theres some distortion, thats ok. $\endgroup$ Jan 19, 2017 at 9:49
  • $\begingroup$ @MichaelBöckling to help you answer that question: Could you simply edit your original question to explain to what end / for what purpose you want to do this? $\endgroup$ Jan 19, 2017 at 10:00
  • $\begingroup$ You're right, just did that. $\endgroup$ Jan 19, 2017 at 10:15

2 Answers 2

2
$\begingroup$

Use a "phase vocoder" which will use short term FFT properties to change the pitch without changing the duration.

There is plenty of information and links to "phase vocoder" on Wikipedia and Google in general.

It is a great educational exercise to go through its operation as you learn from it the critical importance of the phase information in the FFT for proper reconstruction.

$\endgroup$
0
0
$\begingroup$

The easiest way, I guess, to change your MP3's pitch is to actually play them at a different sampling rate that the header (bits 21 & 22) specifies – that will of course change the overall duration of playback.

$\endgroup$
4
  • $\begingroup$ This might work if I just wanted to slow down, but I wanted to pitch it up and since its streaming audio (though with limited length) and I can't buffer everything I'm not sure that'll work out. But I'll try that first, just in case my assumptions are wrong. $\endgroup$ Jan 19, 2017 at 20:55
  • $\begingroup$ why only to slow down? If you fake a higher sampling rate than what was used, tones should be higher! $\endgroup$ Jan 19, 2017 at 20:57
  • 1
    $\begingroup$ I tried halving the sample rate and started to stream web radio, then the server drops the connection because I read data too slow. If I double the sample rate instead, will I not get buffer underruns because samples will be consumed faster than they come in? $\endgroup$ Jan 19, 2017 at 23:11
  • $\begingroup$ @MichaelBöckling aah I forgot about the streaming aspect; well, then things get more haiy :/ $\endgroup$ Jan 20, 2017 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.