Coder Social home page Coder Social logo

Comments (10)

filoe avatar filoe commented on July 21, 2024 1

A sample application would be great. But as I already said, its hard to compare C# with native languages on such a low latency.

from cscore.

filoe avatar filoe commented on July 21, 2024

Take a look at the following snippet: https://github.com/filoe/cscore/blob/master/CSCore.Test/RecentIssueTests/SoundInToSoundOutTests.cs
The dsp function can be created by implementing the IWaveSource or ISampleSource interface. The instance of the dsp function can be applied to the waveInToSource object.
For example: soundOut.Initialize(new DmoEchoEffect(waveInToSource));

from cscore.

postacik avatar postacik commented on July 21, 2024

Thank you very much. It works like a charm.

I've been trying to do the same think with the Bass.Net and the Bass library and I succeeded but CSCore way of doing it is just easier and requires only one native DLL.

It would be great if you could extend the sample applications with some common tasks like this one because it is hard to dig into the test codes.

I will try implementing the IWaveSource or ISampleSource interfaces and maybe return with new questions.

from cscore.

filoe avatar filoe commented on July 21, 2024

Glad to hear that.

from cscore.

postacik avatar postacik commented on July 21, 2024

I wrote a sample ISampleSource to amplify captured sound. Is this the right way of doing it?

using System;
using CSCore;

namespace MyTests
{
    class DSPGain: ISampleSource
    {
        ISampleSource _source;
        public DSPGain(ISampleSource source)
        {
            if (source == null)
                throw new ArgumentNullException("source");
            _source = source;
        }
        public int Read(float[] buffer, int offset, int count)
        {
            float gainAmplification = (float)(Math.Pow(10.0, GainDB / 20.0));
            int samples = _source.Read(buffer, offset, count);
            for (int i = offset; i < offset + samples; i++)
            {
                buffer[i] = Math.Max(Math.Min(buffer[i] * gainAmplification, 1), -1);
            }
            return samples;
        }

        public float GainDB { get; set; }

        public bool CanSeek
        {
            get { return _source.CanSeek; }
        }

        public WaveFormat WaveFormat
        {
            get { return _source.WaveFormat; }
        }

        public long Position
        {
            get
            {
                return _source.Position;
            }
            set
            {
                _source.Position = value;
            }
        }

        public long Length
        {
            get { return _source.Length; }
        }

        public void Dispose()
        {
        }
    }
}

from cscore.

filoe avatar filoe commented on July 21, 2024

It is, but do not forget to dispose the _source inside of the dispose method.

from cscore.

postacik avatar postacik commented on July 21, 2024

Thanks. I also added pitch shifting option to the class and it works fine.

However, I tested my application with a user with Admin rights and with a user without Admin rights. (Windows 8)

The application works with minimum latency with the Admin user but it starts to lag and voice quality decreases when I run the application with the other user.

My application also uses the Bass library to achieve the same task as an alternative and it does not have this kind of problem.

CSCore and Bass versions both initialize Wasapi capture and playback in exclusive mode with 5 ms latency.

Do you have any idea why this might happen?

from cscore.

postacik avatar postacik commented on July 21, 2024

Here is a link to the related stackoverflow question which includes the code I am using.

http://stackoverflow.com/q/34634726/5413816

from cscore.

filoe avatar filoe commented on July 21, 2024

Well, if you compare CSCore with Bass you will always have a slightly worse performance. Bass is written in some native languages (I would guess C++?) and CSCore is written in C#. CSCore got a quite nice performance but I am not sure whether it can handle such a low latency. Have you tried to adjust the latency to lets say 20 or 30ms?

from cscore.

postacik avatar postacik commented on July 21, 2024

Well, CSCore and Bass have similar latency when I run the application under an admin user.

My son has a limited user account on my laptop and when I run the application under his account it lags severely with CSCore but has no problems with Bass. In my opinion, it may be related to the AudioClientShareMode.Exclusive option.

I can provide a sample application if you have time to test.

from cscore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.