Пример #1
0
        public void Start()
        {
            if (State != SynthesizerState.Initial)
            {
                return;
            }

            soundio = new SoundIO();
            soundio.Connect();
            soundio.FlushEvents();
            var device = soundio.GetOutputDevice(soundio.DefaultOutputDeviceIndex);

            if (device.ProbeError != 0)
            {
                throw new DX7SynthesizerException($"Cannot probe device {device.Name}.");
            }
            out_stream = device.CreateOutStream();
            if (!device.SupportsFormat(SoundIOFormat.S16LE))
            {
                throw new NotSupportedException();
            }
            out_stream.Format            = SoundIOFormat.S16LE;
            out_stream.WriteCallback     = (min, max) => WriteCallback(min, max);
            out_stream.UnderflowCallback = () => { Debug.WriteLine("underflow"); };
            out_stream.ErrorCallback     = () => {
                throw new DX7SynthesizerException($"ERROR at libsoundio: {out_stream.LayoutErrorMessage}");
            };
            out_stream.Open();
            State = SynthesizerState.Started;
            out_stream.Start();
            soundio.FlushEvents();
        }
Пример #2
0
 void Start()
 {
     _soundIO = SoundIO.getSoundIO(cmbDevices.SelectedValue.ToString(), "wav", cmbFreq.SelectedValue.ToString());
     //new SoundIO(cmbDevices.SelectedItem.ToString(), "wav", cmbFreq.SelectedItem.ToString());
     _soundIO.OutputStream = new MemoryStream();
     _soundIO.StartRecording();
 }
Пример #3
0
        static int ListDevices(SoundIO soundIo)
        {
            int outputCount = soundIo.GetOutputDeviceCount();
            int inputCount  = soundIo.GetInputDeviceCount();

            int defaultOutput = soundIo.GetDefaultOutputDeviceIndex();
            int defaultInput  = soundIo.GetDefaultInputDeviceIndex();

            Console.WriteLine("--------Input Devices--------");
            for (int i = 0; i < inputCount; i++)
            {
                SoundIODevice device = soundIo.GetInputDevice(i);
                PrintDevice(device, defaultInput == i);
                device.Release();
            }
            Console.WriteLine("\n--------Output Devices--------\n");
            for (int i = 0; i < outputCount; i++)
            {
                SoundIODevice device = soundIo.GetOutputDevice(i);
                PrintDevice(device, defaultOutput == i);
                device.Release();
            }

            Console.WriteLine("\n{0} devices found.", inputCount + outputCount);
            return(0);
        }
Пример #4
0
 public void Formats()
 {
     foreach (SoundIOFormat f in Enum.GetValues(typeof(SoundIOFormat)))
     {
         Assert.IsNotNull(SoundIO.GetSoundFormatName(f), $"name expected for {f}");
     }
 }
Пример #5
0
        public void WithDefaultOutputDevice()
        {
            var api = new SoundIO();

            api.Connect();
            try {
                api.FlushEvents();
                var dev = api.GetOutputDevice(api.DefaultOutputDeviceIndex);
                Assert.AreNotEqual(0, dev.GetNearestSampleRate(1), "nearest sample rate is 0...?");
                var wait = new ManualResetEvent(false);
                using (var stream = dev.CreateOutStream()) {
                    stream.Open();
                    stream.WriteCallback = (min, max) => {
                        int frameCount = max;
                        var results    = stream.BeginWrite(ref frameCount);
                        for (int channel = 0; channel < stream.Layout.ChannelCount; channel += 1)
                        {
                            var area = results.GetArea(channel);
                            // FIXME: do write samples
                            area.Pointer += area.Step;
                        }
                        stream.EndWrite();
                        wait.Set();
                    };
                    stream.Start();
                    stream.Pause(true);
                    wait.WaitOne();
                }
            } finally {
                api.Disconnect();
            }
        }
Пример #6
0
        public static int Main(string [] args)
        {
            bool   watch   = false;
            string backend = null;

            foreach (var arg in args)
            {
                switch (arg)
                {
                case "--watch":
                    watch = true;
                    continue;

                default:
                    if (arg.StartsWith("--backend:"))
                    {
                        backend = arg.Substring(arg.IndexOf(':') + 1);
                        continue;
                    }
                    break;
                }
                ShowUsageToExit();
                return(1);
            }

            using (var api = new SoundIO()) {
                SoundIOBackend be = SoundIOBackend.None;
                if (Enum.TryParse(backend, out be))
                {
                    ShowUsageToExit();
                    return(1);
                }
                if (be == SoundIOBackend.None)
                {
                    api.Connect();
                }
                else
                {
                    api.ConnectBackend(be);
                }

                api.FlushEvents();
                if (watch)
                {
                    api.OnDevicesChange = () => OnDeviceChange(api);
                    Console.WriteLine("Type [ENTER] to exit.");
                    Console.ReadLine();
                }
                else
                {
                    DoListDevices(api);
                }
            }


            return(0);
        }
Пример #7
0
        public void ApplicationName()
        {
            var api = new SoundIO();

            Assert.AreEqual("SoundIo", api.ApplicationName, "default app name unexpected");
            api.ApplicationName = "MyApp";
            Assert.AreEqual("MyApp", api.ApplicationName, "app_name not assigned");
            api.Dispose();
        }
Пример #8
0
        /// <summary>
        /// Constructs a new instance of a <see cref="SoundIoAudioOut"/>
        /// </summary>
        public SoundIoAudioOut()
        {
            m_AudioContext = new SoundIO();

            m_AudioContext.Connect();
            m_AudioContext.FlushEvents();

            m_AudioDevice = m_AudioContext.GetOutputDevice(m_AudioContext.DefaultOutputDeviceIndex);
            m_TrackPool   = new SoundIoAudioTrackPool(m_AudioContext, m_AudioDevice, MaximumTracks);
        }
Пример #9
0
        /// <summary>
        /// Constructs a new instance of a <see cref="SoundIoAudioOut"/>
        /// </summary>
        public SoundIoAudioOut()
        {
            _audioContext = new SoundIO();

            _audioContext.Connect();
            _audioContext.FlushEvents();

            _audioDevice = FindNonRawDefaultAudioDevice(_audioContext, true);
            _trackPool   = new SoundIoAudioTrackPool(_audioContext, _audioDevice, MaximumTracks);
        }
Пример #10
0
        /// <summary>
        /// Constructs a new instance of a <see cref="SoundIoAudioTrack"/>
        /// </summary>
        /// <param name="trackId">The track ID</param>
        /// <param name="audioContext">The SoundIO audio context</param>
        /// <param name="audioDevice">The SoundIO audio device</param>
        public SoundIoAudioTrack(int trackId, SoundIO audioContext, SoundIODevice audioDevice)
        {
            TrackID         = trackId;
            AudioContext    = audioContext;
            AudioDevice     = audioDevice;
            State           = PlaybackState.Stopped;
            ReleasedBuffers = new ConcurrentQueue <long>();

            m_Buffer          = new SoundIoRingBuffer();
            m_ReservedBuffers = new ConcurrentQueue <SoundIoBuffer>();
        }
        public SoundIoHardwareDeviceDriver()
        {
            _audioContext        = new SoundIO();
            _updateRequiredEvent = new ManualResetEvent(false);
            _sessions            = new List <SoundIoHardwareDeviceSession>();

            _audioContext.Connect();
            _audioContext.FlushEvents();

            _audioDevice = FindNonRawDefaultAudioDevice(_audioContext, true);
        }
Пример #12
0
        public void Dispose()
        {
            _outstream?.Dispose();
            _outstream = null;

            Device?.RemoveReference();
            Device = null;

            _api?.Disconnect();
            _api?.Dispose();
            _api = null;
        }
Пример #13
0
        public SoundIoHardwareDeviceDriver()
        {
            _audioContext        = new SoundIO();
            _updateRequiredEvent = new ManualResetEvent(false);
            _pauseEvent          = new ManualResetEvent(true);
            _sessions            = new ConcurrentDictionary <SoundIoHardwareDeviceSession, byte>();

            _audioContext.Connect();
            _audioContext.FlushEvents();

            _audioDevice = FindNonRawDefaultAudioDevice(_audioContext, true);
        }
Пример #14
0
 public void HaveBackend()
 {
     Assert.IsTrue(SoundIO.HaveBackend(SoundIOBackend.Dummy), "not even a Dummy?");
     if (Environment.OSVersion.Platform != PlatformID.Unix)
     {
         Assert.IsFalse(SoundIO.HaveBackend(SoundIOBackend.Alsa), "Wait, your Windows has ALSA??");
     }
     else
     {
         Assert.IsFalse(SoundIO.HaveBackend(SoundIOBackend.Wasapi), "Wut, you have WASAPI on your Unix platform?");
     }
 }
Пример #15
0
 static void DoListDevices(SoundIO api)
 {
     Console.WriteLine("Inputs");
     for (int i = 0; i < api.InputDeviceCount; i++)
     {
         PrintDevice(api.GetInputDevice(i));
     }
     Console.WriteLine("Outputs");
     for (int i = 0; i < api.OutputDeviceCount; i++)
     {
         PrintDevice(api.GetInputDevice(i));
     }
 }
Пример #16
0
        static void ShowUsageToExit()
        {
            Console.Error.WriteLine(@"Arguments:
--watch		watch devices.
--backend:xxx	specify backend to use.

libsoundio version: {0}

available backends: {1}
",
                                    SoundIO.VersionString,
                                    string.Join(", ", Enum.GetValues(typeof(SoundIOBackend))
                                                .Cast <SoundIOBackend> ()
                                                .Where(b => SoundIO.HaveBackend(b))));
        }
Пример #17
0
        public void EnumerateBackends()
        {
            var obj = new SoundIO();

            Assert.AreNotEqual(0, obj.BackendCount, "no backend?");
            var nameList = new List <string> ();

            for (int i = 0; i < obj.BackendCount; i++)
            {
                nameList.Add(SoundIO.GetBackendName(obj.GetBackend(i)));
            }
            string names = string.Join(", ", nameList);

            Assert.AreNotEqual(string.Empty, names, "no backend names?");
            obj.Dispose();
        }
Пример #18
0
        public void OnBackendDisconnect()
        {
            var    api = new SoundIO();
            string msg = null;
            int    err = -1;

            api.OnBackendDisconnect = e => {
                msg = "disconnected";
                err = e;
            };
            api.Connect();
            api.FlushEvents();
            api.Disconnect();
            Assert.AreEqual("disconnected", msg, "msg not set");
            Assert.AreEqual(0, err, "either error occured or event not fired");
            api.Dispose();
        }
Пример #19
0
        public void SoftwareLatencyOffset()
        {
            var api = new SoundIO();

            api.Connect();
            try {
                api.FlushEvents();
                var dev = api.GetOutputDevice(api.DefaultOutputDeviceIndex);
                Assert.AreNotEqual(0, dev.GetNearestSampleRate(1), "nearest sample rate is 0...?");
                using (var stream = dev.CreateOutStream()) {
                    Assert.AreEqual(0, stream.SoftwareLatency, "existing non-zero latency...?");
                    stream.SoftwareLatency = 0.5;
                    Assert.AreEqual(0.5, stream.SoftwareLatency, "wrong software latency");
                }
            } finally {
                api.Disconnect();
            }
        }
Пример #20
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Initialize sio
            sio = new SoundIO();

            // Initialize AudioTool with sio's output parameters:
            at = new AudioTool(sio.getOutputNumChannels(), sio.getOutputSampleRate());

            // Setup event logic with a lambda to run every time we get an input buffer of audio
            sio.audioInEvent += (float[] data) =>
            {
                // When we get a buffer of data, make Audio Tool convert it from mono to stereo:
                float[] output = at.convertChannels(data, 1);

                // Output that data to the speakers
                sio.writeAudio(output);
            };
        }
Пример #21
0
        /// <summary>
        /// Searches for a shared version of the default audio device
        /// </summary>
        /// <param name="audioContext">The <see cref="SoundIO"/> audio context</param>
        /// <param name="fallback">Whether to fallback to the raw default audio device if a non-raw device cannot be found</param>
        private static SoundIODevice FindNonRawDefaultAudioDevice(SoundIO audioContext, bool fallback = false)
        {
            SoundIODevice defaultAudioDevice = audioContext.GetOutputDevice(audioContext.DefaultOutputDeviceIndex);

            if (!defaultAudioDevice.IsRaw)
            {
                return(defaultAudioDevice);
            }

            for (int i = 0; i < audioContext.BackendCount; i++)
            {
                SoundIODevice audioDevice = audioContext.GetOutputDevice(i);

                if (audioDevice.Id == defaultAudioDevice.Id && !audioDevice.IsRaw)
                {
                    return(audioDevice);
                }
            }

            return(fallback ? defaultAudioDevice : null);
        }
Пример #22
0
        public void Properties()
        {
            var api = new SoundIO();

            api.Connect();
            try {
                api.FlushEvents();
                var dev = api.GetOutputDevice(api.DefaultOutputDeviceIndex);
                foreach (var p in typeof(SoundIODevice).GetProperties())
                {
                    try {
                        p.GetValue(dev);
                    } catch (Exception ex) {
                        Assert.Fail("Failed to get property " + p + " : " + ex);
                    }
                }
            } finally {
                api.Disconnect();
                api.Dispose();
            }
        }
Пример #23
0
        public void Test1()
        {
            // https://github.com/AddictedCS/soundfingerprinting.soundtools/blob/master/src/SoundFingerprinting.SoundTools/DrawningTool/WinDrawningTool.cs

            string    pathToSourceFile = @"C:\Users\pnerseth\Amazon Drive\Documents\Audio\FL Projects\!PERIVAR\Clean Bandit - Rather Be Programming\Clean Bandit - Region 1 Slow.wav";
            const int sampleRate       = 32000;
            string    DirectoryPath    = @"C:\Users\pnerseth\My Projects\test-output";

            var          audioService = new FindSimilarAudioService();
            AudioSamples data         = audioService.ReadMonoSamplesFromFile(pathToSourceFile, sampleRate, 2, 5);

/*
 *          var imageService = new FindSimilarImageService();
 *          using (Image image = imageService.GetSignalImage(data.Samples, 2000, 500))
 *          {
 *              image.Save(Path.Combine(DirectoryPath, "_downsampled.png"), ImageFormat.Jpeg);
 *          }
 *
 */
            SoundIO.WriteWaveFile(Path.Combine(DirectoryPath, "_resampled.wav"), data.Samples, sampleRate);
        }
Пример #24
0
        public void Devices()
        {
            var api = new SoundIO();

            api.Connect();
            try {
                api.FlushEvents();
                Assert.IsTrue(api.DefaultInputDeviceIndex >= -1, "default input device index");
                Assert.IsTrue(api.DefaultOutputDeviceIndex >= -1, "default output device index");
                for (int i = 0; i < api.OutputDeviceCount; i++)
                {
                    var dev = api.GetOutputDevice(i);
                }
                for (int i = 0; i < api.InputDeviceCount; i++)
                {
                    var dev = api.GetInputDevice(i);
                }
            } finally {
                api.Disconnect();
            }
        }
        public void Properties()
        {
            var api = new SoundIO();

            api.Connect();
            try {
                api.FlushEvents();
                var dev = api.GetInputDevice(api.DefaultInputDeviceIndex);
                using (var stream = dev.CreateInStream()) {
                    foreach (var p in typeof(SoundIOInStream).GetProperties())
                    {
                        try {
                            p.GetValue(stream);
                        } catch (Exception ex) {
                            Assert.Fail("Failed to get property " + p + " : " + ex);
                        }
                    }
                }
            } finally {
                api.Disconnect();
                api.Dispose();
            }
        }
Пример #26
0
        public void WithDefaultOutputDevice()
        {
            var api = new SoundIO();

            api.Connect();
            try {
                api.FlushEvents();
                var dev = api.GetOutputDevice(api.DefaultOutputDeviceIndex);
                Assert.AreNotEqual(0, dev.GetNearestSampleRate(1), "nearest sample rate is 0...?");
                using (var stream = dev.CreateOutStream()) {
                    stream.Open();
                    stream.WriteCallback = (min, max) => {
                        int frameCount = max;
                        stream.BeginWrite(ref frameCount);
                    };
                    stream.Start();
                    stream.Pause(true);
                    Thread.Sleep(50);
                    stream.EndWrite();
                }
            } finally {
                api.Disconnect();
            }
        }
Пример #27
0
        public void Properties()
        {
            var api = new SoundIO();

            api.Connect();
            try {
                api.FlushEvents();
                var dev = api.GetOutputDevice(api.DefaultOutputDeviceIndex);
                using (var stream = dev.CreateOutStream()) {
                    foreach (var p in typeof(SoundIOOutStream).GetProperties())
                    {
                        try {
                            switch (p.Name)
                            {
                            case "Layout":
                                var cl = stream.Layout;
                                foreach (var pcl in typeof(SoundIOChannelLayout).GetProperties())
                                {
                                    Console.Error.WriteLine(pcl + " : " + pcl.GetValue(cl));
                                }
                                break;

                            default:
                                p.GetValue(stream);
                                break;
                            }
                        } catch (Exception ex) {
                            Assert.Fail("Failed to get property " + p + " : " + ex.InnerException);
                        }
                    }
                }
            } finally {
                api.Disconnect();
                api.Dispose();
            }
        }
Пример #28
0
        private void ReadAndWrite(string category, string audioPath, string outputPath)
        {
            var audioData = fixture.FindSimilarAudioService.ReadMonoSamplesFromFile(audioPath, fixture.SampleRate, 0, 0);

            SoundIO.WriteWaveFile(outputPath, audioData.Samples, fixture.SampleRate);
        }
Пример #29
0
        /// <summary>
        /// Determines if SoundIO can connect to a supported backend
        /// </summary>
        /// <returns></returns>
        private static bool IsSupportedInternal()
        {
            SoundIO          context = null;
            SoundIODevice    device  = null;
            SoundIOOutStream stream  = null;

            bool backendDisconnected = false;

            try
            {
                context = new SoundIO();

                context.OnBackendDisconnect = (i) => {
                    backendDisconnected = true;
                };

                context.Connect();
                context.FlushEvents();

                if (backendDisconnected)
                {
                    return(false);
                }

                if (context.OutputDeviceCount == 0)
                {
                    return(false);
                }

                device = FindNonRawDefaultAudioDevice(context);

                if (device == null || backendDisconnected)
                {
                    return(false);
                }

                stream = device.CreateOutStream();

                if (stream == null || backendDisconnected)
                {
                    return(false);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }

                if (context != null)
                {
                    context.Dispose();
                }
            }
        }
Пример #30
0
 static void OnDeviceChange(SoundIO api)
 {
     DoListDevices(api);
 }
Пример #31
0
        private void setupSensors()
        {
            // Initialize the combined orientation sensor
            try
            {
                motion = new Motion();
                motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(100);
                motion.CurrentValueChanged += motion_CurrentValueChanged;
                motion.Start();
            }
            catch
            {
                // Print out an error
                MessageBox.Show("Could not initialize Motion API.  This phone does not have the necessary sensors to run this code properly!");

                // The kill the current application
                Application.Current.Terminate();
            }

            // Setup sound output
            sio = new SoundIO();
            sio.audioOutEvent += sio_audioOutEvent;
            sio.start();
            at = new AudioTool(sio.getOutputNumChannels(), sio.getOutputSampleRate());
        }
Пример #32
0
        private void Start()
        {
            _soundIO = SoundIO.getSoundIO(cmbDevices.Items[cmbDevices.SelectedIndex].ToString(), "wav", cmbFreq.Items[cmbFreq.SelectedIndex].ToString());

            //new SoundIO(cmbDevices.SelectedItem.ToString(), "wav", cmbFreq.SelectedItem.ToString());
            _soundIO.OutputStream = new MemoryStream();
            _soundIO.StartRecording();
        }