Csound Csound-dev Csound-tekno Search About

high-quality resampling (Re: [Csnd] dither)

Date2011-12-31 23:08
FromDennis Raddle
Subjecthigh-quality resampling (Re: [Csnd] dither)


On Sat, Dec 31, 2011 at 1:01 PM, Erik de Castro Lopo <mle+la@mega-nerd.com> wrote:
jpff@cs.bath.ac.uk wrote:

> I believe that at that time libsndfile did not implemnet dithering
> although there was an API call.

Thats correct. libsndfile does still not implement dithering.

>  Whether we fixed libsndfile or Csound I
> cannot remember, but my belief is that it should work in all formats.

Dithering is useful for recordings in 16 bits and less. Doing dithering
on say 24 bit audio is a waste of CPU cycles.

I thought about my fundamental problem and I think it has more to do with changing the sample rate (or equivalently speed of playback) in a high-quality fashion.

I have a set of 16/44 samples of a violin, very good recordings. When I play them back with loscil and no frequency shift, they sound fine. However, when I do a frequency shift the quality disappears--they sound crummy. I think what I really need to do is a high-quality frequency shift, which I could ahead of time and store as separate wav files.

What I imagine a high-quality resample needs is: convert 16 bit samples to 24 bits, perform a good digital filtering to resample, and then convert back to 16 bits (WITH very good, appropriate dither).

Can someone give me a clue how to do this?

Date2012-01-01 12:35
Fromjpff@cs.bath.ac.uk
SubjectRe: high-quality resampling (Re: [Csnd] dither)
As ever this is just off my head, but surely the Secret Rabbit Code from
Erik is what you are seeking


> On Sat, Dec 31, 2011 at 1:01 PM, Erik de Castro Lopo
> wrote:
>
>> jpff@cs.bath.ac.uk wrote:
>>
>> > I believe that at that time libsndfile did not implemnet dithering
>> > although there was an API call.
>>
>> Thats correct. libsndfile does still not implement dithering.
>>
>> >  Whether we fixed libsndfile or Csound I
>> > cannot remember, but my belief is that it should work in all formats.
>>
>> Dithering is useful for recordings in 16 bits and less. Doing dithering
>> on say 24 bit audio is a waste of CPU cycles.
>>
>
> I thought about my fundamental problem and I think it has more to do with
> changing the sample rate (or equivalently speed of playback) in a
> high-quality fashion.
>
> I have a set of 16/44 samples of a violin, very good recordings. When I
> play them back with loscil and no frequency shift, they sound fine.
> However, when I do a frequency shift the quality disappears--they sound
> crummy. I think what I really need to do is a high-quality frequency
> shift,
> which I could ahead of time and store as separate wav files.
>
> What I imagine a high-quality resample needs is: convert 16 bit samples to
> 24 bits, perform a good digital filtering to resample, and then convert
> back to 16 bits (WITH very good, appropriate dither).
>
> Can someone give me a clue how to do this?
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
>
>




Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2012-01-01 22:59
FromErik de Castro Lopo
SubjectRe: high-quality resampling (Re: [Csnd] dither)
Dennis Raddle wrote:

> What I imagine a high-quality resample needs is: convert 16 bit samples to
> 24 bits, perform a good digital filtering to resample, and then convert
> back to 16 bits (WITH very good, appropriate dither).

MY suggestion is that after resampling, you store the files as 24 bit
or floating point WAV files so that you don't need to dither them.
CSound should have no problem reading 24 bit or floating point WAV files.

The way I would do this is with the programs:

    sndfile-convert    - Part of libsndfile [0]
    sndfile-resample   - Part of libsamplerate [1]

and the following procedure (assumes oroginal samples are sampled
at 44.1kHz):

    # Convert the file to floating point samples.
    sndfile-convert -float32 original.wav float.wav

    # Resample to 441000 * 1.0594630943592953 (ie on semitome)
    sndfile-resample -by 1.0594630943592953 float.wav resampled.wav

    # Set the sample rate of the file to 44100 again.
    sndfile-convert -override-sample-rate=44100 resampled.wav repitched.wav


The file repitched.wav should be pitched down a semitone.

HTH,
Erik

PS : I am the main author of these two packages.

[0] http://www.mega-nerd.com/libsndfile/
[1] http://www.mega-nerd.com/libsamplerate/

Date2012-01-02 01:05
FromDennis Raddle
SubjectRe: high-quality resampling (Re: [Csnd] dither)
Thanks Eric, looks like great stuff!

But I have to play them back as 16 bit eventually. Somewhere the dither has to come in. I guess if I only use these audio samples as *input* to csound, then the dithering can take place on the csound output.

But then, csound won't dither to file output!

Don't I still need a separate utility to dither 24 bits down to 16?

On Sun, Jan 1, 2012 at 2:59 PM, Erik de Castro Lopo <mle+la@mega-nerd.com> wrote:
Dennis Raddle wrote:

> What I imagine a high-quality resample needs is: convert 16 bit samples to
> 24 bits, perform a good digital filtering to resample, and then convert
> back to 16 bits (WITH very good, appropriate dither).

MY suggestion is that after resampling, you store the files as 24 bit
or floating point WAV files so that you don't need to dither them.
CSound should have no problem reading 24 bit or floating point WAV files.

The way I would do this is with the programs:

   sndfile-convert    - Part of libsndfile [0]
   sndfile-resample   - Part of libsamplerate [1]

and the following procedure (assumes oroginal samples are sampled
at 44.1kHz):

   # Convert the file to floating point samples.
   sndfile-convert -float32 original.wav float.wav

   # Resample to 441000 * 1.0594630943592953 (ie on semitome)
   sndfile-resample -by 1.0594630943592953 float.wav resampled.wav

   # Set the sample rate of the file to 44100 again.
   sndfile-convert -override-sample-rate=44100 resampled.wav repitched.wav


The file repitched.wav should be pitched down a semitone.

HTH,
Erik

PS : I am the main author of these two packages.

[0] http://www.mega-nerd.com/libsndfile/
[1] http://www.mega-nerd.com/libsamplerate/

--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


Send bugs reports to the Sourceforge bug tracker
           https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2012-01-02 01:26
FromErik de Castro Lopo
SubjectRe: high-quality resampling (Re: [Csnd] dither)
Dennis Raddle wrote:

> Thanks Eric, looks like great stuff!
> 
> But I have to play them back as 16 bit eventually. Somewhere the dither has
> to come in. I guess if I only use these audio samples as *input* to csound,
> then the dithering can take place on the csound output.
> 
> But then, csound won't dither to file output!
> 
> Don't I still need a separate utility to dither 24 bits down to 16?

Please realise that every time you add dither, you are adding noise.

If you want to avoid adding noise un-necessarily you need to add as
little dither as possible. This means having all your intermediate
files in a format that doesn't require dither (24 bits or more PCM
or floating point file formats).

The *only* place where it makes any sense to add dither is during the
last, final conversion to 16 bits for CD pressing or something similar.

Erik

Date2012-01-02 01:45
FromDennis Raddle
SubjectRe: high-quality resampling (Re: [Csnd] dither)


On Sun, Jan 1, 2012 at 5:26 PM, Erik de Castro Lopo <mle+la@mega-nerd.com> wrote:

The *only* place where it makes any sense to add dither is during the
last, final conversion to 16 bits for CD pressing or something similar.

Erik


Ok, got it.. but how I add dither? Do your utitilies do it? Does Audacity do it?

Sorry to be fixated on the dither question, but it really improves the sound of my csound-based sampler... I really notice it because the original samples are so darn beautiful and the output so diminished in quality, especially after pitch-shifting.

I guess using 24 bits will make more difference there.

Also I'm a fan of analog recordings, and I see digital as a technology that has to be done "right" in order to approach analog, so I'm just plain curious about how to do it right.

I'm talking about A/D dither here (in the analog domain) and also about ways to preserve a non-correlated noise floor in digital post-processing such as digital mixing.

I'm not asking you to explain it. Just wondering for now if there is a way to dither well without needing to grasp the mathematics involved.

Despite liking analog recordings, I still collect a lot of CDs and I can tell right away when a recording was done well.. good dynamic range, resolution, etc. There must be a number of factors, but surely how digital is processed and how CDs are mastered must be one of them.

Dennis

Date2012-01-02 04:08
FromErik de Castro Lopo
SubjectRe: high-quality resampling (Re: [Csnd] dither)
Dennis Raddle wrote:

> Ok, got it.. but how I add dither? Do your utitilies do it?

No. It was always a feature I intended to add but never got
around to.

> Does Audacity do it?

Not sure.

> Sorry to be fixated on the dither question, but it really improves the
> sound of my csound-based sampler... I really notice it because the original
> samples are so darn beautiful and the output so diminished in quality,
> especially after pitch-shifting.

That is probably more about the quality of the pitch shifting rather
than the lack of dither. Honestly, on well recorded material, telling
the difference between dithered and non-dithered is rather difficult.

> I guess using 24 bits will make more difference there.

Using 24 bits means you aren't adding multiple noise at intermediate
stages of the production/mix process.
 
> I'm talking about A/D dither here (in the analog domain) and also about
> ways to preserve a non-correlated noise floor in digital post-processing
> such as digital mixing.
> 
> I'm not asking you to explain it. Just wondering for now if there is a way
> to dither well without needing to grasp the mathematics involved.

I think dither is overhyped. I suggest you fix your re-pitching
problems first (using at least 24 bits) and master your tracks
to 24 bits or floating point. Then you can worry about dither.

Erik

Date2012-01-02 08:46
FromTito Latini
SubjectRe: high-quality resampling (Re: [Csnd] dither)
AttachmentsNone  None  dither_test.tar.gz  

Date2012-01-02 09:55
Fromjpff@cs.bath.ac.uk
SubjectRe: high-quality resampling (Re: [Csnd] dither)
> But then, csound won't dither to file output!
>

Erik is correct in his advice, but I do not understand this remark.  the
code is there.  Are you saying that it does not work?

(for fanatics it is in InOut/libsnd.c try lines 215-265)

==John ff



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2012-01-02 10:29
FromErik de Castro Lopo
SubjectRe: high-quality resampling (Re: [Csnd] dither)
jpff@cs.bath.ac.uk wrote:

> 
> > But then, csound won't dither to file output!
> >
> 
> Erik is correct in his advice, but I do not understand this remark.  the
> code is there.  Are you saying that it does not work?
> 
> (for fanatics it is in InOut/libsnd.c try lines 215-265)

Yes, that looks like real dithering.

Erik

Date2012-01-02 23:55
Fromrichard duckworth
SubjectRe: high-quality resampling (Re: [Csnd] dither)
Mastering Audio by Bob Katz has plenty of good advice about this subject. Sounds like you'll want to export from Cs in 24 bit and then 'master' the track in a dedicated editor, one which gives plenty of options, say: Soundforge, Soundtrack Pro or one of those. Then you'll have the export capabilities that you need. 
 
Rich Duckworth
Lecturer in Music Technology
Department of Music
House 5
Trinity College
Dublin 2
Ireland

Tel 353 1 896 1500


It's the most devastating moment in a young mans life, when he quite reasonably says to himself, "I shall never play The Dane!"

From: Dennis Raddle <dennis.raddle@gmail.com>
To: csound@lists.bath.ac.uk
Sent: Monday, 2 January 2012, 1:45
Subject: Re: high-quality resampling (Re: [Csnd] dither)



On Sun, Jan 1, 2012 at 5:26 PM, Erik de Castro Lopo <mle+la@mega-nerd.com> wrote:

The *only* place where it makes any sense to add dither is during the
last, final conversion to 16 bits for CD pressing or something similar.

Erik


Ok, got it.. but how I add dither? Do your utitilies do it? Does Audacity do it?

Sorry to be fixated on the dither question, but it really improves the sound of my csound-based sampler... I really notice it because the original samples are so darn beautiful and the output so diminished in quality, especially after pitch-shifting.

I guess using 24 bits will make more difference there.

Also I'm a fan of analog recordings, and I see digital as a technology that has to be done "right" in order to approach analog, so I'm just plain curious about how to do it right.

I'm talking about A/D dither here (in the analog domain) and also about ways to preserve a non-correlated noise floor in digital post-processing such as digital mixing.

I'm not asking you to explain it. Just wondering for now if there is a way to dither well without needing to grasp the mathematics involved.

Despite liking analog recordings, I still collect a lot of CDs and I can tell right away when a recording was done well.. good dynamic range, resolution, etc. There must be a number of factors, but surely how digital is processed and how CDs are mastered must be one of them.

Dennis