electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Normalizing the volume of short samples
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
sebpiq



Joined: Apr 02, 2011
Posts: 4
Location: finland

PostPosted: Sat Aug 27, 2011 1:15 am    Post subject: Normalizing the volume of short samples Reply with quote  Mark this post and the followings unread

Hi !

I am trying to normalize several samples that have different volume levels ...

For this, I am trying to calculate RMS on those samples, but even that, I don't manage to do Crying or Very sad

Here is my code :

Code:

SndBuf b => FFT fft =^ RMS rms => blackhole;
"sons/1.wav" => b.read;
0 => b.pos;

// set parameters
b.samples() => fft.size;
// set hann window
Windowing.hann(b.samples()) => fft.window;
// upchuck: take fft then rms
rms.upchuck() @=> UAnaBlob blob;
// advance time
fft.size()::samp => now;
// print out RMS
<<< blob.fval(0) >>>;


First problem, is that it always outputs "0.0" ... so what am I doing wrong ?

Second problem, I would like to do this analysis "offline", i.e., I don't want to wait for the whole file to play in real-time. So is there a way to read all samples from the file and send them to the UAna somehow ?

Third problem (yep ... that's a lot of problems), is that the correct way to perform a rms normalization (compute rms, then somehow compute an appropriate gain for normalizing the file) ? I didn't find any algorithm that I could copy ... any link would be really welcome !!!

Cheers !

Sébastien
Back to top
View user's profile Send private message
sebpiq



Joined: Apr 02, 2011
Posts: 4
Location: finland

PostPosted: Tue Aug 30, 2011 9:26 am    Post subject: Peak normalization Reply with quote  Mark this post and the followings unread

My samples being percussion samples, I chose a peak normalization, and it seems to work quite well. In case it interests someone, here is the code I came up with :

Code:

//Volume normalization functions

fun float find_peak(SndBuf buf) {
    0.0 => float max;
    for (0 => int i; i<buf.samples(); i++) {
        if (buf.valueAt(i) > max){
            buf.valueAt(i) => max;
        }
    }
    return max;
}

fun UGen peak_normalization (float level, SndBuf buf) {
    find_peak(buf) => float peak;
    buf => Gain g;
    level/peak => g.gain;
    return g;
}


// TESTS
// init
SndBuf b => dac;
"low_volume_beat.wav" => b.read;
SndBuf b2 => dac;
"loud_beat.wav" => b2.read;

<<< "before peak normalization" >>>;
0 => b.pos;
b2.samples() => b2.pos;
b.samples()::samp + 0.5::second => now;
0 => b2.pos;
b2.samples()::samp + 0.5::second => now;
0 => b.pos;
b.samples()::samp + 0.5::second => now;
0 => b2.pos;
b2.samples()::samp + 0.5::second => now;

<<< "after peak normalization" >>>;
2::second => now;
b =< dac;
b2 =< dac;
peak_normalization(1, b) => dac;
peak_normalization(1, b2) => dac;

0 => b.pos;
b.samples()::samp => now;
0 => b2.pos;
b2.samples()::samp => now;
0 => b.pos;
b.samples()::samp => now;
0 => b2.pos;
b2.samples()::samp => now;
2::second => now;


Cheers,

Sébastien
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Niio1

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use