Reply by alex October 24, 20102010-10-24
Il 12/10/2010 14.58, Richard Dobson ha scritto:
> On 12/10/2010 08:53, Viv wrote: >> Hi all, > .. >> 1) I get a file with some audio with the following attributes: >> Frequency 44k, bps (bits per seconds) 16, Channels 1 and I have to >> convert it to: Frequency 11k, bps 12, Channels 1. >> > Is this something you have been asked to do, or something you have > yourself decided to do? > > No such thing as "bits per second", as such, in an audiofile. The > numbers relate to "bits per sample" - hence a 16bit file. A 12bit sample > is extremely strange these days, and is unsupported either by standard > audio hardware or most standard soundfile formats. Where has that > requirement come from? The only file format that could handle it is > WAVEFORMATEXTENSIBLE, in which you can define a 12bit sample inside a > 16bit word (hence, no saving of storage space). If you are supposed to > be making a compressed file (e.g. two 12bit samples packed into three > bytes), you will have to code that yourself from first principles, and > use some custom file format to contain it. I can't think of any > published tools or code that will package samples like that. > > The sample rate conversion is reasonable enough (especially if you > actually mean 11025Hz), the word reduction is very unusual these days. > Decades ago some hardware employed 12bit samples (the Ensoniq EPS comes > to mind) - is that the sort of thing you are targetting? The word > reduction is really the aspect that gives the most trouble here. So you > will need a Very Good Reason for needing that. >
i have an old consumer sony DAT which, in LP mode, work at 32kHz 12bit stereo (32 * 12 is exactly half bandwidth of 48 * 16). I heard about 4 channels DAT machines in the past with the same 4*32*12. Once i transferred a DAT tape recorded in LP into my daw via spdif and i got 32kHz 16bit with the less meaningful 4 bits obviously filled with zeroes. The spdif itself produce the full bitdepth on the output even if the source is 12. I needed my old digigram card because the other hardware i own is not capable of 32kHz even with foreign clock source. I never seen 12 bits on computer files.
>> >> I am not familiar neither with audio files nor with the resampling >> concept. > > Given your strange requirements, with regard to both sample rate and > word size, you will need to become as familiar as possible with audio > file formats. > > >> My problem is that the library itself doesn't have any documentation, >> also I couldn't find anywhere on internet a usage sample of the >> library and the only documentation that I seem to find is something > > > See the readme file, and the code examples supplied with the package. > Libresample is a C library targetted at C programmers, who are assumed > to know how to use such a library and learn all they need from the > example test applications supplied. This shows you that you will in any > case need a soundfile library to read and write soundfiles, e.g. > libsndfile (which is GPL). If you need simply to make a program to do a > task, and which is not to be distributed, it matters not at all what the > code licence is. So you may be much better off using libsamplerate, > which comes with lots of documentation and examples. > > Richard Dobson >
Reply by Stuart Barkley October 24, 20102010-10-24
On Tue, 12 Oct 2010 at 03:53 -0000, Viv wrote:

> I was told to find out a library, preferably LGPL, but in a worst > case scenario also a commercial one would be ok, that would do > resampling.
Using a library implies you will write some program code (presumably in C). If you are looking for an application program to use I would suggest using sox (see: http://sox.sourceforge.net/ ). sox will do all you ask at a command line prompt (and lots more).
> Some scenarios where I will have to use this would be: > > 1) I get a file with some audio with the following attributes: > Frequency 44k, bps (bits per seconds) 16, Channels 1 and I have to > convert it to: Frequency 11k, bps 12, Channels 1.
As others mentioned 'bps' here is wrong in various possible ways. 12-bit samples sounds like you might be dealing with some voip audio data, which is a whole other area. Also, some of your other numbers appear to be rounded. You need to be very exact with these numbers if you want things to work correctly. You probably mean 44100 (instead of 44k), 11025 (instead of 11k) and 22500 (instead of 22k). Assuming proper .wav files (which include the sample rate in the header) the sox command/application you could use might be: 1) sox input.wav output.wav rate 11k Changing the number of bit per sample requires additional considerations (file format, codec, dithering, etc).
> 2) I get 2 audio files: > - file 1: Freq 22k, bps 16, Channels 1 > - file 2: Freq 22k, bps 16, Channels 1 > and I have to merge them and convert them either to: > a) Freq 22k, bps 16, Channels 1 > or > b) Freq 22k, bps 16, Channels 2
Sample rate conversion libraries won't help with these as there is no change in sample rate needed. libsndfile may be helpful to do file I/O if you really want to write a program in C. For sox command line you could use: 2a) sox -m file1.wav file2.wav output.wav 2b) sox -M file1.wav file2.wav output.wav
> Note: The files might be as big as 200MB.
Shouldn't be an issue with today's computers.
> I am not familiar neither with audio files nor with the resampling > concept. I read about it and I found out that there are 3 libraries > that one can use: > https://ccrma.stanford.edu/~jos/resample/Free_Resampling_Software.html > resample, libresample and libsamplerate > > I decided to go for the second one: libresample by Dominic Mazzoni b/c > it's LGPL licensed. > > My problem is that the library itself doesn't have any documentation,
I would use libsamplerate. See: http://www.mega-nerd.com/SRC/api.html This looks like sufficient documentation for your needs. Specifically: http://www.mega-nerd.com/SRC/api_simple.html has sufficient information to program a simple application to convert sample rates for standalone data inside a program. You will need additional code to read and write audio files. I use and suggest libsndfile (see: http://www.mega-nerd.com/libsndfile ).
> also I couldn't find anywhere on internet a usage sample of the > library and the only documentation that I seem to find is something > like: > > https://ccrma.stanford.edu/~jos/resample/ > > which is too technical for what I need, as I don't think I need to > understand all that math behind the lib, but I do need to understand > what source, factor, etc means in order to use the lib.
If you are doing a class project or a one time use application you can ignore most of this. You should not need this to write a basic C program. You will eventually need to understand this to get everything to high sound quality or to understand the library source code. You will also need to deal with lots of other math if you are doing a serious application for professional use (filtering, dithering, clipping, format conversions, audio codecs).
> Can somebody point out a place where I could see how to use the > library (libresample by Dominic Mazzoni) in order to achieve the > scenarios I described above? What calls do I have to make? What input > should I pass? What would be the values of the parameters? And what > should I expect as output?
I would use libsamplerate which does have documentation. You can also pay the author $AU 1000 if the GPL doesn't work for you. It also depends very much on unstated requirements. One time use on single files? real time use with audio interfaces? How much variability in number of sources and how they need to be combined? Stuart Barkley -- I've never been lost; I was once bewildered for three days, but never lost! -- Daniel Boone
Reply by Mark October 12, 20102010-10-12
> > Can somebody point out a place where I could see how to use the > library (libresample by Dominic Mazzoni) in order to achieve the > scenarios I described above? What calls do I have to make? What input > should I pass? What would be the values of the parameters? And what > should I expect as output? > > Thank you in advance, > Any tip would be appreciated! > Viv
if you are asking for code that you can embed in another program, then I suggest you ask the question again over at comp.dsp.. if you just need to get it done and a stand alone program will work for you , look at SWITCH: http://www.nch.com.au/switch/index.html?gclid=CM7suZTZzaQCFQY65QodJScAjA Mark
Reply by Steve Pope October 12, 20102010-10-12
Viv  <vcotirlea@hotmail.com> wrote:

>Hi all,
>I really hope this is the right place to post my question because I >really need some guidance from some experts.
>I was told to find out a library, preferably LGPL, but in a worst case >scenario also a commercial one would be ok, that would do resampling.
>Some scenarios where I will have to use this would be:
>1) I get a file with some audio with the following attributes: >Frequency 44k, bps (bits per seconds) 16, Channels 1 and I have to >convert it to: Frequency 11k, bps 12, Channels 1.
>2) I get 2 audio files: >- file 1: Freq 22k, bps 16, Channels 1 >- file 2: Freq 22k, bps 16, Channels 1 >and I have to merge them and convert them either to: >a) Freq 22k, bps 16, Channels 1 >or >b) Freq 22k, bps 16, Channels 2 >Note: The files might be as big as 200MB.
>I am not familiar neither with audio files nor with the resampling >concept. I read about it and I found out that there are 3 libraries >that one can use: >https://ccrma.stanford.edu/~jos/resample/Free_Resampling_Software.html >resample, libresample and libsamplerate
>I decided to go for the second one: libresample by Dominic Mazzoni b/c >it's LGPL licensed.
>My problem is that the library itself doesn't have any documentation, >also I couldn't find anywhere on internet a usage sample of the >library and the only documentation that I seem to find is something >like: >https://ccrma.stanford.edu/~jos/resample/ >which is too technical for what I need, as I don't think I need to >understand all that math behind the lib, but I do need to understand >what source, factor, etc means in order to use the lib.
>Can somebody point out a place where I could see how to use the >library (libresample by Dominic Mazzoni) in order to achieve the >scenarios I described above? What calls do I have to make? What input >should I pass? What would be the values of the parameters? And what >should I expect as output?
You've left out some information. Do you need to do this exactly once, on one set of audio files, and then your project is complete? Or do you need to do it on an ongoing basis, but perhaps in software on a non-real-time basis? Or do you need to do it in real-time? If so, do you need just one instance of the machine that does it in real-time, say for a lab setup; or are you building a product that does this continuously, perhaps a high-volume product with cost/power constraints? Further: It is not clear what is meant by "merge". You are correct that a DSP library should have the sort of functions you need, but quite obviously an undocumented library is of no use, even to an expert. These functions could be written in bare C++ code without a library. Or they could be written in Matlab (license cost a few thousand $ for one instance, which could run multiple such jobs). Hope this helps. Steve
Reply by Richard Dobson October 12, 20102010-10-12
On 12/10/2010 08:53, Viv wrote:
> Hi all,
..
> 1) I get a file with some audio with the following attributes: > Frequency 44k, bps (bits per seconds) 16, Channels 1 and I have to > convert it to: Frequency 11k, bps 12, Channels 1. >
Is this something you have been asked to do, or something you have yourself decided to do? No such thing as "bits per second", as such, in an audiofile. The numbers relate to "bits per sample" - hence a 16bit file. A 12bit sample is extremely strange these days, and is unsupported either by standard audio hardware or most standard soundfile formats. Where has that requirement come from? The only file format that could handle it is WAVEFORMATEXTENSIBLE, in which you can define a 12bit sample inside a 16bit word (hence, no saving of storage space). If you are supposed to be making a compressed file (e.g. two 12bit samples packed into three bytes), you will have to code that yourself from first principles, and use some custom file format to contain it. I can't think of any published tools or code that will package samples like that. The sample rate conversion is reasonable enough (especially if you actually mean 11025Hz), the word reduction is very unusual these days. Decades ago some hardware employed 12bit samples (the Ensoniq EPS comes to mind) - is that the sort of thing you are targetting? The word reduction is really the aspect that gives the most trouble here. So you will need a Very Good Reason for needing that.
> > I am not familiar neither with audio files nor with the resampling > concept.
Given your strange requirements, with regard to both sample rate and word size, you will need to become as familiar as possible with audio file formats.
> My problem is that the library itself doesn't have any documentation, > also I couldn't find anywhere on internet a usage sample of the > library and the only documentation that I seem to find is something
See the readme file, and the code examples supplied with the package. Libresample is a C library targetted at C programmers, who are assumed to know how to use such a library and learn all they need from the example test applications supplied. This shows you that you will in any case need a soundfile library to read and write soundfiles, e.g. libsndfile (which is GPL). If you need simply to make a program to do a task, and which is not to be distributed, it matters not at all what the code licence is. So you may be much better off using libsamplerate, which comes with lots of documentation and examples. Richard Dobson
Reply by Viv October 12, 20102010-10-12
Hi all,

I really hope this is the right place to post my question because I
really need some guidance from some experts.

I was told to find out a library, preferably LGPL, but in a worst case
scenario also a commercial one would be ok, that would do resampling.

Some scenarios where I will have to use this would be:

1) I get a file with some audio with the following attributes:
Frequency 44k, bps (bits per seconds) 16, Channels 1 and I have to
convert it to: Frequency 11k, bps 12, Channels 1.

2) I get 2 audio files:
- file 1: Freq 22k, bps 16, Channels 1
- file 2: Freq 22k, bps 16, Channels 1
and I have to merge them and convert them either to:
a) Freq 22k, bps 16, Channels 1
or
b) Freq 22k, bps 16, Channels 2
Note: The files might be as big as 200MB.

I am not familiar neither with audio files nor with the resampling
concept. I read about it and I found out that there are 3 libraries
that one can use:
https://ccrma.stanford.edu/~jos/resample/Free_Resampling_Software.html
resample, libresample and libsamplerate

I decided to go for the second one: libresample by Dominic Mazzoni b/c
it's LGPL licensed.

My problem is that the library itself doesn't have any documentation,
also I couldn't find anywhere on internet a usage sample of the
library and the only documentation that I seem to find is something
like:
https://ccrma.stanford.edu/~jos/resample/
which is too technical for what I need, as I don't think I need to
understand all that math behind the lib, but I do need to understand
what source, factor, etc means in order to use the lib.

Can somebody point out a place where I could see how to use the
library (libresample by Dominic Mazzoni) in order to achieve the
scenarios I described above? What calls do I have to make? What input
should I pass? What would be the values of the parameters? And what
should I expect as output?

Thank you in advance,
Any tip would be appreciated!
Viv