package com.vaadin.addon.audio.server.encoders;

import java.nio.ByteBuffer;

import com.vaadin.addon.audio.server.Encoder;
import com.vaadin.addon.audio.shared.PCMFormat;

/**
 * PCM-to-MSWave encoder.
 */
public class WaveEncoder extends Encoder {

	private PCMFormat outputFormat;
	
	public WaveEncoder() {
		this(null);
	}
	
	public WaveEncoder(PCMFormat outputFormat) {
		this.outputFormat = outputFormat;
	}
	
	@Override
	public byte[] encode(int from_offset, int length) {
		
		PCMFormat infmt = getInputFormat();
		PCMFormat outfmt = outputFormat == null ? infmt : outputFormat;
		
		// TODO: allow different input and output formats - we currently do no conversion
				
		
		return null;
	}

}

@@ -164,16 +164,68 @@
 MFormat;
+%0Aimport com.vaadin.addon.audio.shared.util.WaveUtil;
 %0A%0A/**%0A *
@@ -570,79 +570,11 @@
 ();%0A
+%0A
 %09%09
-PCMFormat outfmt = outputFormat == null ? infmt : outputFormat;%0A%09%09%0A%09%09
 // T
@@ -654,31 +654,391 @@
 sion
+%0A%09%09//PCMFormat outfmt = outputFormat == null ? infmt : outputFormat;%0A%09%09PCMFormat outfmt = infmt;%0A%09%09%0A%09%09int dataLength = infmt.getSampleSize() * length;%0A%09%09%0A%09%09ByteBuffer in = getInputBuffer();%0A%09%09ByteBuffer out = ByteBuffer.allocate(dataLength + WaveUtil.getDataStartOffset(null));
 %0A%09%09
+%0A
 %09%09
-%0A%09%09%0A%09%09return null;
+out.put(WaveUtil.generateHeader(outfmt, length));%0A%09%09out.put(in.array());%0A%09%09%0A%09%09return out.array();%0A%09%09
 %0A%09%7D%0A

Implement WaveEncoder