예제 #1
0
 public Audio(int inputChannels, int outputChannels, int frequency, uint framesPerBuffer,
     PortAudio.PaStreamCallbackDelegate paStreamCallback)
 {
     log("Initializing...");
      		this.inputChannels = inputChannels;
      		this.outputChannels = outputChannels;
      		this.frequency = frequency;
      		this.framesPerBuffer = framesPerBuffer;
      		this.paStreamCallback = paStreamCallback;
      		if (errorCheck("Initialize",PortAudio.Pa_Initialize())) {
      			this.disposed = true;
      			// if Pa_Initialize() returns an error code,
      			// Pa_Terminate() should NOT be called.
      			throw new Exception("Can't initialize audio");
      		}
      		int apiCount = PortAudio.Pa_GetHostApiCount();
     for (int i = 0; i < apiCount; i++) {
         PortAudio.PaHostApiInfo availableApiInfo = PortAudio.Pa_GetHostApiInfo(i);
         log("available API index: " + i + "\n" + availableApiInfo.ToString());
     }
      		this.hostApi = apiSelect();
      		log("selected Host API: " + this.hostApi);
      		this.apiInfo = PortAudio.Pa_GetHostApiInfo(this.hostApi);
     this.inputDeviceInfo = PortAudio.Pa_GetDeviceInfo(apiInfo.defaultInputDevice);
     this.outputDeviceInfo = PortAudio.Pa_GetDeviceInfo(apiInfo.defaultOutputDevice);
     log("input device:\n" + inputDeviceInfo.ToString());
      		log("output device:\n" + outputDeviceInfo.ToString());
 }
예제 #2
0
        public Audio(int inputChannels, int outputChannels, int frequency, uint framesPerBuffer,
                     PortAudio.PaStreamCallbackDelegate paStreamCallback)
        {
            log("Initializing...");
            this.inputChannels    = inputChannels;
            this.outputChannels   = outputChannels;
            this.frequency        = frequency;
            this.framesPerBuffer  = framesPerBuffer;
            this.paStreamCallback = paStreamCallback;
            if (errorCheck("Initialize", PortAudio.Pa_Initialize()))
            {
                this.disposed = true;
                // if Pa_Initialize() returns an error code,
                // Pa_Terminate() should NOT be called.
                throw new Exception("Can't initialize audio");
            }
            int apiCount = PortAudio.Pa_GetHostApiCount();

            for (int i = 0; i < apiCount; i++)
            {
                PortAudio.PaHostApiInfo availableApiInfo = PortAudio.Pa_GetHostApiInfo(i);
                log("available API index: " + i + "\n" + availableApiInfo.ToString());
            }
            this.hostApi = apiSelect();
            log("selected Host API: " + this.hostApi);
            this.apiInfo          = PortAudio.Pa_GetHostApiInfo(this.hostApi);
            this.inputDeviceInfo  = PortAudio.Pa_GetDeviceInfo(apiInfo.defaultInputDevice);
            this.outputDeviceInfo = PortAudio.Pa_GetDeviceInfo(apiInfo.defaultOutputDevice);
            log("input device:\n" + inputDeviceInfo.ToString());
            log("output device:\n" + outputDeviceInfo.ToString());
        }
예제 #3
0
        void ASIODeviceControlLoad(object sender, EventArgs e)
        {
            int deviceCount = PortAudio.Pa_GetDeviceCount();

            Console.WriteLine("Device count: " + paHostApiInfo.deviceCount + " default input device: " + paHostApiInfo.defaultInputDevice);

            deviceComboBox.Items.Clear();
            for (int i = 0; i < deviceCount; i++)
            {
                PortAudio.PaDeviceInfo  paDeviceInfo = PortAudio.Pa_GetDeviceInfo(i);
                PortAudio.PaHostApiInfo paHostApi    = PortAudio.Pa_GetHostApiInfo(paDeviceInfo.hostApi);
                if (paHostApi.type == PortAudio.PaHostApiTypeId.paASIO)
                {
                    Console.WriteLine("\n#" + i + "\n" + paDeviceInfo);
                    if (paDeviceInfo.maxOutputChannels > 0)
                    {
                        deviceComboBox.Items.Add(new DeviceItem(i, paDeviceInfo));
                        if (i == paHostApiInfo.defaultOutputDevice)
                        {
                            deviceComboBox.SelectedIndex = deviceComboBox.Items.Count - 1;
                        }
                    }
                }
            }

            bufferSizeComboBox.Items.Clear();
            int bufferSize = 256;

            while (bufferSize < 44100 / 2)
            {
                bufferSizeComboBox.Items.Add(bufferSize);
                bufferSize *= 2;
            }
            bufferSizeComboBox.SelectedIndex = 2;
        }
예제 #4
0
        public HostApiItem(PortAudio.PaHostApiInfo hostApiInfo, IUpdatableControl updatableControl)
        {
            this.hostApiInfo = hostApiInfo;

            int deviceCount = PortAudio.Pa_GetDeviceCount();
            int selectedHostApiDeviceCount = 0;

            for (int i = 0; i < deviceCount; i++)
            {
                PortAudio.PaDeviceInfo  paDeviceInfo = PortAudio.Pa_GetDeviceInfo(i);
                PortAudio.PaHostApiInfo paHostApi    = PortAudio.Pa_GetHostApiInfo(paDeviceInfo.hostApi);
                if (paHostApi.type == hostApiInfo.type)
                {
                    selectedHostApiDeviceCount++;
                }
            }

            if (selectedHostApiDeviceCount > 0)
            {
                switch (hostApiInfo.type)
                {
                case PortAudio.PaHostApiTypeId.paMME:
                    hostApiDeviceControl = new MMEDeviceControl(hostApiInfo, updatableControl);
                    break;

                case PortAudio.PaHostApiTypeId.paDirectSound:
                    hostApiDeviceControl = new DirectSoundDeviceControl(hostApiInfo, updatableControl);
                    break;

                case PortAudio.PaHostApiTypeId.paASIO:
                    hostApiDeviceControl = new ASIODeviceControl(hostApiInfo, updatableControl);
                    break;

                case PortAudio.PaHostApiTypeId.paALSA:
                    hostApiDeviceControl = new ALSADeviceControl(hostApiInfo, updatableControl);
                    break;
                }
            }
            else
            {
                hostApiDeviceControl = new NoDevicesDeviceControl(hostApiInfo, updatableControl);
            }
        }
예제 #5
0
 public DeviceItem(int deviceIndex, PortAudio.PaDeviceInfo deviceInfo)
 {
     this.deviceIndex = deviceIndex;
     this.deviceInfo  = deviceInfo;
 }
예제 #6
0
 public DeviceItem(int deviceIndex, PortAudio.PaDeviceInfo deviceInfo)
 {
     this.deviceIndex = deviceIndex;
     this.deviceInfo = deviceInfo;
 }
예제 #7
-1
        public int Open(string FileName)
        {
            if (_FileOpened)
                return -1;

            if (!System.IO.File.Exists(FileName))
                return -1;

            if (_FileOpened)
                return -1;

            _Decoder = new CAudioDecoderFFmpeg();
            _Decoder.Init();

            try
            {
                if (errorCheck("Initialize", PortAudio.Pa_Initialize()))
                    return -1;

                _Initialized = true;
                int hostApi = apiSelect();
                _apiInfo = PortAudio.Pa_GetHostApiInfo(hostApi);
                _outputDeviceInfo = PortAudio.Pa_GetDeviceInfo(_apiInfo.defaultOutputDevice);
                _paStreamCallback = new PortAudio.PaStreamCallbackDelegate(_PaStreamCallback);

                if (_outputDeviceInfo.defaultLowOutputLatency < 0.1)
                    _outputDeviceInfo.defaultLowOutputLatency = 0.1;
            }

            catch (Exception)
            {
                _Initialized = false;
                CLog.LogError("Error Init PortAudio Playback");
                return -1;
            }
            
            _FileName = FileName;
            _Decoder.Open(FileName);
            _Duration = _Decoder.GetLength();

            FormatInfo format = _Decoder.GetFormatInfo();
            _ByteCount = 2 * format.ChannelCount;
            _BytesPerSecond = format.SamplesPerSecond * _ByteCount;
            _CurrentTime = 0f;
            _SyncTimer.Time = _CurrentTime;

            AudioStreams stream = new AudioStreams(0);
            
            IntPtr data = new IntPtr(0);

            PortAudio.PaStreamParameters outputParams = new PortAudio.PaStreamParameters();
            outputParams.channelCount = format.ChannelCount;
            outputParams.device = _apiInfo.defaultOutputDevice;
            outputParams.sampleFormat = PortAudio.PaSampleFormat.paInt16;
            outputParams.suggestedLatency = _outputDeviceInfo.defaultLowOutputLatency;

            uint bufsize = (uint)CConfig.AudioBufferSize;
            errorCheck("OpenDefaultStream", PortAudio.Pa_OpenStream(
                out _Ptr,
                IntPtr.Zero,
                ref outputParams,
                format.SamplesPerSecond,
                bufsize,
                PortAudio.PaStreamFlags.paNoFlag,
                _paStreamCallback,
                data));

            stream.handle = _Ptr.ToInt32();

            if (stream.handle != 0)
            {
                _Paused = true;
                _waiting = true;
                _FileOpened = true;
                _data = new RingBuffer(BUFSIZE);
                _NoMoreData = false;
                _DecoderThread.Priority = ThreadPriority.Normal;
                _DecoderThread.Name = Path.GetFileName(FileName);
                _DecoderThread.Start();
                
                return stream.handle;
            }
            return -1;
        }