public bool TryDequeue (out FLACPacket packet) { return mQueue.TryDequeue (out packet); }
public void Enqueue (FLACPacket packet) { mQueue.Enqueue (packet); }
public bool TryPeek (out FLACPacket packet) { return mQueue.TryPeek (out packet); }
/// <summary> /// FLAC Write Call Back - libFlac notifies back on a frame that was read from the source file and written as a frame /// </summary> /// <param name="context"></param> /// <param name="frame"></param> /// <param name="buffer"></param> /// <param name="clientData"></param> protected LibFLAC.StreamDecoderWriteStatus WriteCallback(IntPtr context, IntPtr frame, IntPtr buffer, IntPtr clientData) { // Read the FLAC Frame into a memory samples buffer (m_flacSamples) LibFLAC.FlacFrame flacFrame = (LibFLAC.FlacFrame)Marshal.PtrToStructure(frame, typeof(LibFLAC.FlacFrame)); // TODO: Write functions for handling 8-bit audio as well if (flacFrame.Header.BitsPerSample != 16) { mLogger.Warning(string.Format("FLAC: Unsupported bit-rate: {0}", flacFrame.Header.BitsPerSample)); return LibFLAC.StreamDecoderWriteStatus.WriteStatusAbort; } // TODO : POSSIBLE OPTIMIZATION - FLACPacket object pool var packet = new FLACPacket (); packet.Channels = flacFrame.Header.Channels; //packet.Format = this.Format; packet.SampleRate = flacFrame.Header.SampleRate; packet.BlockSize = flacFrame.Header.BlockSize; packet.Offset = 0; CopyRawFLACBufferData (buffer, 0, ref mFLACChannelData_Mono_0, packet.BlockSize); // 16 bit only if (packet.Channels == 2) { // Stereo CopyRawFLACBufferData (buffer, 1, ref mFLACChannelData_Stereo_1, packet.BlockSize); // TODO : POSSIBLE OPTIMIZATION - byte[] object pool packet.Data = new byte[4 * packet.BlockSize]; uint writePosition = 0; for(uint i = 0; i < packet.BlockSize; i++) { int leftChannel = mFLACChannelData_Mono_0[i]; int rightChannel = mFLACChannelData_Stereo_1[i]; packet.Data[writePosition++] = (byte)(leftChannel >> 0); packet.Data[writePosition++] =(byte)(leftChannel >> 8); packet.Data[writePosition++] = (byte)(rightChannel >> 0); packet.Data[writePosition++] = (byte)(rightChannel >> 8); } } else { // TODO : POSSIBLE OPTIMIZATION - byte[] object pool packet.Data = new byte[2 * packet.BlockSize]; uint writePosition = 0; // Mono for(uint i = 0; i < packet.BlockSize; i++) { int leftChannel = mFLACChannelData_Mono_0[i]; packet.Data[writePosition++] = (byte)(leftChannel >> 0); packet.Data[writePosition++] = (byte)(leftChannel >> 8); } } mPacketQueue.Enqueue (packet); return LibFLAC.StreamDecoderWriteStatus.WriteStatusContinue; }