I want to record sound to a file and at the same time I want to be able to play audio from the same file in C#
For example, play the last 15 seconds but the microphone has to keep on registering and recording while replaying.
Is this possible and in that case, which is the best approach to do this?
The answer is YES, and you should play around with low level audio API, namely WaveIn/Out functions from winmm.dll, through P/Invoke in C#.
In short words, you need to use WaveIn to capture input signal from a input device and store in some structure, then use WaveOut to play back the audio simultaneously, or some delay after.
Here is a project you can start with: a duplex audio player. You can download the project and play around with it and see how it achieves it, then do some modifications upon the project to achieve what you want :)
Related
I want to create somewhat of a simple visualizer for my PC audio output channel (same as speakers/headphones) that will send signals to my arduino board when there is bass or treble being played. I already have LEDs wired up and my own program with animations and colors running, I also developed a game modification that lets me control the lights using game events. All I need now is to read my PC audio output channel, find there a specific sound (probably bass, right?) and send byte on serial port just as I did previously.
I can't find any simple tutorials how to read windows audio so I decided to ask here. Where should I start? BASS.NET looks very complicated for that "simple" task. Is there something built-in in standard .NET libraries? I am by no means audio mastermind, I am not even sure if I am using correct terms. In simple words I just want to make lights light up to the rhythm when there is real-time music playing.
I suffer from tinnitus, and there are a number of sound-based therapies that I can use to mitigate the phantom sounds.
I would like to explore the possibility of processing the sound going to my headphones, or even my speakers, from my PC with a software-based filter.
Is there a way using C# to intercept the audio stream, process it (applying a band-pass filter for example), allowing it to continue to external devices?
I would suggest to use virtual audio device to capture the sound and transmit it to the real speakers after processing. I'm not sure if it is possible to create this using c#. But you can use existing drivers like vac. So you set vac as default device. You create a c# program which records from vac, does the processing, and sends it to the speakers.
I'd like to be able to press a button to play a sound of a button being pressed while music is already playing. SoundPlayer is no help because it stops the music to play the sound.
I have added the sounds to my Resources (WindowsFormsApplication2.Resources.Properties.button) and I don't want to have to type in the file location.
Answer from MerickOWA
You CANNOT play two sounds at once using SoundPlayer.
SoundPlayer is using the native WINAPI PlaySound function to accomplish the task which has no support for playing simultaneous sounds. Creating multiple instances of SoundPlayer won't help.
There are many options most of which involve implementing a lot of the low level API to window's native audio library or DirectSound (note neither are C# and require alot of interop code)
The simplest option would be to depend on windows media player to play the audio for you.
Add a reference to "C:\Windows\System32\wmp.dll"
then use
var player = new WMPLib.WindowsMediaPlayer();
player.URL = #"..\..\bin\debug\tribal dance.wav";
Note: play starts immediately after setting the URL property
The down side of this approach is your reliance on media player for your application to work properly. On the upside, you can use any file format media player supports.
I want to be able to precisely control the timing of .wav files played in my program. I also want to be able to play more than one .wav file at the same time. The SoundPlayer was not good enough because I can't play two sounds at once, and even when I play different sounds consecutively, there is about a 1/8th second delay between each sound, which is unacceptable for what I am doing. I cannot find a way to add a Device using SharpDX.
You have a directsound sample in sharpdx, should get you started.
Also you can have a look at NAudio , which should also fit your needs and be a bit easier to use.
Is a way of creating a program (either in C(+,++,#) or VB.net) that would be able to send a beep sound through the same line-in that is being used for audacity (not stereo mix)?
I am trying to make a way of syncing up audio and video from 2 different programs, in a similar way that a clapper bored works in the movies.
Would there be a way of using a sort of microphone enhancement that could be created because they affect the microphone input?
I assume you're trying to implement something like http://www.singularsoftware.com/pluraleyes.html then? I think the best way would be to write a VST/LADSPA plug-in for Audacity that inserts the beeps synced to a timecode stream (or whatever you're syncing to).
There's a neat little library called VST.NET that allows you to write VST plug-ins in standard C#/VB.NET if you like.