-
Notifications
You must be signed in to change notification settings - Fork 190
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
VS10XX as DAC #231
Comments
Just a note that I have generic audio output and input working with the nano (both 1003 and 1053) just not with mozzi. |
Two steps involved:
in mozzi_config.h. Now you are fully bypassing the Mozzi buffer, which means you can (and will have to) take care of intermediate buffering, yourself. You will have to define two functions in your sketch:
An implementation (totally untested) might perhaps look something like this:
If you get things to work, we'll be interested in adding your code as an example! |
Ah, ok. I thought I might have to override the native buffer, but wasn't sure. Thanks a bunch. I'll work my way through this tomorrow! |
On question, this retains the updatecontrol and loop audiohook structures, correct? Just bypasses the buffering? |
Could not have said better than @tfry-git !
Edit: Thinking about it, not sure my solution works, as |
Yes! |
@tfry-git I guess my question on the usage of |
Ok, I'm getting errors
Source is here: https://github.com/poetaster/VS1003/blob/master/examples/vs1053_wavcpm_sine/vs1053_wavcpm_sine.ino This version has a cbuf implementation in it, since that's the approach that worked in other cases (non-mozzi). Trying:
won't work without a cast to char and I thought I'd try what worked in other contexts firxt. |
That's a bug in the AVR port. Do you have your Mozzi installed from git (or are you willing to try that)? Then we could talk you through switching to the devel/Mozzi2-branch. This should work there (after I've just pushed some fixes; you're doing some pioneer work, here). Instead of editing mozzi_config.h, you'd put the following at the top of your sketch (above any other Mozzi includes):
The remainder of the sketch should work unchanged (if you haven't done anything unusual, that is).
Yes, that makes sense. |
Some additions though, after actually looking at your sketch:
Background: audioHook() in your case is essentially doing (skipping some detail):
|
Ok, I switched to devel/Mozzi2, and added the includes/defines. Without changing anything else I get: I'm not sure I grok the the logic. I was trying, But I just spotted 2 errors ... The dac writes do block until the DREQ pin comes up. Writing to the dac:
|
If I understood the logic correctly it reduces to:
|
just pulled latest commits on dev/Mozzi2 and the error does go away if I:
|
Ah, I had the old MozziGuts include in, maybe that was the problem :0 |
Typing from my mobile.
You still need to provide updateAudio(), too (where thhe Samples are produced).
|
Sorry, just spotted that remark. I can set the frequency and that seems to be a non-issue:
|
Ok. I'm working on getting rid of the cbuf hack to make sure that doesn't get in way. |
That should not be the problem. Based on what you posted about the routines for writing to the DAC:
|
Ah, ok, I think I get what you meant before. I had not thought of just putting it in the loop. Thanks! |
I am more a spectator here, but I wonder, for cleanness, if part of that code should actually be in the
This only has the advantage of keeping the |
Ok, both work for me, but negelect that I'm actually copying from the cbuf to a 32 byte buffer which then get's sent 'whole'. But otherwise, looks like it could go. I have to rework the driver some more since I'm getting into conflicts over who controlls the spi bus :) |
Ok, I've have compiling and can't even get a hello world serial output. I've tried removing the cbuf method. But something is broken. Other mozzi (unaltered) sketches 'just work' and the driver (without mozzi) works. Where should I start to debug this. |
In such cases, I usually try finding out what parts of the code get reached, e.g. by toggling the LED_BUILTIN pin. Serial is also an option of course, but beware that Serial does not transmit, instantly. You may want to add Serial.flush() to get more reliable info. If you post an example, we can look at that, too. The smaller the better (and sometimes, the process of minimizing helps understand what's going wrong, in the first place). |
Ok, I just took a PT8211 and wired it to the nano (digi 6 not 5) and that seems to work fine with the Mozzi2 branch. It's noisy, though. Not sure what the artifacts are. In any case:
Works. Is it possible that not defining the number of channels was the issue with my sketch? I found a bug or two in my ripped cbuf but had taken that out of the way anyway. |
Ok, I'm getting closer, but keep simplifying. Just for reference, here is a non-mozzi, very crappy write a sine wave out to dac. I'm reworking the CircleBuffer and just hacked this together: After starting the VS (hardcoded write_register(SCI_AUDATA,16384); ) the WAV/RIFF header is sent and that patch pounds a nasty approximation of a sinewave with no control at the dac. Ugly. But it works. I'll keep trying some primitive variations of this with the mozzi variant WITHOUT circumventing the buffer. So,
|
BTW, the reason this is in a VS1003 context is that for playing PCM, either chip 1003/1053 will behave the same way with the same setup. Which is nice. That old driver is the very minimal needed for audio out with PCM. Hence the choice to start there. |
Not sure if any of these are of interest:
|
Just a quick note. I'm going to try this on a pi pico since I don't believe I'll have the processing power and ram on a nano. However much I love that machine, 3 different circular buffer types and I'm at writing assembler. And I still won't have enough ram. So, I'll get back to this thread when I've tried on a pico. |
Sigh. Well, the pi pico experiments aren't much better :) pschatzmanns tools and drivers didn't help me, though, with his driver my crappy direct to dac sketch works: https://github.com/poetaster/VS1003/tree/master/examples/vs1053_wavcpm_sine_nomozzi_pico But, frankly, I can't get reliably audio on the pico either. I've done some radical reductions like:
(pico), but that doesn't work. That DOES work with two types of osc. One is just values from a table and the other is an osc. object (stolen from bela). But my crappy approaches feed to the DAC just fine (with the ancient 1003 driver on arduino 328 or the newer 1053 driver on RP2040). Not sure what to do, but I thought I'd try going back to mozzi 1.1.2 and test there. |
Not sure if I understand you correctly. What you're saying is: You can get some very simple audio output going along these lines, but as soon as your output gets any more complex, it stops working? (How exactly does "doesn't work" show?) That pattern would actually make a whole lot of sense: The code you show buffers 32 bytes of data, then essentially blocks until it can write them all at once, leaving an empty buffer. If your audio generation is minimal, it may be fast enough to avoid a buffer underrun, but that will easily be exceeded with anything even slightly more complex. I think at the minimum, your loop() should contain a check for |
No, it's not a matter of complexity, per se. On the nano I've only been with and without mozzi. There, I can generate any kind of waveform (also with an osc. object ) and feed it to the dac. The simple form being read from table (with offset) and only playchunk when the mp3buff is full. That works. But not with mozzi. On the RP2040 the issues are compounded by there being a bug (working on it) in the 1053 driver which is not the same one I'm using on the nano.
I've removed all blocking in the sketch and on the nano made sure the driver is running at rates that nano can supply. Seems ok (tested 8000 - 16 000).
The driver, handles that buffer logic. #231 (comment) |
But, in short, you think I'm getting buffer underruns? But those would only lead to choppy sound, not to NO sound, or? If I do serial output in the simple sketch, the sound get's choppy fast. |
Hi,
So to summarize, the problem seems to be how to get samples from Mozzi into your buffer. As: you manage to correctly transfer the content of the buffer to the DAC right? The way I would approach this problem would be first to try to make the DAC play from a buffer that is not actuated by Mozzi: fill it with 32 recognizable samples in setup (16 at max value and 16 at min value), and get it transfer while Mozzi is started (maybe in Then, if that works (DAC and PWM output something reasonnable), I would switch to a Next step would be the same, but with bypassing the buffer and using yours for If all of that works, sending the buffer to the DAC should be possible. The idea is to first test that there is no hidden conflict, then that the buffer implementation is working correctly. Not sure if that helps… Not really related but as you mentioned it: the PT8211 is a cheap DAC but you can manage quite good sound quality with it. The crux is that it is nowhere stabilized, hence you should provide it a quite clean voltage source. This is especially true if you are powering the board via USB, which is extremely noisy. It also benefits with filtering the output. I managed some quite good results with the setup here, but this is powered by battery which also helps! |
I have a number of different types of boards. Purchased in China, they're about 8 euros. I'd be happy to sponsor Mozzi with one or two of these. The 1053 is nice since it also has stereo in and general midi instruments on board :) Let me know, and I'll send a board.
Yes. I simplified so far that on the loop a sample to the buffer and simply send and reset if I have 32. That works fine. Building a proper Circular buffer has proven to be more of a challenge :)
I did try something like this, but will do so again, more methodically. I also thought: ' why not just let mozzi bang at the dreq pin once the codec is up :) In theory it should work :)
Check.
Check.
Yes, I had thought that there maybe a conflict with the use of SPI. The drivers I'm using do some locking on the SPI side (to avoid contention) and that occured to me could be an issue. But, I'll go through the above outline first.
I took a look at the spec sheet for the PT8211 and they do 'require' some more filtering. I think the 5012 based boards, at 2 euros more, are better isolated and less of a problem. But I need to do some more testing. I'll try the PT8211 again when I've gotten farther with this. Thanks! |
Ok, so first test with mozzi after driver test:
The first chunk of audio (hello!) plays. Delay, and after startMozzi, the second attempt fails. The send_header() command is executed by the module but it's unclear if it get's to the dac. So Mozzi is doing something odd. If I start mozzi first, no sound. |
Thanks for the test! Is this on the Nano? Thanks for the DAC references btw! I looked some time ago for other type of DAC, but could not converge… Nice to have some advice from a DIYer! |
That test was with pico and the VS1053Driver from pschatzmann. But it's the same(with Mozzi2) on the Nano and other drivers.
ah, I need to look at the guts :) I'm using https://github.com/pschatzmann/arduino-vs1053 on the pico and this one, https://github.com/maniacbug/VS1053 (smaller footprint, less features) on the nano.
I need to test this again, but I have one I2S interface that has really clean audio even with usb power (it's a 5102a with phone and headphone outs). I'll try to put some more time into that since it's my default out DAC. |
This is the DAC probonopd/MiniDexed#279 (comment) I mean. |
I've been using the VS1003b and VS1053b for a bunch of different 328 projects since they are really flexible. Midi stuff 'just works'. But simple PCM output, I'm stuck at feeding from the mozzi output buffer. The general approach on the VS1053 is to feed from a buffer in 32 byte chunks. You begin with a header:
borrowed from: https://github.com/jeroenlukas/KitchenRadio/blob/master/src/kr_bluetoothsink.cpp
And then simply play chunks from the buffer, something like this:
I'm stuck at how I get the data uint_8 data from the mozzi buffer and directly stream from the buffer. Once the WAV header has been set, I should be able to just push 32 byte long chunks of PCM data to the chip. I need to see if the nano lags, but first things first. Any tips? Thanks!
The text was updated successfully, but these errors were encountered: