nacker2000
asked on
Convert Wave Sample Rate
Hi all
I am sampling audio from a number of sources mainly at 44100 16bit stereo but some sources are 48000 16bit stereo and I need to convert these sources to 44100.
I have the actual raw audio data available to me in memory so what I am looking for is some code (a function or procedure) which I can pass the audio data pointer and a target sample rate and have it returned in the correct format on-the-fly.
I can do this through the ACM but its not ideal and relies on opening, closing and managing the ACM. I would much prefere it in code.
I have searched the internet on some way to do this or even an explanation of how it could be done but I can't find anything. It's either really easy to do and I am overthinking it or it's just not very well documented.
Any help is appreciated.
Thanks.
I am sampling audio from a number of sources mainly at 44100 16bit stereo but some sources are 48000 16bit stereo and I need to convert these sources to 44100.
I have the actual raw audio data available to me in memory so what I am looking for is some code (a function or procedure) which I can pass the audio data pointer and a target sample rate and have it returned in the correct format on-the-fly.
I can do this through the ACM but its not ideal and relies on opening, closing and managing the ACM. I would much prefere it in code.
I have searched the internet on some way to do this or even an explanation of how it could be done but I can't find anything. It's either really easy to do and I am overthinking it or it's just not very well documented.
Any help is appreciated.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi CodedK
Thanks for your posts. I have been working away on this problem and actually came across this example http://www.delphipraxis.net/topic104889_upsampling+algorithmus.html&highlight=upsampling on the Delphi Praxis site. Its in German but the code is English.
I modified the code so I could convert from any format to any format as in the code snippet.
The example I found and the converted code works the same as the idea you posted.
Both your posts were helpful and the link I posted and the code will hopefully come in handy for someone else.
Thanks for your posts. I have been working away on this problem and actually came across this example http://www.delphipraxis.net/topic104889_upsampling+algorithmus.html&highlight=upsampling on the Delphi Praxis site. Its in German but the code is English.
I modified the code so I could convert from any format to any format as in the code snippet.
The example I found and the converted code works the same as the idea you posted.
Both your posts were helpful and the link I posted and the code will hopefully come in handy for someone else.
type
TWaveSample = record
l: smallint;
r: smallint;
end;
procedure ConvertAudio(_in: TStream; _out: TStream; _inrate: integer = 48000; _outrate: integer = 44100);
var
smpl1,smpl2,smpl3: TWaveSample;
i,i2: int64;
alength: int64;
begin
_in.Position := 0;
alength := round((_in.Size / sizeof(TWaveSample))*(_outrate / _inrate))+1;
i := 0;
if not assigned(_out) then
_out := TMemoryStream.Create;
_out.Position := 0;
while i < alength do
begin
i2 := round(i*(_inrate/_outrate)) * sizeof(TWaveSample);
_in.Position := i2;
_in.Read(smpl1,sizeof(TWaveSample));
smpl2.l := smpl1.l;
smpl2.r := smpl1.r;
_out.Write(smpl2,sizeof(TWaveSample));
i := i + 1;
end;
end;
Thank you my friend.
I'm glad i could help a little :)
I'm glad i could help a little :)
You can use "ACS Audio Component Suite" : http://acs.ullihome.de/acs/index.php/Main_Page
It has a sample rate converter and its free.
Direct download link : http://acs.ullihome.de/acs/downloads/libs.zip
Hope this helps.