?
Solved

Convert Wave Sample Rate

Posted on 2007-12-03
4
Medium Priority
?
864 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:nacker2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 16

Expert Comment

by:CodedK
ID: 20404123
Hi nacker2000.

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.
0
 
LVL 16

Accepted Solution

by:
CodedK earned 1500 total points
ID: 20404173
Also take a look at this PAQ:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20572504.html
~-~-~-~-~-~-~-~-~-~-~-~-~-
To convert from 22.05 KHz to 11.025: Create another buffer that is half the size, and loop through the original buffer copying a sample and droping the next and so on until the end of buffer.

A single sample size is MS * SR
Where MS is 1 for mono, 2 for stereo
and SR is 1 for 8 bit and 2 for 16 bit.
~-~-~-~-~-~-~-~-~-~-~-~-~-
0
 
LVL 5

Author Comment

by:nacker2000
ID: 20412731
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.
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;

Open in new window

0
 
LVL 16

Expert Comment

by:CodedK
ID: 20412776
Thank you my friend.
I'm glad i could help a little :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question