Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: What's the meaning of "sample rate" in MP3/Vorbis/AAC? (Read 12128 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

What's the meaning of "sample rate" in MP3/Vorbis/AAC? Wouldn't it be meaningless after transform, same as bit depth?


What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #1
No, the transform occurs on sampled data and so the sample rate determines which samples correspond to which frequencies.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #2
Still. since the data are stored as frequencies and intensities, couldn't it be decoded to any arbitrary sample rate?

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #3
When we say that lossy streams don't have a strictly defined bit depth (as opposed to LPCM streams), it is because the transforms that happen to the signal and the way data is stored make it variable. (Sometimes it's said that for MP3 it is 32bits float, but that's a simplification as well).

Said that, the same is not exactly applicable to sample rate. Even though the frequency bands might or might not have information, the compressed data is specific for one max frequency (so a specific sample rate).


I.e. It is not the same to resample (either from the decoded signal, or by samplerate halving, like older mp3 decoders allowed to do), than to say that the samplerate is not defined for the encoded data.


Two examples:

An MP3 stream can be MPEG1 layer 3, MPEG2 layer 3 and the so-called "MPEG2.5 layer 3". So it can be one of "48Khz, 44.1Khz, 32Khz", "24Khz, 22.05Khz, 16Khz", "12Khz, 11.025Khz, 8Khz". The encoded data is relative to this sample rate, and the decoder (needs and) will use it to generate the decoded stream.

An Opus stream is a 48Khz stream. The encoded data is always at this sample rate, and when decoding, can be resampled to another sample rate. (If the original stream was at 44.1Khz, it can be resampled to that samplerate).

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #4
I'm not intimately acquainted with the details of any of these formats, but from what little I do know, I think many of the answers thus far are misleading.

If you transform a periodic signal with the DCT, and thus really were only storing information in the frequency domain, you could decode that at any sample rate. Yes, like Saratoga said, the original sample rate would normally be used to define a standard list of frequencies so you can just store coefficients rather than both frequencies and coefficients, but you could still natively decode it at any frequency.

But since we're looking at the MDCT, a lapped/windowed transform, the width of the window and the overlap are time-domain information, and combining the windows, and the filtering that allows you to do that without introducing artifacts, surely involves some sample rate inflexibilities. For instance, at most sampling rates the window won't be an integer number of samples.

But it still may be possible to decode at a number of different rates which are integer multiples of each other. In particular, though [JAZ] said "an Opus stream is a 48kHz stream," Opus was designed so it can be decoded at any of 8, 16, 24, or 48 kHz. The native-lower-sampling-rate decoding isn't normally used, since they've only targeted their code for that at highly resource-constrained environments and thus that decoder gives lower quality, so even if you tell opusdec on the PC to give you 16 kHz output it will use its high-quality 48kHz decoding and then downsample, but it is there (and somebody could implement a higher-quality native-24-kHz decoder if they really felt like it).

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #5
fs is part of the MDCT equation.  If you didn't know the sample rate, you wouldn't be able to decode the audio.  Like others have said, you can decode easily to sample rates that are multiples, but you cannot decode to arbitrary sample rates without resampling.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #6
Winamp MP3 decoder still have Full/Half/Quarter quality setting

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #7
Using a dct means you could easily drop the sample rate by a factor of 2^n. This is widely used in jpeg and some old mp3 decoders. But that's just an optimization based on how inverse transforms work. You can't actually decode to an arbitrary sample rate. Converting to the frequency domain doesn't really make much difference for sampling. You still have a well defined sampling rate In the frequency domain.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #8
I still think you're wrong here. Once you've taken a DCT and have stuff represented as a sum of sinusoids you can sample those sinusoids at any intervals, even at nonuniform sampling points. You just can't use the efficiency of the IDCT to do so, so it'll be computationally inefficient.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #9
I still think you're wrong here. Once you've taken a DCT and have stuff represented as a sum of sinusoids you can sample those sinusoids at any intervals, even at nonuniform sampling points. You just can't use the efficiency of the IDCT to do so, so it'll be computationally inefficient.


Could you explain what you mean more precisely? Its difficult to understand what your idea is.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #10
Okay, so the original fs needs to be plugged in somewhere, but isn't it possible (in theory at least) to decode to an arbitrary sample rate < fs? From what's said above it sounds like it's more of a question of decoder design. Or is there just no way to get from the frequency domain data to sample points that aren't aligned with the original sample rate (or 2-n)?

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #11
I think one problem is that we're never doing a Fourier Transform of the entire file.

Instead we do overlapping windowed transforms, which don't preserve all the frequency content of the original file accurately (and spread the single frequencies across multiple bins.

Given that there must be frequency spreading, there will at least be some difficulty in anti-aliasing, and there will also be elements of temporal spreading too.

I admit that I haven't got my head around the whole concept, though it has occurred to me in thinking about things like pitch-shifting or tempo-shifting but I still haven't worked out all the pitfalls.

I know that algorithms like Soundtouch have audible problems especially on multi-instrument/vocalist samples.
Dynamic – the artist formerly known as DickD

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #12
Okay, so the original fs needs to be plugged in somewhere, but isn't it possible (in theory at least) to decode to an arbitrary sample rate < fs?



Like others have said, you can decode easily to sample rates that are multiples, but you cannot decode to arbitrary sample rates without resampling.




You can't actually decode to an arbitrary sample rate.



Are you reading the replies to this thread

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #13
I guess the way I put it does seem like a retread. The thing is, some statements above make it sound like it could be an implementation problem rather than a complete inherent impossibility.

JAZ says "the compressed data is specific for one max frequency". Makes it sound like he refers to decoding to higher frequencies. Then the mention of Opus using 48kHz internally for all sample rates (though, afterwards I found an old discussion that suggest 44.1kHz *is* a problem).

Benski says "If you didn't know the sample rate, you wouldn't be able to decode the audio", makes it sound like just needing the rate for the math. And the "easily" in "can decode easily to sample rates that are multiples" like a problem of complexity.

...sample those sinusoids at any intervals...

Could you explain what you mean more precisely? Its difficult to understand what your idea is.

This is what I was wondering about. Perhaps it's just my oversimplified idea of what the transformed data represents. Taken to an extreme, let's say you have 10 seconds of 1kHz sine wave at a fixed level. If encoding ultimately just means storing the frequency, level, and phase, it seems you should be able to recreate that 1kHz sine wave with as many or as few samples as you'd like. What would actually be stored in such a case?

the sample rate determines which samples correspond to which frequencies.

What does "which samples correspond to which frequencies" mean?

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #14
Benski says "If you didn't know the sample rate, you wouldn't be able to decode the audio", makes it sound like just needing the rate for the math. And the "easily" in "can decode easily to sample rates that are multiples" like a problem of complexity.


I'm interpreting your question to actually ask "Is there some way to start with (M)DCT transformed data and then transform to time domain at an arbitrary sample rate that is algorithmically more efficient than a combination of inverse (M)DCT and resampling. 

My answer is no.  The choice of domain makes no difference with respect to sampling and starting or ending in one domain or the other is orthogonal to questions about sampling.  I can see no way to exploit one to make the other easier.

If encoding ultimately just means storing the frequency, level, and phase, it seems you should be able to recreate that 1kHz sine wave with as many or as few samples as you'd like. What would actually be stored in such a case?


The process of fitting a function to data for purposes of changing the sampling rate is called resampling.  So your idea here is probably something like "resampling then fourier transforming".  This will work but its no different than the usual process once you actually implement it.  You've just expressed the same process in a different way.

the sample rate determines which samples correspond to which frequencies.

What does "which samples correspond to which frequencies" mean?


Are you familiar with the discrete fourier transform (or fast fourier transform)?  In these (and all) discrete fourier transforms, the choice of sampling rate determines which samples in the Fourier domain contain which frequencies.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #15
Mmm.. the tranformation that (most) lossy codecs do from time domain (samples) to frequency domain (frequency bands intensity and phase) does not compress by itself. It might even need more data, depending on the precision.

What codecs use to reduce the bitrate demands is allowing frequencies to be less precise (quantizing the different possible values), coupled with other compressing techniques (joint stereo with less bits for side channel, huffmann compression, parametric audio reconstruction, etc..).

But going back, what you usually get from the transformation is not "frequency 1Hz, x intensity, frequency 2Hz y intensity,...). To get that, you would need to use an FFT of the same size of the sampling rate, and in that case, you would need to say which size it is. (effectively defining the sample rate).

Generally, though, a fixed size (depending on sample rate, to have enough definition) transformation is used. In MP3, it is an overlapped window of 1152 samples (in case of long blocks) (Please, correct me if i am wrong!), which generates 576 frequency bands (and their phases). Those 576 values by themselves don't mean a thing, because there is the same number of bands from a 32Khz wave than from a 48Khz wave.

Concretely, the band 576, for a 32Khz contains frequency information from the frequency 31943Hz to the frequency 31999Hz.
For a 48Khz, that same band contains frequency information from the frequency 47915Hz to the frequency 47999Hz.
It is only on playback that the frequency gets any meaning. And to understand it, you might think on what happens when playing a 22Khz file at 44Khz, or playing an LP of 33RPM at 45RPM.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #16

Concretely, the band 576, for a 32Khz contains frequency information from the frequency 31943Hz to the frequency 31999Hz.
For a 48Khz, that same band contains frequency information from the frequency 47915Hz to the frequency 47999Hz.


As [JAZ] would realise if reading that back, band 576 of the power spectrum reaches up to the Nyquist limit, so reaches 15999.999 Hz at a 32 kHz sampling rate, and 23999.999 Hz at 48 kHz sampling rate, however, that's just putting in specific number to illustrate a point.
Dynamic – the artist formerly known as DickD

 

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #17
Winamp MP3 decoder still have Full/Half/Quarter quality setting


Yes, and it does this by not doing the calculations for all the bands, and only doing a 16 or 8pt iMDCT at the end. Remember that MP3 is cascade of 32 18-pt iMDCTs followed by a 32-pt iMDCT.  This was done mainly to reuse hardware and software from Layer 2 decoders.  From memory, I think there's a step in between that would prevent an implementation from simply using a 576 point MDCT.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #18
So am I understanding correctly that 99.9% of decoding is independent of the original sample rate, and only at the very end where the wav header is filled in does it even matter?

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #19
Winamp MP3 decoder still have Full/Half/Quarter quality setting


Yes, and it does this by not doing the calculations for all the bands, and only doing a 16 or 8pt iMDCT at the end. Remember that MP3 is cascade of 32 18-pt iMDCTs followed by a 32-pt iMDCT.  This was done mainly to reuse hardware and software from Layer 2 decoders.  From memory, I think there's a step in between that would prevent an implementation from simply using a 576 point MDCT.


Its actually a subband decomposition followed by an MDCT on each subband.  So basically when you decode you do the iMDCT which gives you a bunch of MP2 style subbands.  Then you use an inverse filterbank to put the subbands back into a single signal.  The downsample by 2 trick works because of some symmetry in the filterbank that lets you throw away half of the samples in exchange for half as much work in the filterbank.  Since the filterbank is much slower then the iMDCT, this was used on old systems to speed up decoding.  Its not really useful though once you break ~50-60MHz CPUs. 

So am I understanding correctly that 99.9% of decoding is independent of the original sample rate, and only at the very end where the wav header is filled in does it even matter?


No, I would say the opposite.  In a transform codec, entire lossy decoding process (everything after huffman decoding) depends on the sample rate.

Edit:  For example, a lot of codecs don't even use the same MDCT at different sample rates (e.g. Vorbis, WMA).


What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #21

That might work for current CPU's, but a 486DX2 66Mhz needed to play it at 22Khz


Which decoder?  Early 90s ARM processors do full 32 bit output at less than 50 MHz, but you need to do fixed point + quite a bit of optimization.  I don't know much about the 486 processor, but I didn't think it was much slower than early 90s ARM chips.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #22
Winamp with the in-house decoder (i.e. not the frauhoffer decoder) that they used at the time. (I'm not sure if it was already winamp 2, or still winamp 1.7 or so). No MMX, probably x87 math...

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #23

Winamp with the in-house decoder (i.e. not the frauhoffer decoder) that they used at the time. (I'm not sure if it was already winamp 2, or still winamp 1.7 or so). No MMX, probably x87 math...


x87 is definitely not going to work, but integer should be a lot faster.  I actually don't know if any fixed point decoders were popular back then, libmad dates back to 2000, so I guess it couldn't have been used in those old DOS decoders.

What's the meaning of "sample rate" in MP3/Vorbis/AAC?

Reply #24
My recollection is that Winamp 1.7 running under Windows 95 on a Pentium 60 was just capable of decoding MP3 at 44.1kHz (typically encoded by l3enc at 192kbps CBR) and MP2 (from CoolEdit96 plugin) at 192-224 kbps, but my Mum's PC, around the spec [JAZ] mentioned needed 22.05kHz playback.

Encoding used to take forever, but disc space was so scarce, it was worth it. Fortunately, I didn't switch to Xing for the speed up.
Dynamic – the artist formerly known as DickD