Hacking native 8kHz sample rates

Moderator: flatmax

Post Reply
flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Hacking native 8kHz sample rates

Post by flatmax » Sat Oct 14, 2017 2:25 pm

As pointed out here, recent changes to the I2S driver for the bcm2835 kernel mean that it is no longer possible to get native 8 kHz sample rates out of the box. Whilst it is possible to use the dmix plugin to resample to/from 8 kHz, it will increase latency. You can use a command similar to this to get software resampled 8 kHZ rates - with this example using an 8 kHz sound file named "fileName.8kHz.wav" :

Code: Select all

aplay -Dplug:dmix fileName.8kHz.wav
If you absolutely have to have low latency 8 kHz native playback, then here is on esolution, but it requires hacking !

Firstly setup your linux kernel source code and compile it : http://forum.audioinjector.net/viewtopi ... =10&t=3099

Now you should be ready to hack !

You need to edit the file :

Code: Select all

sound/soc/bcm/audioinjector-pi-soundcard.c 
In the function snd_audioinjector_pi_soundcard_hw_params change this line :

Code: Select all

return snd_soc_dai_set_bclk_ratio(cpu_dai, 1);
To this :

Code: Select all

return snd_soc_dai_set_tdm_slot(cpu_dai, 0x1, 0x1, 2, 512);
Now edit the file :

Code: Select all

sound/soc/bcm/bcm2835-i2s.c
Remove the slot count guards :

Code: Select all

		if (hweight_long((unsigned long) rx_mask) != 2
		    || hweight_long((unsigned long) tx_mask) != 2)
			return -EINVAL;
It will look something like this :

Code: Select all

		// if (hweight_long((unsigned long) rx_mask) != 2
		//     || hweight_long((unsigned long) tx_mask) != 2)
		// 	return -EINVAL;
Compile the kernel, install it ... and whalah ! You will have mono native 8 kHz sample rates :)

Enjoy
Matt
Checkout the next kickstarter campaign - the Ultra 2 : https://kck.st/2xwM3DL
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests