RE: sample rate conversion
RE: sample rate conversion
- Subject: RE: sample rate conversion
- From: "Edwards, Waverly" <email@hidden>
- Date: Tue, 7 Sep 2010 09:25:22 -0500
- Acceptlanguage: en-US
- Thread-topic: sample rate conversion
I'm feeling a bit dense here. I am attempting to do everything in memory. My test (reading file) is a 10 second file with a 22050 sample rate, which gives me 220500 samples.
I read the data into memory. I setup my output ASBD for the following. After reading the file I think I should have 441000 samples (resampled from 220500) but I do not.
audioOutFormat.mFormatID = kAudioFormatLinearPCM;
audioOutFormat.mSampleRate = 44100.0;
audioOutFormat.mChannelsPerFrame = numChannels;
audioOutFormat.mBytesPerPacket = 2 * numChannels;
audioOutFormat.mFramesPerPacket = 1;
audioOutFormat.mBytesPerFrame = 2 * numChannels;
audioOutFormat.mBitsPerChannel = 16;
audioOutFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
I am performing calculations and manipulations on the data in memory with the end goal of manually mixing the two files.
It occurred to me that if I dont have the same sample rate, this will not work. I have two problems.
The first is that I cant seem to figure out how to get the conversion done and available to me in memory without have to write the data out to disk
and then reading it back in. The second was really unexpected. When I wrote my 10 second 22050 sample rate file out to disk, it reads back as a
5 second 44100 sample rate. The sample rate was desired but the play duration was half the length.
Am I going about this the wrong way?
________________________________________
From: Brian Willoughby [email@hidden]
Sent: Friday, September 03, 2010 8:35 PM
To: Edwards, Waverly
Cc: email@hidden
Subject: Re: sample rate conversion
On Sep 3, 2010, at 17:17, Edwards, Waverly wrote:
> I am working with ExtAudioFile API's and I hit a snag that I have
> not been
> able to figure out how to work through. I have two file both with
> different
> sample rates. I plan to mix the two files but I concluded that I
> need to
> ensure that the sample rates are the same, otherwise I will not be
> able
> to properly mix the two files. I've been reading the documentation
> but
> I havent found anything that would satisfy this need. Would someone
> suggest a solution and even better, if there is an example that I
> can look
> at.
You're on the right track. I suggest that you write your code to
determine which of the files has the higher sample rate, and then use
the ExtAudioFile API to set the client format for the other file -
the one with the lower sample rate - to match the higher one. Then,
when you get data from ExtAudioFile for the lower-quality file, it
will be converted.
In contrast, AudioFile does not offer a client data format that is
different from the file format. You would need to create your own
AudioConverter object to handle that. Thankfully, ExtAudioFile
handles this for you, but you still need to tell it what client
format you prefer (e.g. you could decide to use a lower sample rate,
or even a much higher sample rate that is a common factor of both
input sample rates, for improved mixing quality - there are many
options).
There is sample source on your drive for afconvert, which should show
how this is done.
Brian Willoughby
Sound Consulting
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden