Okay couldn´t come up with a good topic.
The point is, i have a code which i got help with that´s changing the bit depth from 32bit to 16bit, not sure how it works, but i think it simply just removes every other bit, nothing fancy.
So if it´s possible to do that with the code, it should be possible to change the samplerate. Also i don´t want something fancy here as it´s more for debugging uses, i just want to make it into some other samplerate, it doesn´t have to be a "resampling".
Meaning for example, if the audio is 48khz, and i resample it while it plays to 47khz, it won´t sound the same as it still think it´s 48khz, meaning it will play it slower.
So in other words i am going to use it for changing the speed of the audio in a very simple way.
here is the code to change bit depth which i hope can be reused for this.
Int32 bytesrecorded = e.BytesRecorded;
byte[] newArray16Bit = new byte[bytesrecorded / 2];
fixed (byte* sourcePtr = e.Buffer)
fixed (byte* targetPtr = newArray16Bit)
{
float* sourceTyped = (float*)sourcePtr;
short* targetTyped = (short*)targetPtr;
Int32 count = bytesrecorded / 4;
for (int i = 0; i < count; i++)
{
targetTyped[i] = (Int16)(sourceTyped[i] * Int16.MaxValue);
}
}
e.Bytesrecorded
= the size of the audio buffer,
e.Buffer
= the actual buffer
As i don´t fully understand this, i simply look at the /2 and assume it just divides teh length of the size, then the /4 part will be moving the bytes around to make it fit.
Though i don´t know how i can use this to change the samplerate, as this is just bytes moving around, it shouldn´t be to hard to make something for the samplerate.
Thanks