Comments (5)
The standard Circle I2S driver is not compatible with this device and I think it needs the following modifications:
-
The master clock (MCLK) must be 4 times greater than the serial bit clock (SCLK), which is normally provided by the driver. That is 384 times the sample rate.
-
The width of two channels must be exactly 48 bits. Normally the driver uses two 32 bits (total 64 bits) channels with 24 bits data each. This is not supported here.
These modifications should be applied by the following patch, which is based on Circle 44.5 from master branch:
diff --git a/lib/i2ssoundbasedevice.cpp b/lib/i2ssoundbasedevice.cpp
index ab6194e..674eec7 100644
--- a/lib/i2ssoundbasedevice.cpp
+++ b/lib/i2ssoundbasedevice.cpp
@@ -35,7 +35,7 @@
#include <assert.h>
#define CHANS 2 // 2 I2S stereo channels
-#define CHANLEN 32 // width of a channel slot in bits
+#define CHANLEN 24 // width of a channel slot in bits
//
// PCM / I2S registers
@@ -114,11 +114,10 @@ CI2SSoundBaseDevice::CI2SSoundBaseDevice (CInterruptSystem *pInterrupt,
unsigned nClockFreq =
CMachineInfo::Get ()->GetGPIOClockSourceRate (GPIOClockSourcePLLD);
assert (nClockFreq > 0);
- assert (8000 <= nSampleRate && nSampleRate <= 192000);
- assert (nClockFreq % (CHANLEN*CHANS) == 0);
- unsigned nDivI = nClockFreq / (CHANLEN*CHANS) / nSampleRate;
- unsigned nTemp = nClockFreq / (CHANLEN*CHANS) % nSampleRate;
- unsigned nDivF = (nTemp * 4096 + nSampleRate/2) / nSampleRate;
+ assert (32000 <= nSampleRate && nSampleRate <= 48000);
+ double fDiv = nClockFreq / 384.0 / nSampleRate;
+ unsigned nDivI = fDiv;
+ unsigned nDivF = (fDiv - nDivI) * 4096.0 + 0.5;
assert (nDivF <= 4096);
if (nDivF > 4095)
{
@@ -304,11 +303,11 @@ void CI2SSoundBaseDevice::RunI2S (void)
// enable channel 1 and 2
write32 (ARM_PCM_TXC_A, TXC_A_CH1WEX
| TXC_A_CH1EN
- | (1 << TXC_A_CH1POS__SHIFT)
+ | (0 << TXC_A_CH1POS__SHIFT)
| (0 << TXC_A_CH1WID__SHIFT)
| TXC_A_CH2WEX
| TXC_A_CH2EN
- | ((CHANLEN+1) << TXC_A_CH2POS__SHIFT)
+ | (CHANLEN << TXC_A_CH2POS__SHIFT)
| (0 << TXC_A_CH2WID__SHIFT));
write32 (ARM_PCM_RXC_A, RXC_A_CH1WEX
These modifications are for I2S output only. You can use standard sample rates of 44100 and 48000 Hz, not more because the clock generator with MASH can generate a maximum frequency of 25 MHz.
I wasn't able to test this without hardware, of course. If it doesn't work, we have to rethink this.
from circle.
I tested these modifications on the hardware, but doesn't work as expected.
What i found when trying sample 34-sounddevice:
Changing CHANLEN, clock speed, and Write in RunI2S:
No sound
only changing clock speed:
440hz tone sounds much higher pitched, and distorted
only changing CHANLEN, Write in RunI2S:
No Sound
No changes:
440hz tone pitch sounds correct, but distorted
This makes me think the clock is fine. Is it perhaps the order of MSB and LSB that are different? I seem to recal having similar distortion in an old esp32 project that had the wrong i2s format settings.
from circle.
According to this datasheet pg. 119 the bit order is MSB to LSB in the Raspberry Pi I2S peripheral, which is the same as noted in the Pmod I2S2 Reference Manual, you have referenced above.
Unfortunately I think, my assumptions were wrong, we cannot generate MCLK with the I2S peripheral in the Raspberry Pi, because the serial bit clock is not only presented via the GPIO pin, but is also used to shift the data in the peripheral. I think we need a second separate GPIO clock for this purpose. I do not know, if this will work, because this second clock wouldn't be synchronized with the SCLK signal and the data, coming from the I2S peripheral, but we could try. Let me think about this until tomorrow.
from circle.
Thx Rene, but if it's too much trouble for the implementation then let's move on. I just need to find a reasonable high quality i2s DAC + ADC for my sampler project. If this is too difficult/exotic to get working, I'd rather put my efforts in getting the audio injector octo running. Two years ago when I started working with Circle I got it to work in 2ch mode using some existing code for a vGuitar rig made by Patrick on Hackaday. If I want to use all of the 8ch out and 6ch in, i'll have to try and implement TDM in Circle, which i'm afraid is above my capabilities but I can try. Patrick ported Paul Stofregen's Teensy Audio Library to Circle, and that had TDM support, and believe he got it to work with Circle. Maybe i can try to reverse engineer/hack it into Circle.
from circle.
OK, no problem. I think continuing here would only be of interest for Circle, if there would be many potential users of the Pmod I2S2 on the Raspberry Pi, but I did a search in the forums and found only one user. Good luck for your plans with the Teensy Audio Library port, and thank you for using Circle!
from circle.
Related Issues (20)
- aarch64-none-elf-g++: fatal error: '-fuse-linker-plugin', but liblto_plugin.so not found compilation terminated. HOT 5
- Pi Zero 2 W failing to Initialize WLAN HOT 2
- CTimer delays busy-spin the processor HOT 2
- Advice Needed: REST framework HOT 1
- release-45.2 usb samples compile with errors HOT 2
- TCP Connection in Interrupt HOT 2
- I2C feature request: add support for repeated start HOT 6
- USB CDC/ACM gadget HOT 19
- GetClockTicks without wrap HOT 3
- GPU support on Raspi 4 HOT 4
- Circle linker failure with softfp HOT 2
- Make USB gadget vendor and device strings configurable HOT 2
- Support for touchscreens with additional reports in HID descriptor HOT 7
- Question about log when testing with Qemu HOT 2
- Help with setting PREFIX HOT 4
- Question: Waveshare 5'' DSI display support? HOT 2
- Waveshare 15.6inch Capacitive Touch Screen HOT 2
- Can I run OpenCV? HOT 2
- Sample "07-usbstorage" fails with Pi5 HOT 8
- Unsuportted USB touch screen driver - Big Tree Tech HDMI7 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from circle.