public WaveInRecorder(int device, WaveFormat format, int bufferSize, int bufferCount, BufferDoneEventHandler doneProc) { m_DoneProc = doneProc; WaveInHelper.Try(WaveNative.waveInOpen(out m_WaveIn, device, format, m_BufferProc, 0, WaveNative.CALLBACK_FUNCTION)); AllocateBuffers(bufferSize, bufferCount); for (int i = 0; i < bufferCount; i++) { SelectNextBuffer(); m_CurrentBuffer.Record(); } WaveInHelper.Try(WaveNative.waveInStart(m_WaveIn)); m_Thread = new Thread(new ThreadStart(ThreadProc)); m_Thread.Start(); }
/// <summary> /// Create a Mp3Writer with specific MP3 format /// </summary> /// <param name="Output">Stream that will hold the MP3 resulting data</param> /// <param name="InputDataFormat">PCM format of input data</param> /// <param name="Mp3Config">Desired MP3 config</param> public Mp3Writer(Stream Output, WaveFormat InputDataFormat, BE_CONFIG Mp3Config) : base(Output, InputDataFormat) { try { m_Mp3Config = Mp3Config; uint LameResult = Lame_encDll.beInitStream(m_Mp3Config, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream); if ( LameResult != Lame_encDll.BE_ERR_SUCCESSFUL) { throw new ApplicationException(string.Format("Lame_encDll.beInitStream failed with the error code {0}", LameResult)); } m_InBuffer = new byte[m_InputSamples*2]; //Input buffer is expected as short[] m_OutBuffer = new byte[m_OutBufferSize]; } catch { base.Close(); throw; } }
/// <summary> /// A constructor with this signature must be implemented by descendants. /// <see cref="System.Runtime.Serialization.ISerializable"/> for more information /// </summary> /// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo"/> where is the serialized data.</param> /// <param name="context">The source (see <see cref="System.Runtime.Serialization.StreamingContext"/>) for this serialization.</param> protected AudioWriterConfig(SerializationInfo info, StreamingContext context) { int rate = info.GetInt32("Format.Rate"); int bits = info.GetInt32("Format.Bits"); int channels = info.GetInt32("Format.Channels"); m_Format = new WaveFormat(rate, bits, channels); }
public AudioWriterConfig(WaveFormat f) { m_Format = new WaveFormat(f.nSamplesPerSec, f.wBitsPerSample, f.nChannels); }
public void StartRecording() { Logging.Instance.WriteLine("Starting recording..."); StopRecording(); Logging.Instance.WriteLine("StartRecording has stoped recording"); try { WaveFormat fmt = new WaveFormat(44100, 16, 2); Logging.Instance.WriteLine("Created fmt"); Mp3WriterConfig config = new Mp3WriterConfig(fmt); Logging.Instance.WriteLine("created config"); if (filePath == null) { Logging.Instance.WriteLine("File Path is null"); filePath = GetFilePath(); Logging.Instance.WriteLine("File Path:" + filePath); } //DoRecord = false; currentFile = new FileStream(filePath, FileMode.Append); m_Writer = new Mp3Writer(currentFile, config); Logging.Instance.WriteLine("writer intialized"); m_Recorder = new WaveInRecorder(-1, fmt, 16384, 3, new BufferDoneEventHandler(DataArrived)); Logging.Instance.WriteLine("recorder initialized"); } catch (Exception ex) { Logging.Instance.WriteLine(ex.StackTrace); StopRecording(); throw ex; } Logging.Instance.WriteLine("leaving start recording"); }
public AudioWriter(Stream Output, WaveFormat InputDataFormat) : base(Output, System.Text.Encoding.ASCII) { m_InputDataFormat = InputDataFormat; }
/// <summary> /// Create a Mp3Writer with the default MP3 format /// </summary> /// <param name="Output">Stream that will hold the MP3 resulting data</param> /// <param name="InputDataFormat">PCM format of input data</param> public Mp3Writer(Stream Output, WaveFormat InputDataFormat) : this(Output, InputDataFormat, new BE_CONFIG(InputDataFormat)) { }
public static extern int waveInOpen(out IntPtr phwi, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
public Format(WaveFormat format, uint MpeBitRate) { lhv1 = new LHV1(format, MpeBitRate); }
public BE_CONFIG(WaveFormat format) : this(format, 128) { }
public BE_CONFIG(WaveFormat format, uint MpeBitRate) { this.dwConfig = BE_CONFIG_LAME; this.format = new Format(format, MpeBitRate); }
public ushort nQuality; // Quality Setting, HIGH BYTE should be NOT LOW byte, otherwhise quality=5 #region Constructors // FUTURE USE, SET TO 0, align strucutre to 331 bytes //[ MarshalAs( UnmanagedType.ByValArray, SizeConst=255-4*4-2 )] //public byte[] btReserved;//[255-4*sizeof(DWORD) - sizeof( WORD )]; public LHV1(WaveFormat format, uint MpeBitRate) { if ( format.wFormatTag != (short)WaveFormats.Pcm ) { throw new ArgumentOutOfRangeException("format", "Only PCM format supported"); } if ( format.wBitsPerSample != 16) { throw new ArgumentOutOfRangeException("format", "Only 16 bits samples supported"); } dwStructVersion = 1; dwStructSize = (uint)Marshal.SizeOf(typeof(BE_CONFIG)); switch (format.nSamplesPerSec) { case 16000 : case 22050 : case 24000 : dwMpegVersion = MPEG2; break; case 32000 : case 44100 : case 48000 : dwMpegVersion = MPEG1; break; default : throw new ArgumentOutOfRangeException("format", "Unsupported sample rate"); } dwSampleRate = (uint)format.nSamplesPerSec; // INPUT FREQUENCY dwReSampleRate = 0; // DON'T RESAMPLE switch (format.nChannels) { case 1 : nMode = MpegMode.MONO; break; case 2 : nMode = MpegMode.STEREO; break; default: throw new ArgumentOutOfRangeException("format", "Invalid number of channels"); } switch (MpeBitRate) { case 32 : case 40 : case 48 : case 56 : case 64 : case 80 : case 96 : case 112 : case 128 : case 160 : //Allowed bit rates in MPEG1 and MPEG2 break; case 192 : case 224 : case 256 : case 320 : //Allowed only in MPEG1 if (dwMpegVersion != MPEG1) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } break; case 8 : case 16 : case 24 : case 144 : //Allowed only in MPEG2 if (dwMpegVersion != MPEG2) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } break; default : throw new ArgumentOutOfRangeException("MpsBitRate", "Unsupported bit rate"); } dwBitrate = MpeBitRate; // MINIMUM BIT RATE nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY; // QUALITY PRESET SETTING dwPsyModel = 0; // USE DEFAULT PSYCHOACOUSTIC MODEL dwEmphasis = 0; // NO EMPHASIS TURNED ON bOriginal = 1; // SET ORIGINAL FLAG bWriteVBRHeader = 0; bNoRes = 0; // No Bit resorvoir bCopyright = 0; bCRC = 0; bEnableVBR = 0; bPrivate = 0; bStrictIso = 0; dwMaxBitrate = 0; dwVbrAbr_bps = 0; nQuality = 0; nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; nVBRQuality = 0; }
public Mp3WriterConfig(WaveFormat InFormat) : this(InFormat, new BE_CONFIG(InFormat)) { }
public Mp3WriterConfig(WaveFormat InFormat, BE_CONFIG beconfig) : base(InFormat) { m_BeConfig = beconfig; }