PDA

View Full Version : [Frage] process-Methode


Ubik
18-11-2004, 12:16
Habe ein Problem mit dem Audio-Codec. Die process-Methode sieht folgendermaßen aus:


public int process(Buffer input, Buffer output)
{
byte[] inData = (byte[])input.getData();
int inLength = input.getLength();
int inOffset = input.getOffset();
Format inFormat = input.getFormat();

byte[] outData = new byte[inLength];
int outLength = inLength;
int outOffset = output.getOffset();
int j = outOffset;

// Lesen von AudioInputSream (File wurde zuvor erfolgreich geladen)
byte[] shotData = new byte[inLength];
shotStream.read(shotData, 0, inLength);

int numSamples = inLength / 2;
int shotTempH = 0;
int shotTempL = 0;
int tempH;
int tempL;
short shotSample;
short sample;
int shotOffset = 0;

for (int i = 0; i < numSamples; i++)
{
shotTempH = shotData[shotOffset++] & 0xff;
shotTempL = shotData[shotOffset++] & 0xff;
tempH = inData[inOffset++] & 0xff;
tempL = inData[inOffset++] & 0xff;

shotSample = (short)(((shotTempL << 8) | shotTempH) * 0.5f);
sample = (short)(((tempL << 8) | tempH) * 0.5f);
sample = (short)(sample + shotSample);
outData[j++] = (byte)(sample >> 8);
outData[j++] = (byte)(sample & 0xff);
}

output.setData(outData);
output.setLength(outLength);
output.setOffset(outOffset);
output.setFormat(outputFormat);
return (BUFFER_PROCESSED_OK);
}


Das Sample ist zu hören, aber darüber liegt nur Rauschen (und nicht der gewünschte Effekt). Hat jemand eine Ahnung, was hier falsch läuft?