How transfer system mic audio stream to attached device mic audio stream
Asked Answered
R

1

6

I am trying to attach USB device used for tele calling which have pnp sound controller for mic and speaker. Now i have two speaker and two mic for input output as shown in image below.<code>Speaker</code>mic. Now my motive is to transfer audio stream from system mic to usb mic and from usb speaker to system speaker.

I tried to solve this issue with virtual cable software but with this i need to depend on third party. What can be the possible solution that can attained using c#.

I don't have knowledge about this, so don't know how to start. After googling i found

  1. CS Core
  2. N Audio

Can help me i don't know how.

 public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        List<NAudio.Wave.WaveInCapabilities> sources = new List<NAudio.Wave.WaveInCapabilities>();

        for (int i = 0; i < NAudio.Wave.WaveIn.DeviceCount; i++)
        {
            sources.Add(NAudio.Wave.WaveIn.GetCapabilities(i));
        }

        sourceList.Items.Clear();

        foreach (var source in sources)
        {
            ListViewItem item = new ListViewItem(source.ProductName);
            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, source.Channels.ToString()));
            sourceList.Items.Add(item);
        }
    }

    NAudio.Wave.WaveIn sourceStream,sourceStream1 = null;
    NAudio.Wave.DirectSoundOut waveOut = null;

    private void button2_Click(object sender, EventArgs e)
    {
        if (sourceList.SelectedItems.Count == 0) return;

        int deviceNumber = sourceList.SelectedItems[0].Index;

        sourceStream = new NAudio.Wave.WaveIn();
        sourceStream.DeviceNumber = 0;
        sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);



        NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream1);
        sourceStream.
        waveOut = new NAudio.Wave.DirectSoundOut();
        waveOut.Init(waveIn);

        sourceStream1.StartRecording();
        waveOut.Play();
    }

    private void button3_Click(object sender, EventArgs e)
    {
        if (waveOut != null)
        {
            waveOut.Stop();
            waveOut.Dispose();
            waveOut = null;
        }
        if (sourceStream != null)
        {
            sourceStream.StopRecording();
            sourceStream.Dispose();
            sourceStream = null;
        }
    }

    private void button4_Click(object sender, EventArgs e)
    {
        button3_Click(sender, e);
        this.Close();
    }
}

Using this code i can send mic audio to speaker but how can i implement my task using this.

Reredos answered 7/7, 2016 at 8:16 Comment(3)
This is not the answer but it will give you a hint daveamenta.com/2011-05/… it's in c++ but you can compile it to DLL or EXE and call it from you C# code.Eastern
Could you elaborate more, why you would want to do that? What is the goal? To me, it looks like you would like to use both, the system microphone and usb microphone, at the same time - right? Maybe you can tell the problem you have with two devices, there might be a better solution.Rugby
@DanielGilbert usb microphone is only port which can take input there is no physical microphone for sound input(connected to external sound card). My goal i am developing telephone which is operated using c# by sending commands to my device which is working perfect. If i attached headphone directly to my device it works perfect. But i want to exchange sound through headphone connected to system. So that i can remove mic and speaker jack from my external hardware.Reredos
P
2

Actually there is no way to do this without writing any custom driver. You can not render audio data to a input device. Input devices are meant to read data from. Output devices (speakers) are meant to write data to.

There are programs like virtual audio cable, which are using custom drivers to bypass these limitations.

Pothook answered 9/7, 2016 at 6:42 Comment(1)
The WinDDK contains some samples.Pothook

© 2022 - 2024 — McMap. All rights reserved.