コード例 #1
0
        public AudioCapture(int sampleRate, int sampleSize)
        {
            this.sampleRate = sampleRate;
            this.sampleSize = sampleSize;

            if (sampleSize <= 0)
            {
                throw new ArgumentException("Sample size must be > 0, instead it is " + sampleSize);
            }

            resSamples = new float[this.sampleSize];
            var ayy = new MMDeviceEnumerator();

            // This uses the wasapi api to get any sound data played by the computer
            capture        = new WasapiCapture(false, AudioClientShareMode.Shared);
            capture.Device = ayy.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia);
            capture.Initialize();
            capture.DataAvailable += Capture_DataAvailable;

            IWaveSource source = new SoundInSource(capture);


            dataSource             = new PureDataSource(new WaveFormat(sampleRate, 8, 1), source.ToSampleSource());
            dataSource.OnDataRead += DataSource_OnDataRead;

            finalSource = dataSource.ToWaveSource();

            capture.Start();
        }
コード例 #2
0
    public void BeginCapture(MMDevice device1, MMDevice device2)
    {
        // This uses the wasapi api to get any sound data played by the computer
        capture        = new WasapiLoopbackCapture();
        capture.Device = device1;
        capture.Initialize();

        actualSource = new SoundInSource(capture);

        dataSource = new PureDataSource(new WaveFormat(device2.DeviceFormat.SampleRate, 8, 2), actualSource.ToSampleSource());

        capture.Start();

        games        = new WasapiOut();
        games.Device = device2;
        games.Initialize(dataSource.ToWaveSource());

        isSetup = true;
    }
コード例 #3
0
    public void Apply(PureDataSource source, float delay)
    {
        switch (type)
        {
        case PureDataOption.OptionTypes.Volume:
            source.SetVolume(GetValue <float>(), 0, delay);
            break;

        case PureDataOption.OptionTypes.Pitch:
            source.SetPitch(GetValue <float>(), 0, delay);
            break;

        case PureDataOption.OptionTypes.RandomVolume:
            float randomVolume = GetValue <float>();
            source.SetVolume(source.Info.volume + source.Info.volume * HelperFunctions.RandomRange(-randomVolume, randomVolume), 0, delay);
            break;

        case PureDataOption.OptionTypes.RandomPitch:
            float randomPitch = GetValue <float>();
            source.SetPitch(source.Info.pitch + source.Info.pitch * HelperFunctions.RandomRange(-randomPitch, randomPitch), 0, delay);
            break;

        case PureDataOption.OptionTypes.FadeIn:
            source.SetFadeIn(GetValue <float>());
            break;

        case PureDataOption.OptionTypes.FadeOut:
            source.SetFadeOut(GetValue <float>());
            break;

        case PureDataOption.OptionTypes.Loop:
            source.SetLoop(GetValue <bool>(), delay);
            break;

        case PureDataOption.OptionTypes.Clip:
            source.SetClip(source.pureData.clipManager.GetClip(GetValue <AudioClip>().name));
            break;

        case PureDataOption.OptionTypes.Output:
            source.SetOutput(GetValue <string>(), delay);
            break;

        case PureDataOption.OptionTypes.PlayRange:
            Vector2 playRange = GetValue <Vector2>();
            source.SetPlayRange(playRange.x, playRange.y, delay, true);
            break;

        case PureDataOption.OptionTypes.Time:
            source.SetPhase(GetValue <float>(), delay);
            break;

        case PureDataOption.OptionTypes.DopplerLevel:
            source.DopplerLevel = GetValue <float>();
            break;

        case PureDataOption.OptionTypes.VolumeRolloffMode:
            source.VolumeRolloffMode = GetValue <PureDataVolumeRolloffModes>();
            break;

        case PureDataOption.OptionTypes.MinDistance:
            source.MinDistance = GetValue <float>();
            break;

        case PureDataOption.OptionTypes.MaxDistance:
            source.MaxDistance = GetValue <float>();
            break;

        case PureDataOption.OptionTypes.PanLevel:
            source.PanLevel = GetValue <float>();
            break;
        }
    }
コード例 #4
0
 public PureDataSourceItem(PureDataSource audioSource, PureData pureData)
     : base(pureData)
 {
     this.audioSource = audioSource;
 }
コード例 #5
0
    public void Apply(PureDataSource source)
    {
        switch (type)
        {
        case PureDataOption.OptionTypes.Volume:
            float[] volumeData = GetValue <float[]>();
            source.SetVolume(volumeData[0], volumeData[1], delay);
            break;

        case PureDataOption.OptionTypes.Pitch:
            float[] pitchData = GetValue <float[]>();
            source.SetPitch(pitchData[0], pitchData[1], delay);
            break;

        case PureDataOption.OptionTypes.RandomVolume:
            float randomVolume = GetValue <float>();
            source.SetVolume(source.Info.volume + source.Info.volume * HelperFunctions.RandomRange(-randomVolume, randomVolume), 0, delay);
            break;

        case PureDataOption.OptionTypes.RandomPitch:
            float randomPitch = GetValue <float>();
            source.SetPitch(source.Info.pitch + source.Info.pitch * HelperFunctions.RandomRange(-randomPitch, randomPitch), 0, delay);
            break;

        case PureDataOption.OptionTypes.FadeIn:
            source.SetFadeIn(GetValue <float>());
            break;

        case PureDataOption.OptionTypes.FadeOut:
            source.SetFadeOut(GetValue <float>());
            break;

        case PureDataOption.OptionTypes.Loop:
            source.SetLoop(GetValue <bool>());
            break;

        case PureDataOption.OptionTypes.Clip:
            source.SetClip(source.pureData.clipManager.GetClip(GetValue <string>()));
            break;

        case PureDataOption.OptionTypes.Output:
            source.SetOutput(GetValue <string>(), delay);
            break;

        case PureDataOption.OptionTypes.PlayRange:
            float[] playRangeData = GetValue <float[]>();
            source.SetPlayRange(playRangeData[0], playRangeData[1], delay, true);
            break;

        case PureDataOption.OptionTypes.Time:
            source.SetPhase(GetValue <float>(), delay);
            break;

        case PureDataOption.OptionTypes.DopplerLevel:
            source.spatializer.DopplerLevel = GetValue <float>();
            break;

        case PureDataOption.OptionTypes.VolumeRolloffMode:
            source.spatializer.VolumeRolloffMode = (PureDataVolumeRolloffModes)GetValue <float>();
            break;

        case PureDataOption.OptionTypes.MinDistance:
            source.spatializer.MinDistance = GetValue <float>();
            break;

        case PureDataOption.OptionTypes.MaxDistance:
            source.spatializer.MaxDistance = GetValue <float>();
            break;

        case PureDataOption.OptionTypes.PanLevel:
            source.spatializer.PanLevel = GetValue <float>();
            break;

        default:
            Logger.LogError(string.Format("{0} can not be applied to {1}.", this, source.GetType()));
            break;
        }
    }