Giter Site home page Giter Site logo

Comments (15)

tfry-git avatar tfry-git commented on June 27, 2024 1

Thanks for the feedback. I have committed the following, then: f49e8d0

I assume that closes the issue, but please reopen, if it doesn't.

from mozzi.

tfry-git avatar tfry-git commented on June 27, 2024

Did you scale the audio to 12 bits on teensy? Otherwise it will simply come out too silent, and with a worse signal-to-noise ratio.

from mozzi.

tfry-git avatar tfry-git commented on June 27, 2024

Oh, sorry, did not read well. You are not using a teensy.

I don't think the SAMD21-support has received a lot of testing so far, and I'm not sure, what board it was originally developped, for. I still suspect an audio scaling issue, though 12 bits may not be the correct scaling to use. (The adafruit page mentions a 10bit DAC, but the code seems to assume 12 bits).

Experiment with scaling your audio output to 8, 10, and 12 bits, testing what sounds best. Also, you may have to adjust AudioConfigSAMD21.h, which assumes 12 bits (setting the center point to 2048).

from mozzi.

DavidHaitch avatar DavidHaitch commented on June 27, 2024

I am experiencing a similar issue. Running the Sinewave demo on a Feather M0 produced no sound whatsoever, until I changed AUDIO_BIAS in AudioConfigSAMD21.h from 2048 to 1024. Then, I got output that sounded like @gregsadetsky 's "degraded" sinewave.

@tfry-git: I would like to try and assist in testing fixes to this, but I don't know what you mean by scaling the audio output to different bit widths. I thought Mozzi always used 16 bits?

from mozzi.

gregsadetsky avatar gregsadetsky commented on June 27, 2024

Wow, it works!!!! Setting

#define AUDIO_BIAS ((uint16_t) 512)

works!! :-)

Thank you so, so much!

Should there be a pre-processor directive, or additional documentation about this?

from mozzi.

DavidHaitch avatar DavidHaitch commented on June 27, 2024

@gregsadetsky I am also working with a Feather M0, and I am unable to replicate your success. Even after setting AUDIO_BIAS to 512 in AudioConfigSAMD21.h, I still get a Sinewave that sounds like your degraded one.
Could you share the code that worked for you?

from mozzi.

gregsadetsky avatar gregsadetsky commented on June 27, 2024

I will take a look again, but I do remember the change being just what I posted above (the #define line).

Just to be sure (as this was a bit confusing to me initially), did you change the value in the AudioConfigSAMD21.h file that's within the Arduino library directory, or did you download a fresh copy of Mozzi that you included in your project directory, and made the change there?

I'm simply asking to make sure that you did the change in the code that was indeed compiled. Out of curiosity, if you delete the Mozzi directory where you did the change, does that create a compilation error?

Also, I remember trying much smaller values than 512 for fun and it did end up creating a "bit crushing" audio effect (a similar-ish distortion to what I posted). Could you try that (256, 128, etc.), just to make sure, again, that your changes in AudioConfigSAMD21.h are being taken into account? Cheers

from mozzi.

tfry-git avatar tfry-git commented on June 27, 2024

@DavidHaitch

I would like to try and assist in testing fixes to this, but I don't know what you mean by scaling the audio output to different bit widths. I thought Mozzi always used 16 bits?

Unfortunately, Mozzi does not always use 16 bits. For instance on the classic AVR architectures, it uses just over 8 bits, an STM32 it uses 10 bits, and on ESP8266 it uses 16 bits. You will always have to make sure that your updateAudio() returns the correct range of values for your configuration. This is not easy to fix, but see #43 for one idea (and more background).

This might also be the reason why your sinewave still sounds distorted. Make sure updateAudio() returns values between -511 and 512.

@gregsadetsky

Should there be a pre-processor directive, or additional documentation about this?

Definitely. Do you think there is a compiler defintion that will identify the Feather M0, realiably? Then this could be used in AudoConfigSAMD21.h, as appropriate.

from mozzi.

gregsadetsky avatar gregsadetsky commented on June 27, 2024

@tfry-git

Definitely. Do you think there is a compiler defintion that will identify the Feather M0, realiably? Then this could be used in AudoConfigSAMD21.h, as appropriate.

There's an ADAFRUIT_FEATHER_M0 flag/constant that - as far as I understand - comes from adafruit_samd's boards.txt: ... extra_flags=... -DADAFRUIT_FEATHER_M0.

adafruit_samd needs to be installed (see here) in order to use the Feather M0 family of boards with the Arduino IDE.

As an example, you can see this constant used here, for a Feather M0-based board with built-in radio (this one).

from mozzi.

DavidHaitch avatar DavidHaitch commented on June 27, 2024

@tfry-git I think I've found another possible issue.
On line 518 of MozziGuts.cpp, the IS_SAMD21() case sets analogWriteResolution to 12 bits, even though the DAC on the SAMD21 is 10 bits.

According to the analogWriteResolution docs, setting the resolution to something higher than the hardware's actual resolution results in the remaining bits being dropped - only the first 10 are actually used. I don't have access to the hardware right now, but is that a possible problem?

from mozzi.

tfry-git avatar tfry-git commented on June 27, 2024

Yes, this is a possible problem. But it's really hard to fix this kind of problem, without having the hardware to test (and I don't that that, either).

from mozzi.

tfry-git avatar tfry-git commented on June 27, 2024

Hi!

Sorry for dropping the ball on this one. I have committed an experimental fix for this. Could you please do

git pull
git checkout testing/SAMD21_analog_resolution

and then test with that? If it works, I can merge this into the official branch. In theory this should now work out of the box (you'll still have to make sure updateAudio() returns values in the +/-512 range).

Thanks!

from mozzi.

infovore avatar infovore commented on June 27, 2024

I've been working with a SAMD21 and have run into this issue too. @tfry-git's solution in the branch is correct for all SAMD21 chips.

The SAMD21 only has a single 10-bit DAC on it. (Its _ADC_s are 12-bit, however). This includes the Gemma M0 that support is listed for - that only has a 10-bit DAC output.

I'd put together my own PR but it seems a relatively straightforward fix...

from mozzi.

infovore avatar infovore commented on June 27, 2024

Looks good - only other thing you might want to change is AnalogWriteResolution in MozziGuts.cpp, line 542. I didn't find this made any difference, but it's one thing I could think of.

from mozzi.

infovore avatar infovore commented on June 27, 2024

👍

from mozzi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.