Audio Library

Status
Not open for further replies.
Hi Paul,
Is there a way to DC offset a sine wave for use as an LFO ? (To avoid feeding negative values to a modulation input)
 
I was just thinking this morning about adding a really trivial DC signal object. I'll put it in later today.

Then you can run the DC and sine wave through the mixer to add them together.
 
I've added AudioSynthWaveformDc.

I put in a mode where it can gradually transition from one level to another. That turned out to be quite a pain, due to integer overflow on what seems like such simple math. If anyone knows a trick to subtract-then-divide, with proper results over the entire numerical range, please let me know?
 
Last edited:
If 64-bit integer is indeed too slow (do you have specific timing requirements here?), and if the nested ifs are faster, go for them. It seems like this might be a very good question for stackoverflow
 
Wow, impressive work Paul!
For my synth I developed my own envelope effect,
now you also made one my version is probably going to retire.
One question:
From your code I guess the envelope is linear.
However, I want to use exponential envelopes.
What would you recommend?
- modding your code to support exponential envelopes or
- using the envelope, waveshape it and then apply it with a multiply block?
 
A non-portable method which would speed up the handling would be to code it in an assembler macro. The macro can do the subtraction and test for overflow. That way the only complication is when an overflow occurs. I haven't figured out how to deal with the overflow yet - maybe leave that as an exercise for the reader :)

Pete
 
From your code I guess the envelope is linear.

Yup, it's linear.

It also has a limitation of 8 sample timing resolution, which allows for a highly optimized implementation with the Cortex-M4 DSP instructions. The linear ramp is updated for each sample, but each timed phase (delay, attack, hold, decay, and release) has to be a multiple of 8 samples.

I wanted to make a "default" envelope that's extremely efficient. I'm happy to accept more sophisticated envelopes into the library, with more CPU usage as the trade-off for their advanced shapes. They should be named with an extra word added on the end, to indicate what their extra features are.

However, I want to use exponential envelopes.
What would you recommend?
- modding your code to support exponential envelopes or
- using the envelope, waveshape it and then apply it with a multiply block?

Without any programming in the library, yeah, you could create any arbitrary envelope as sequence of positive integers and use a AudioPlayMemory object to stream it into an AudioEffectMultiply object to apply it. Of course, this approach will give a fixed length envelope, rather than allowing the sustain phase to continue for arbitrary times.

If you care about efficiency using the CPU, perhaps 2, 3 or 4 linear segments could be a close enough fit to the desired exponential curve? Creating a new object with more linear segments should be pretty simple.

The other alternative would be storing a lookup table of the exponential curve, and read pairs from the table and use linear interpolation (like the sine wave gen) to stretch the curve. Or if you need exponential only in the attack phase, or only in attack and decay, and fixed lengths are ok, just read a fixed table rather than computing a linear ramp.

Actually computing the exponential curve on every sample in update() is probably too expensive. But maybe a 2nd or 3rd order polynomial (with integer-only math handled well) could give a close enough approximation?
 
Last edited:
Quick questions here:

1) I will be building a (VERY) simple sound sample pattern engine for my project - is there anything "under-way" which I shouldbe aware - might be better off contributing toward?

The Dream:
I'd ultimately like to contribute it back to the project such that it can support sound samples, wavetable synths and FM synths, plus (if ram/cpu will allow) DSP /filter settings and potentially pitches etc. using the old Amiga MOD application as a goal. Whether I include MOD, ST3 (Scream Tracker) or IT (Impulse Tracker) level functionality will depend on CPU power and ram usage pretty much entirely.

For now, I'll make a 64 element sample pattern engine, like the very earliest MOD engines, but it won't support frequency functions, effects, envelopes or any of that jazz at first.

So question 2)
Will I need to add an RTC Crystal to keep musical time accurately? Or are the clocks in the chips sufficiently precise? I'd like to leave the potential open for MIDI in the future but I think this will keep in sync via an external midi master clock anyway. I'm assuming I'll be fine without it, I really don't need to know the time but I need to be sure I'm not going to drift out in case I want to sync with other devices.

I've been trying to read through this thread from the beginning....page 8 so far. Mind=mashed.
 
I'm not familiar with those old sound systems, so I really can't comment on that part.

Teensy has a pretty good crystal, probably better than the clock source in most PCs. It's probably fine for timing of musical notes for all but the most critical applications.

Something to keep in mind is the default sample rate isn't exactly 44100 Hz. It's 48 MHz / 1088. All the on-chip synthesis, like the sine wave and FM sine wave objects, is calculated with SAMPLE_RATE_EXACT, which takes this into account. But if you import raw data sampled at 44100, it will play slightly faster, shifting the pitch up slightly. If you need exact tones, best to resample your data up to 44117.76406 Hz.
 
Thanks Paul :

https://code.google.com/p/arduino-music-player/

Someone has already done a lot of work. Might think about porting to Audio, although my goal is not to play these files. We'll see....


incidentally:
Found a guy who used an atmega644 to play mods, 28 simultaneous channels at 11Khz using linear interpolation
"AVR MCU is overclocked to 32MHz from initial 20MHz so it's possible to play 12-channel trackers at sampling rate of 28kHz in 16-bit stereo with linear interpolation. Audio output from MCU is something like I2S digital stream (using TDA1545 D-A converter)."

This mean 8 simultaneous mixed channels at 44Khz is quite possible on a teensy with 3 times the CPU power, leaving headroom for other elements. :)
 
Last edited:
Amiga module player is very interesting idea :)

+1

It is, however it has been done before and is a solution designed around a problem which ceased to exist a long time ago.

This morning I conceived a different type of pattern editor which is very similar but you don't have channels/instruments you simply have up to 64 audio objects. In the future these could be synth objects with adjustable parameters.

Instead of 64 positions in the pattern you have 1024, in a single pattern buffer in the ram.

Every fire of a sample (note trigger) becomes an event (4 bytes or more depending on the type of event), and these events are queried to populate the upcoming pattern.

You only have to store as many events as your song has so it should be a fairly efficient solution but it will have a considerable pattern footprint (8192 bytes) as a base requirement

I'll detail it in the beat maker thread rather than cluttering up this one.
 
Last edited:
I'm not sure if there's another way of doing this but it could be nice to have a "Constant" object that would be a fixed value. This could be useful for objects like multiply if you want to multiply the signal by a constant value.
 
There's one thing I'm not sure is possible right now, is there a way to offset a signal in the positive range using the DC object ? (See image)
This seems like it would require an Add object.

Capture d’écran 2014-08-29 à 11.27.40.png

Edit: ah the mixer would work for this. Sorry no more questions :)
 
Last edited:
I've added a delay object, which can implement up to 8 separate taps and a total delay line up to about 333 ms (about half of Teensy 3.1's RAM).
 
I've been reading and googling; Is there any stable support for https://www.pjrc.com/teensy/W25Q128FV.pdf yet?

I see el_supremo had prototype code working which had issues working alongside the SD Card. Did those issues get resolved?

I'm absolutely drooling over 16 Mbyte of sample data. That chip will be essential to make practical use of the high quality output in real applications. Otherwise all my samples will be u-law, only because of the available ram. What a waste that woudl be, of a 44/16 12 bit DAC....

:)
 
I've added a pink noise generator.

SPI flash support is on my list.....

Edit: here's a scope view of the pink noise.

pinknoise.png

Sadly, my scope doesn't have the ability to display the spectrum's horizontal axis on a log scale, where pink noise ought to have a perfectly straight diagonal line.

I did import reference data from Stefan Stenzel's reference code into audacity and it does look very good, and I compared the binary output from the first several blocks to the reference data.
 
Last edited:
Status
Not open for further replies.
Back
Top