I am trying to increase the size of 8000hz, 16-bit wav file to 11025hz in AS3. At the moment, I'm not worried about applying low-pass filters, which, as I know, I will eventually need.
I was linking to this wiki page .
Here is what I have done so far:
- The smallest total number equal to 3,528,000
- The calculated L should be 441
- Calculated M will be 320
- Added 440 zeros between swatches
- Every 320th sample is written on a new byte array
However, when I go to play the new wav, it is an indistinguishable noise. Here is my code:
const sourceRate:uint = 8000;
const targetRate:uint = 11025;
var lcm:uint = lcm(targetRate, sourceRate);
var l:uint = lcm / sourceRate;
var m:uint = lcm / targetRate;
var upsampleData:ByteArray = new ByteArray();
upsampleData.endian = Endian.LITTLE_ENDIAN;
while(originalWavData.bytesAvailable > 1) {
upsampleData.writeBytes(fill);
upsampleData.writeShort(originalWavData.readShort());
}
var downsampleData:ByteArray = new ByteArray();
downsampleData.endian = Endian.LITTLE_ENDIAN;
upsampleData.position = 0;
for(var k:uint=0; k<upsampleData.length; k++) {
upsampleData.position = k * m;
if(upsampleData.bytesAvailable < 2) break;
downsampleData.writeShort(upsampleData.readShort());
}
Can someone show me what I'm doing wrong in my code? This is my first question, so if I forgot something or you need to provide more information, please let me know.
Thank!
Update:
Aric , :
function interpolate(y0:int, y1:int, numSamples:uint):ByteArray {
var b:ByteArray = new ByteArray();
b.endian = Endian.LITTLE_ENDIAN;
var m:Number = Math.round((y1-y0)/numSamples);
for(var i:uint=0; i<numSamples; i++) {
var n:int = m * i + y0;
b.writeShort(n);
}
b.position = 0;
return 0;
}
var n1:int = 0;
while(originalWavData.bytesAvailable > 1) {
var sample:int = originalWavData.readShort();
upsampleData.writeBytes(interpolate(n1, sample, (l-1)));
n1 = sample;
}
while(upsampleData.bytesAvailable > 1) {
downsampleData.writeShort(upsampleData.readShort());
upsampleData.position += ((m-1)*2);
}
, : , . , - , . n1 . , , , M- , .
, 1000 , , . .