Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio files plays in slow mo #169

Open
crack-coder opened this issue Apr 2, 2022 · 5 comments
Open

audio files plays in slow mo #169

crack-coder opened this issue Apr 2, 2022 · 5 comments

Comments

@crack-coder
Copy link

crack-coder commented Apr 2, 2022

I was adding files to the folder to play and when I unplugged the pi I was using to move my setup, I started the pi back up and when I turned on the radio to hear the music I put on it was in slow mo. I tried all of the music I put on and I get the same result. I even dragged the wavs over to my computer and they would play normally. I didn't do anything new and the ran the same command as before and now the files don't play at full speed.

@crack-coder crack-coder changed the title auido other than demo file plays in slow mo audio files plays in slow mo Apr 3, 2022
@mouseroot
Copy link

mouseroot commented Apr 21, 2022

I was having this issue as well, even the star-wars.wav file was playing at a delayed rate, after headaches, the answer lies with the DMA setting, in the readme is says that if you use 255 it will disable the DMA channel, this fixed all my issues, hope it helps you too...

also, I was not really sure what DMA channel setting does, but for me 0, 1 gives the same slow audio, 2 seems like its a tad faster, but still too slow, i didn't get any different results from any other settings (0-15) and 15 giving no audio at all.

sudo sox NightVale_174.mp3 -r 44050 -c 1 -t wav - | sudo ./fm_transmitter -f 94.1 -d 255 -

Originally I had thought perhaps sox and even ffmpeg was not producing the proper audio formats, but using WinSCP and pulling the files onto my windows machine, the translated files were perfecly fine

infact after some digging i learned that you can use the soxi command to get a sanity check on the output of the wav files if you try to convert them first before using the transmitter, though to be honest, its kinda of easier to just use the stdin and play mp3 files instead of having to convert them first

pi@retropie:~/FM/fm_transmitter $ soxi ../sounds/star-wars.wav

Input File     : '../sounds/star-wars.wav'
Channels       : 1
Sample Rate    : 22050
Precision      : 16-bit
Duration       : 00:02:20.00 = 3087000 samples ~ 10500 CDDA sectors
File Size      : 6.17M
Bit Rate       : 353k
Sample Encoding: 16-bit Signed Integer PCM

pi@retropie:~/FM/fm_transmitter $ soxi nv2.wav

Input File     : 'nv2.wav'
Channels       : 1
Sample Rate    : 22050
Precision      : 16-bit
Duration       : 00:23:12.20 = 30697920 samples ~ 104415 CDDA sectors
File Size      : 61.4M
Bit Rate       : 353k
Sample Encoding: 16-bit Signed Integer PCM

pi@retropie:~/FM/fm_transmitter $

After this sanity check i started to dig into the existing settings and thats when i saw the DMA option.

@JadenJSJ
Copy link

@crack-coder and @mouseroot
I think i found a temporary fix, although kinda hacky it works.
It works by increasing the pitch and increasing the speed of the music.
I also found that using 44100 sample rate yields better quality, so I used it here

ffmpeg -i 米津玄師.m4a -ac 1 -af "asetrate=44100*(44100/22050),aresample=44100" -f wav -bitexact -acodec pcm_s16le - | sudo ./fm_transmitter -f 105.2 -b 230 -

@markondej
Copy link
Owner

this problem occur mainly on RPi 4, as some other hardware is messing PWM clock and DMA is triggered slower than expected. I found this may be related to ARM cores frequency governor, and by disabling it problem can be solved. Please try typing:

echo "powersave"| sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

@JadenJSJ
Copy link

JadenJSJ commented Nov 22, 2022

@markondej I am using a Raspberry Pi 3B+ and I have the issue

Please try typing:

'''echo "powersave"| sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'''

Dosen't work for me, the sound is still slowed down

I also tried using the parameter below
'-d 255'
It didn't work, it would say bus error, and exit.

@anattolia
Copy link

anattolia commented Mar 15, 2024

I had the same problem and I guess it's a sample rate frequency issue, although I don't know exactly why this happens.

My solution: to duplicate the sampleRate in the PMWController class (transmitter.cpp file) when you set the parameters of the ClockDevice.
As you can see, i literally just multiplied the value (sampleRate) by 2:

Screenshot from 2024-03-15 10-58-32-ed

After saving the changes you have to build the executable again with the make command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants