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

nrf: Add i2s audio output #2127

Merged
merged 7 commits into from
Sep 10, 2019
Merged

nrf: Add i2s audio output #2127

merged 7 commits into from
Sep 10, 2019

Conversation

jepler
Copy link
Member

@jepler jepler commented Sep 8, 2019

Testing performed: I used a Particle Xenon with a HDA1334 I2S DAC. I played a variety of mono 16-bit samples at 11025 and 22050Hz nominal bit rates. With this setup, all the 11025Hz samples sound good. I tested play, pause, and loop functionality.

During some runs with 22050Hz samples, there were glitches. However, these may have only occurred during runs where I had set breakpoints and watchpoints in gdb.

I also tested with a MAX98357A I2S amplifier. On this device, everything sounded "scratchy". I was powering it from 5V and the 5V rail seemed steady, so I don't have an explanation for this. However, I haven't tried it with a SAMD board.

Testing performed: I used a Particle Xenon with a HDA1334 I2S DAC.
I played a variety of mono 16-bit samples at 11025 and 22050Hz nominal
bit rates.  With this setup, all the 11025Hz samples sound good.
I tested play, pause,  and loop functionality.

During some runs with 22050Hz samples, there were glitches.  However,
these may have only occurred during runs where I had set breakpoints
and watchpoints in gdb.

I also tested with a MAX98357A I2S amplifier.  On this device, everything
sounded "scratchy".  I was powering it from 5V and the 5V rail seemed
steady, so I don't have an explanation for this.  However, I haven't
tried it with a SAMD board.
@C47D
Copy link
Collaborator

C47D commented Sep 9, 2019

I had used those MAX98357A amplifiers at work and had problems with them at the beginning, by any chance did you captured the I2S traffic with a logic analyzer?

My problem was because I didn't removed the bit clock before removing the LRClock (WSCLK).

@jepler
Copy link
Member Author

jepler commented Sep 9, 2019

@C47D the "scratchy" audio with MAX is while a sample is playing, so I don't think this is the cause. However, I'll attempt to capture a scope trace of the end of playing and look for problems.

@C47D
Copy link
Collaborator

C47D commented Sep 9, 2019

@jepler Noted, I did work with an STM32 microcontroller on that project and had to use double buffers to play the audio, didn't took a look at your implementation, maybe it's different for the Nordic device, which I'm not (yet) very familiar with the I2S and DMA peripherals.

@ladyada
Copy link
Member

ladyada commented Sep 9, 2019

@jepler what's it look like with a sine wave playing? you can put an RC filter on the speaker outputs to scope it - also maybe post a pic of your setup?

@tannewt tannewt self-requested a review September 9, 2019 22:25
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall nice work! I tested it using the UDA1443 and the nrF52840 FeatherWing with the sine sample: https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a/circuitpython-wiring-test

Screen Shot 2019-09-09 at 4 19 56 PM

I did the same test to compare with the Feather M4 and it did way worse. I could hear the tone but it wasn't as loud or as clear as the nRF. So hopefully you don't mind working on I2S. :-)

Screen Shot 2019-09-09 at 4 21 20 PM

Just a couple code comments and then it should be good to merge. Thanks!

ports/nrf/common-hal/audiobusio/I2SOut.c Outdated Show resolved Hide resolved
ports/nrf/common-hal/audiobusio/I2SOut.c Outdated Show resolved Hide resolved
.. based on some tasks I found that caused stuttering:

 # Test SD and printing
 while True: os.listdir('.')

 # Test bulk I/O
 while True: len(open('somefile.wav', 'rb').read())

Each of these tasks *WAS* worse and I am improving them in a separate
PR by adding RUN_BACKGROUND_TASKS to them.
@jepler
Copy link
Member Author

jepler commented Sep 10, 2019

@tannewt I have attempted to address your review comments. Thank you!

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the refactor and added comments. Please mark comments as resolved as you address them next time. Thanks!

@tannewt tannewt merged commit 89fed70 into adafruit:master Sep 10, 2019
@rdagger
Copy link

rdagger commented Oct 29, 2019

I've been having problems with I2S on the Feather nRF52840 Express running CircuitPython 5.0.0-alpha.4-260-g2b02750f1 (2019-10-26.)
I'm using an Adafruit I2S 3W Class D Amplifier Breakout - MAX98357A (PRODUCT ID: 3006).
I've been using the example programs and here are some issues:

  1. The sine waves only work well at certain frequencies. Some frequencies causes the Feather to reboot in safe mode. Other frequencies have very rough waves.
  2. Often after an I2S program completes without errors, the Feather will reboot a few minutes later.
  3. WAV files have to have a frequency of 22050Hz and 16 bits per sample or else they are garbled.

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

Successfully merging this pull request may close these issues.

5 participants