Esempio n. 1
0
        public String[] GetOutputChannelNames()
        {
            //in case of crackling sound, set the channel count to 12 (just analog)
            //var channelCnt =  tempAsioOut.DriverOutputChannelCount;
            List <String> outputNames = new List <String>();

            if (asioOut == null)
            {
                using (var tempAsioOut = new MyAsioOut(deviceName))
                {
                    //var channelCnt =  tempAsioOut.DriverOutputChannelCount;
                    var channelCnt = 12;
                    for (int i = 0; i < channelCnt; i++)
                    {
                        outputNames.Add(tempAsioOut.AsioOutputChannelName(i));
                    }
                }
            }
            else
            {
                //var channelCnt =  asioOut.DriverOutputChannelCount;
                var channelCnt = 12;
                for (int i = 0; i < channelCnt; i++)
                {
                    outputNames.Add(asioOut.AsioOutputChannelName(i));
                }
            }
            return(outputNames.ToArray());
        }
Esempio n. 2
0
        public void Init(IEnumerable <IEnumerable <String> > fileSets, String spFilename, List <String> inputChannelTypes, List <int> inputMappingData, List <String> outputChannelTypes, List <int> outputMappingData)
        {
            this.soundDictionary = new Dictionary <String, CachedSound>(); // use dictionary to check if cached sound exists
            var inputSets = new List <List <IWaveProvider> >();            // argument to pass  into wave provider
            //set totalOutChannelCnt to 12 in case of crackling sound
            //int totalOutChannelCnt = asioOut.DriverOutputChannelCount;
            int totalOutChannelCnt = 12;
            int speechCnt          = outputChannelTypes.Sum(type => type.Contains("Speech") ? 1 : 0);
            int noiseCnt           = outputChannelTypes.Sum(type => type.Contains("Noise") ? 1 : 0);

            this.desiredInputChannels  = inputMappingData.ToArray();
            this.desiredOutputChannels = outputMappingData.ToArray();

            asioOut = new MyAsioOut(deviceName);

            foreach (var fileSet in fileSets)
            {
                var fileSetArr = fileSet.ToArray();
                var input      = new List <IWaveProvider>();

                for (int i = 0; i < speechCnt; i++)
                {
                    if (fileSetArr[i] == null)
                    {
                        input.Add(new SilenceStream(new WaveFormat(44100, 16, 1)));
                    }
                    else if (i == 0)
                    {
                        var sound = GetSoundFromDictionary(fileSetArr[i]);
                        input.Add(spFilename == null ? new SpeechStream(sound) : new SpeechStream(sound, GetSoundFromDictionary(spFilename)));
                    }
                    else
                    {
                        var sound = GetSoundFromDictionary(fileSetArr[i]);
                        input.Add(spFilename == null ? new InterferenceStream(sound) : new InterferenceStream(sound, GetSoundFromDictionary(spFilename)));
                    }
                }
                for (int i = 0; i < noiseCnt; i++)
                {
                    if (fileSetArr[speechCnt] == null)
                    {
                        input.Add(new SilenceStream(new WaveFormat(44100, 16, 1)));
                    }
                    else
                    {
                        var sound = GetSoundFromDictionary(fileSetArr[speechCnt]);
                        input.Add(spFilename == null ? new NoiseStream(sound) : new NoiseStream(sound, GetSoundFromDictionary(spFilename)));
                    }
                }
                //fill the rest channels
                for (int i = 0; i < totalOutChannelCnt - speechCnt - noiseCnt; i++)
                {
                    input.Add(new SilenceStream(new WaveFormat(44100, 16, 1)));
                }

                inputSets.Add(input);
            }
            mwProvider = new MyWaveProvider(inputSets, inputSets[0].Count);
            // mapping
            for (int i = 0; i < outputMappingData.Count; i++)
            {
                mwProvider.ConnectInputToOutput(i, outputMappingData[i]);
                mwProvider.ConnectInputToOutput(outputMappingData[i], i);
            }
            //we need all inputs from the sound card
            //but just get the analog channel (1-12)
            asioOut.InitRecordAndPlayback(mwProvider, 12);
            asioOut.AudioAvailable += new EventHandler <MyAsioAudioAvailableEventArgs>(AudioAvailable);
        }