0

I haven't started coding a section yet but was wondering if anyone had prior knowledge of a solution for this/has any sources that would be useful for it.

I'm trying to emulate tape saturation on a byte array of 44.1 Khz PCM 16 bit (little endian) audio data which has already been recorded (I have a recording class already ready and functioning). I want to distort and filter the bytes of data to emulate the sound of tape.

In theory, I'm thinking we'd need to use symmetrical soft clipping for the distortion (I've looked at the example on page 118 in this text book for digital audio FX, I just have no idea how to implement it: https://books.google.it/books?id=h90HIV0uwVsC&printsec=frontcover&hl=en#v=onepage&q&f=false) and then filter the entire signal with a low pass filter?

I'm not sure where to start on this really but if you know of any solutions that can be mapped out into a function I'd really appreciate it.

1
  • Regarding audio processing in Java, Jipes might be helpful, though it looks only like a mediocre fit for this. Regarding on how to do the DSP part, I'd ask this question on dsp.stackexchange.com Commented Mar 18, 2020 at 6:56

1 Answer 1

1

Elements needed:

  • read bytes (through AudioInputStream probably, if data isn't being held in a memory array)
  • convert audio data bytes to PCM
  • oversample
  • apply the distortion function
  • anti-alias filtering
  • decimate
  • convert back to bytes
  • output via SourceDataLine

I don't know what the best distortion algorithm might be for your purposes. There are a number of suggestions in DSP Related's free book Physical Audio Signal Processing. I recall that Stanford University's CCRMA had some interesting articles on this as well, but I don't have the links handy.

My personal favorite distortion is the tanh function. The Java code that I use for a synthesized patch that gets a fairly thick guitar-like distortion follows:

float distortVal = (float)Math.tanh(noteVal * (1 + timbreNormal * 5));

In this case, noteVal is a single PCM value. I have a variable timbreNormal ranging from 0 to 1, and am reading it from the equivalent of a foot pedal controller. The "magic number" anti-pattern value of 5 is a constant that I lazily put in. It determines the maximum amount by which the signal is amplified before applying the distortion algorithm. Whatever distortion algorithm you are using, the intensity of the distortion will depend on the degree to which you amplify the signal before applying the algorithm. If you want a more subtle effect, the "magic number" value could be set lower.

Oversampling helps a huge amount with the filtering step. I oversampled by 8, and am using a two-pole Butterworth filter. I'd have to do some significant digging to find the values used in the filter design. But I think you can get the gist of the program flow from this answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.