Quick & dirty audio sample mixing ?

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sampling an audio signal using the ADC and store the data in a buffer to create a delay effect.

I would like to feedback the old data pulled from RAM together with the new sample. If the gain is lower than 1 it should be fading out slowly and create an echo type of effect. The samples are 8bit wide and stored as unsigned numbers.

 

What would be a simple approach that would let me mix them together and possibly control the ratio to some degree?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you might enjoy this...there is also a link with some audio samples

 

https://www.diystompboxes.com/smfforum/index.php?topic=110730.0

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since your samples are unsigned with a range of [0..255]

they have a DC bias of 127.5.  Also it's very likely that

doing any arithmetic using 8-bit numbers would overflow

so I'd recommend using 16-bit operations.  When adding

two samples together, the DC biases add.  Scaling a sample

also scales the DC term, so you need to account for this.

 

To make these numbers easier to work with, remove the

bias before manipulating them: multiply by two and then

subtract 255.  The result will fit in an int16_t and be in the

range [-255..255].  Now you can scale (gain) and/or add

samples with no worries about DC.

 

Before converting back to 8-bit (if that's the plan), check

whether the result will fit.  If not, you can choose how to

handle the overflow.  One option is to clamp the result to

the min/max (clipping) which will produce some distortion.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

  Since you are working with 8-bit digital values, try taking the most recent sample and dividing it by two (8bitADC>>1).  Then take the delayed value (the value originally in the same mem location in the buffer) and divide it by 4 (oldSample>>2).  Then add the two together and put the result in the buffer memory location.  Increment the address pointer and repeat.

 

8-bit delays can sound surprisingly good because most instruments have their note's fundamental frequency be less than 1.5KHz.

 

Fuzz box delays can be made without using an ADC/DAC combo.  The output of a fuzz box is a 1v peak-to-peak square wave with each cycle having a different duty-cycle and frequency value.  If you amplify that signal up to Vcc and ground, then you can do 1-bit sampling (is the signal at gnd or Vcc?) at about 1500 samples per second and store eight samples into a single SRAM byte.  With a Mega328P that has 2048 bytes of SRAM, you can get long multi-second delays with lots of metallic harmonics.   Just be sure to not connect the output pin's signal (that is flipping between Gnd and Vcc) directly into your guitar amp.  Instead use a voltage divider to reduce the output delayed signal from Vcc-gnd to about 1 volt-gnd.

Last Edited: Mon. Feb 11, 2019 - 11:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Since you are working with 8-bit digital values, try taking the most recent sample and dividing it by two (8bitADC>>1).  Then take the delayed value (the value originally in the same mem location in the buffer) and divide it by 4 (oldSample>>2).  Then add the two together and put the result in the buffer memory location.  Increment the address pointer and repeat.

 

I have this implemented like so:

SRAMByteWrite((ADC0.RES >> 1) + (oldVal >> 2), delayAddCurrent);

oldVal is the value pulled from the SRAM and currently being written to the DAC.

This should create an echo effect, however the "dry signal" still needs to to be mixed using an analog circuit with the delay. This is the common practice.

But if I'm really going to lower my quality standards, the DAC write would look like the row above with the current ADC value >> 1 and the value pulled from SRAM >> 2 added together?

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

still needs to to be mixed using an analog circuit with the delay. This is the common practice.

???

 

Why in the world would you use an old school approach from the 1970's and 1980's when you have the data in a digital format?

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@DocJC

 

I'm sampling the audio is pretty lo-fi and in a case like this it is preferred to keep the dry signal analog. If I would sample in 16bits at a higher freq. (using a beefier MCU) that's another story.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not see the charm of doing such things with such a severely constrained uC.

But if you want to excersise your contortionism ordo some self flaggelation that's fine by me too.

 

I would take a uC with hardware I2S and enough ram for a decent echo buffer for something like this.

Or, if it's not battery operated, just use a EUR40 Linux SBC with audio ADC and DAC's and plenty of processing power for lots of stuff to add.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you remember the spring-based reverb units?  No  overflow errors to deal with

We'd jam with our color organs turned to full brightness & the 8-track set to auto repeat

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have one of those in stock. cheeky (different brand)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How much more complicated is digital mixing than adding 2 numbers and maybe dividing by something?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

outer_space wrote:
How much more complicated is digital mixing than adding 2 numbers and maybe dividing by something?

As mentioned, with unsigned samples, you must first remove bias, then do the sums and scaling, then restore the bias. Usually good to have a few explicit casts along the way.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]