public unsafe override void Write(ProcessedAudio input, ContentStream writer, WriterContext ctx) { try { writer.Write(input.FrameCount); writer.Write(input.SampleRate); writer.Write(input.Stereo); writer.Write(false); // true = lossy, false = lossless byte * data = (byte *)input.Data.ToPointer(); RLADAudio rlad = input as RLADAudio; uint lmod = input.Stereo ? 2u : 1; uint len = 0; for (uint ci = 0; ci < rlad.ChunkCount; ++ci, data += len) { var stype = rlad.Chunks[ci].Type; var extra = rlad.Chunks[ci].Extra; var head = ((stype & 0x03) << 6) | (extra & 0x3F); writer.Write((byte)(head & 0xFF)); // First calculate the length assuming one chunk of mono data, then correct for stereo and chunk count len = (stype == RLADAudio.SMALL_TYPE) ? 8u : (stype == RLADAudio.MED_TYPE) ? 12u : 16u; len *= (lmod * (extra + 1u)); writer.Write(data, len); } } finally { input.Dispose(); } }
public unsafe override ProcessedAudio Process(RawAudio input, ProcessorContext ctx) { // Preprocessing step for mp3, convert from float to s16 if (input.Format == AudioFormat.Mp3) { ConvertF32ToS16((short *)input.Data.ToPointer(), (float *)input.Data.ToPointer(), input.SampleCount); } // Perform the compression steps try { var proc = RLADAudio.Encode(input, ctx.UseStats, ctx.Logger); return(proc); } finally { input.Dispose(); // Wont do anything if the encoding functions work properly } }