Anyone have a link to some waveforms in hex, decimal, binary or even octal, text-arrays?
Looking for the basics: tri, saw, squ, sin, etc. And maybe even a few more complex waveforms.
8-, 10-, or 12-bit would be ideal.
sounds like a fun little script to write to generate them
Yeah, I have been exploring my options and I can either write a script to produce the tables that I want or write a function that will produce the values in real time.
The decimal tables for NES are in the famitracker source code. https://github.com/HertzDevil/famitrack Source/APU
The decimal tables for NES are in the famitracker source code. https://github.com/HertzDevil/famitrack Source/APU
Thats super helpful! Thanks for finding it.
Anyone have a link to some waveforms in hex, decimal, binary or even octal, text-arrays?
Looking for the basics: tri, saw, squ, sin, etc. And maybe even a few more complex waveforms.
8-, 10-, or 12-bit would be ideal.
What encoding do you want them in? Just asking for the base in which you represent them isn't really meaningful. Do you want DPCM? PWM? Some other more complex or more application-specific encoding?
If you're looking for something like (L)PCM then you can actually just open up most/all WAV files and read that data out directly. Aside from the preamble bytes it'll just be a byte stream at the bit-depth of the WAV that you can read and copy directly.
Last edited by jefftheworld (Mar 8, 2019 8:51 pm)
You can even read a WAV header yourself to confirm the format of the data.
note: keep in mind that RIFF/WAV format files are little-endian.
First, check format value — 21st and 22nd bytes: If the value is 1, the format is PCM.
Second, check the 23rd and 24th bytes: This will be the number of channels, almost always just 1 or 2.
Third, check the 25th to 28th bytes: This will be the sample-rate as a 32-bit integer.
Fourth, check the 35th to 36th bytes: This will be the bits-per-sample.
The data itself will start at byte 55 and go until the end of the file.
Channels are interleaved in the data, so to illustrate let's look at how a 16-bit WAV with two channels would look. I'll give each value a letter — a for the first channel and b for the second — and a number representing which sample it is — the first sample would be 1, etc.
a1 a1 b1 b1 a2 a2 b2 b2 a3 a3 b3 b3 a4 a4 b4 b4
a5 a5 b5 b5 a6 a6 b6 b6 a7 a7 b7 b7 a8 a8 b8 b8
You'll see that it's actually rather easy to understand this simple PCM encoding as encapsulated by the WAV format since it's just a simple header followed by a byte-stream.
Last edited by jefftheworld (Mar 8, 2019 9:05 pm)
I'm looking for raw data to send to a PWM DAC, or R2R DAC. I have no clue on what these encoded formats are.
LIke this sine wave:
128,140,152,165,176,188,198,208,218,226,234,240,245,250,253,254,255,254,253,250,245,240,234,226,218,208,198,188,176,165,152,140,128,115,103,90,79,67,57,47,37,29,21,15,10,5,2,1,0,1,2,5,10,15,21,29,37,47,57,67,79,90,103,115
This has 64 bytes per period for example.
I over here pulling my hair out trying to program this ATtiny85. Im a hardware guy...
I'm looking for raw data to send to a PWM DAC, or R2R DAC. I have no clue on what these encoded formats are.
LIke this sine wave:128,140,152,165,176,188,198,208,218,226,234,240,245,250,253,254,255,254,253,250,245,240,234,226,218,208,198,188,176,165,152,140,128,115,103,90,79,67,57,47,37,29,21,15,10,5,2,1,0,1,2,5,10,15,21,29,37,47,57,67,79,90,103,115
This has 64 bytes per period for example.
Even with a PWM resistor-ladder DAC you can store the data in a few different ways. It really depends on your playback routine. What is your playback routine like? How does it read data and how does it control your output pins?
If you're using a 1-bit routine that wants a simple differential PWM byte stream you can use my tool below to generate that from any 8-bit WAV file and the readme has a little detail on how the playback routine would work.
oh, thanks. I'll check it out.
I have a few routines that I'm working on simultaneously to see what works. Both are accessing a data array where the sample is stored and both are using in Interrupt Service Routine to control playback speed. One is using a ring buffer which makes it pretty easy to push multiple samples into at once. The other method doesn't store the sample in volatile RAM. It is actually pretty difficult for me to understand how to get playback tuned properly.
I'm going to PM you some code and schematic for better understanding.