1

I would like to make an app (Target pc windows) that let you modify the micro input in real time, like introducing sound effects or even modulating your voice.

I searched over the internet and only found people telling that it would not be possible without using a virtual audio cable.

However I know some apps with similar behavior (voicemod, resonance) not using a virtual audio cable so I would like some help about how can be done (just the name of a library capable would be enough) or where to start.

BraisRV
  • 21
  • 1
  • 4

2 Answers2

0

The linked tutorial worked for me. In it, a sound is recorded and saved to a .wav.

The key to having this stream to a speaker would be opening a SourceDataLine and outputting to that instead of writing to a wav file. So, instead of outputting on line 59 to AudioSystem.write, output to a SourceDataLine write method.

IDK if there will be a feedback issue. Probably good to output to headphones and not your speakers!

To add an effect, the AudioInputLine has to be accessed and processed in segments. In each segment the following needs to happen:

  • obtain the byte array from the AudioInputLine
  • convert the audio bytes to PCM
  • apply your audio effect to the PCM (if the effect is a volume change over time, this could be done by progressively altering a volume factor between 0 to 1, multiplying the factor against the PCM)
  • convert back to audio bytes
  • write to the SourceDataLine

All these steps have been covered in StackOverflow posts.

The link tutorial does some simplification in how file locations, threads, and the stopping and starting are handled. But most importantly, it shows a working, live audio line from the microphone.

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41
  • Actually I want output to mic, not the headphones or speakers. That it's what the example apps I mention do. It's that possible with SourceDataLine? – BraisRV Mar 29 '20 at 03:31
  • Do you want the microphone to be used as a speaker? From your question description I assumed that you wanted to apply affects to sounds coming in from a microphone, in real time. Can you show a link of the example apps? I don't know if the microphone line will accept data, I suppose it might. If it does, I assume that a SourceDataLine would be the way to write to it. – Phil Freihofner Mar 29 '20 at 07:12
  • That's exactly what I want. http://resanance.com/ https://www.voicemod.net/ – BraisRV Mar 29 '20 at 13:27
  • I don't think that is what either of these applications you linked do, though. Data from the mike's line is being processed, in some cases, with granule-based transforms to achieve frequency shifting or with digital filters or other somewhat computationally advanced functions. Then the data is then output through the speakers. Java can do it, and do it well, but C-based languages are more often chosen for this level of digital signal processing for commercial products. – Phil Freihofner Mar 29 '20 at 18:27
0

Firstly, you can use professional ready-made software for that - Digital audio workstation (DAW) in combination with a huge number of plugins for that.

See 5 steps to real-time process your instrument in the DAW.

And What is (audio) direct monitoring?

If you are sure you have to write your own, you can use libraries for real-time audio processing (as far as I know, C++ is better for this than C#).

These libraries really works. They are specially designed for realtime.

https://github.com/thestk/rtaudio
http://www.portaudio.com/

See also https://en.wikipedia.org/wiki/Csound

If you don't have a professional sound interface yet, but want to minimize a latency, read about Asio4All

Vladimir Bershov
  • 2,701
  • 2
  • 21
  • 51
  • Writing my own is what i want so that's not a problem, procesing the audio realtime it's not a problem neither, where i need help is how to modify the input stream bytes so the other apps catch the changes i made to the audio. I don't mind codding in c, c++, c# or java but are any of that librarys capable of that? – BraisRV Mar 29 '20 at 03:39