public void Record() { IntPtr userdata = IntPtr.Zero; //intptr.zero is essentially just a null pointer callbackDelegate = new PortAudio.PaStreamCallbackDelegate(myPaStreamCallback); PortAudio.Pa_Initialize(); PortAudio.PaStreamParameters outputparams = new PortAudio.PaStreamParameters(); outputparams.channelCount = 1; outputparams.sampleFormat = PortAudio.PaSampleFormat.paInt16; outputparams.device = PortAudio.Pa_GetDefaultInputDevice(); outputparams.suggestedLatency = PortAudio.Pa_GetDeviceInfo(outputparams.device).defaultLowInputLatency; outputparams.hostApiSpecificStreamInfo = IntPtr.Zero; PortAudio.PaStreamParameters a = new PortAudio.PaStreamParameters(); //uninteresting output params cause i cant give it null a.channelCount = 1; a.sampleFormat = PortAudio.PaSampleFormat.paInt16; a.device = PortAudio.Pa_GetDefaultOutputDevice(); a.suggestedLatency = PortAudio.Pa_GetDeviceInfo(a.device).defaultLowOutputLatency; a.hostApiSpecificStreamInfo = IntPtr.Zero; PortAudio.PaError error = PortAudio.Pa_OpenStream(out stream, ref outputparams, ref a, this.sampleRate, (uint)NUM_SAMPLES, PortAudio.PaStreamFlags.paClipOff, callbackDelegate, IntPtr.Zero); this.isRecording = true; PortAudio.Pa_StartStream(stream); Thread myThread = new Thread(new ThreadStart(record_loop)); myThread.Start(); }
private bool errorCheck(String action, PortAudio.PaError errorCode) { if (errorCode != PortAudio.PaError.paNoError) { CLog.LogError(action + " error: " + PortAudio.Pa_GetErrorText(errorCode)); if (errorCode == PortAudio.PaError.paUnanticipatedHostError) { PortAudio.PaHostErrorInfo errorInfo = PortAudio.Pa_GetLastHostErrorInfo(); CLog.LogError("- Host error API type: " + errorInfo.hostApiType); CLog.LogError("- Host error code: " + errorInfo.errorCode); CLog.LogError("- Host error text: " + errorInfo.errorText); } return(true); } return(false); }
public PortAudio.PaError OpenStream(out IntPtr stream, ref PortAudio.PaStreamParameters?inputParameters, ref PortAudio.PaStreamParameters?outputParameters, double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) { lock (_Mutex) { if (_Disposed) { throw new ObjectDisposedException("PortAudioHandle already disposed"); } PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData); if (res == PortAudio.PaError.paNoError) { _Streams.Add(stream); } return(res); } }
public void Play() { IntPtr userdata = IntPtr.Zero; //intptr.zero is essentially just a null pointer callbackDelegate = new PortAudio.PaStreamCallbackDelegate(myPaStreamCallback); PortAudio.Pa_Initialize(); uint sampleFormat = 0; switch (bitDepth) { case 8: sampleFormat = 16; break; case 16: sampleFormat = 8; break; case 24: sampleFormat = 4; break; case 32: sampleFormat = 2; break; default: Console.WriteLine("broken WAV"); break; } //not sure why framesPerBuffer is so strange. PortAudio.PaError error = PortAudio.Pa_OpenDefaultStream(out stream, inputChannels, outputChannels, sampleFormat, sampleRate / outputChannels, (uint)(NUM_SAMPLES / (frameSize * 2)), callbackDelegate, userdata); PortAudio.Pa_StartStream(stream); Thread myThread = new Thread(new ThreadStart(play_loop)); myThread.Start(); }
/// <summary> /// Checks if PA returned an error and logs it /// Returns true on error /// </summary> /// <param name="action">Action identifier (E.g. openStream)</param> /// <param name="errorCode">Result returned by Pa_* call</param> /// <returns>True on error</returns> public bool CheckError(String action, PortAudio.PaError errorCode) { if (_Disposed) { throw new ObjectDisposedException("PortAudioHandle already disposed"); } if (errorCode != PortAudio.PaError.paNoError) { CLog.LogError(action + " error: " + PortAudio.Pa_GetErrorText(errorCode)); if (errorCode == PortAudio.PaError.paUnanticipatedHostError) { PortAudio.PaHostErrorInfo errorInfo = PortAudio.Pa_GetLastHostErrorInfo(); CLog.LogError("- Host error API type: " + errorInfo.hostApiType); CLog.LogError("- Host error code: " + errorInfo.errorCode); CLog.LogError("- Host error text: " + errorInfo.errorText); } return(true); } return(false); }