[ supercollider-Feature Requests-2020781 ] Buffer:normalize

View: New views
4 Messages — Rating Filter:   Alert me  

[ supercollider-Feature Requests-2020781 ] Buffer:normalize

by SourceForge.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Feature Requests item #2020781, was opened at 2008-07-17 16:42
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=474251&aid=2020781&group_id=54622

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Buffer:normalize

Initial Comment:
Add a command to normalise a buffer on the server

(from Eric Lyon)

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=474251&aid=2020781&group_id=54622

_______________________________________________
sc-dev mailing list

info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/

Re: [ supercollider-Feature Requests-2020781 ] Buffer:normalize

by stefan kersten-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 17.07.2008, at 18:42, SourceForge.net wrote:
> Add a command to normalise a buffer on the server

/b_gen sine1 1 0 ? untested ;)

<sk>


_______________________________________________
sc-dev mailing list

info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/

Re: [ supercollider-Feature Requests-2020781 ] Buffer:normalize

by Dan Stowell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Strangely, scsynth already has dedicated /b_gen commands for this:
"normalize" and also "wnormalize" for wavetable-style buffers. Anyone
recognise them? :) They seem to work fine, although sclang/SChelp know
nothing about them!

The attached patch exposes the command as Buffer:normalize to the
language, as well as allowing the user to specify their preferred new
peak value, and slightly optimising the code. Patch look OK? If so
will commit. (Oh and I suppose I should add them to the helpfile too)

Dan



Index: build/SCClassLibrary/Common/Control/Buffer.sc
===================================================================
--- build/SCClassLibrary/Common/Control/Buffer.sc (revision 7684)
+++ build/SCClassLibrary/Common/Control/Buffer.sc (working copy)
@@ -402,6 +402,13 @@
  ++ more;
  }
 
+ normalize { arg newmax=1;
+ server.listSendMsg(["/b_gen",bufnum,"normalize",newmax]);
+ }
+ normalizeMsg { arg newmax=1;
+ ^["/b_gen",bufnum,"normalize",newmax];
+ }
+
  gen { arg genCommand, genArgs,
normalize=true,asWavetable=true,clearFirst=true;
  server.listSendMsg(["/b_gen",bufnum,genCommand,
  normalize.binaryValue
Index: Source/plugins/OscUGens.cpp
===================================================================
--- Source/plugins/OscUGens.cpp (revision 7684)
+++ Source/plugins/OscUGens.cpp (working copy)
@@ -4090,12 +4090,12 @@

 void normalize_samples(int size, float* data, float peak)
 {
- float maxamp = 0.0;
+ float maxamp = 0.f;
  for (int i=0; i<size; ++i) {
  float absamp = fabs(data[i]);
  if (absamp > maxamp) maxamp = absamp;
  }
- if (maxamp > 0.0) {
+ if (maxamp != 0.f && maxamp != peak) {
  float ampfac = peak / maxamp;
  for (int i=0; i<size; ++i) {
  data[i] *= ampfac;
@@ -4105,12 +4105,12 @@

 void normalize_wsamples(int size, float* data, float peak)
 {
- float maxamp = 0.0;
+ float maxamp = 0.f;
  for (int i=0; i<size; i+=2) {
  float absamp = fabs(data[i] + data[i+1]);
  if (absamp > maxamp) maxamp = absamp;
  }
- if (maxamp > 0.0) {
+ if (maxamp != 0.f && maxamp != peak) {
  float ampfac = peak / maxamp;
  for (int i=0; i<size; ++i) {
  data[i] *= ampfac;
@@ -4310,17 +4310,29 @@
 }

 void NormalizeBuf(World *world, struct SndBuf *buf, struct sc_msg_iter *msg)
-{
+{
+ float newmax;
+ if(msg->remain() != 0){
+ newmax = msg->getf();
+ }else{
+ newmax = 1.f;
+ }
  float *data = buf->data;
  int size = buf->samples;
- normalize_samples(size, data, 1.);
+ normalize_samples(size, data, newmax);
 }

 void NormalizeWaveBuf(World *world, struct SndBuf *buf, struct
sc_msg_iter *msg)
 {
+ float newmax;
+ if(msg->remain() != 0){
+ newmax = msg->getf();
+ }else{
+ newmax = 1.f;
+ }
  float *data = buf->data;
  int size = buf->samples;
- normalize_wsamples(size, data, 1.);
+ normalize_wsamples(size, data, newmax);
 }

 void CopyBuf(World *world, struct SndBuf *buf, struct sc_msg_iter *msg)





2008/7/17 SourceForge.net <noreply@...>:

> Feature Requests item #2020781, was opened at 2008-07-17 16:42
> Summary: Buffer:normalize
>
> Initial Comment:
> Add a command to normalise a buffer on the server
>
> (from Eric Lyon)
>
> ----------------------------------------------------------------------
>
> You can respond by visiting:
> https://sourceforge.net/tracker/?func=detail&atid=474251&aid=2020781&group_id=54622

Index: build/SCClassLibrary/Common/Control/Buffer.sc
===================================================================
--- build/SCClassLibrary/Common/Control/Buffer.sc (revision 7684)
+++ build/SCClassLibrary/Common/Control/Buffer.sc (working copy)
@@ -402,6 +402,13 @@
  ++ more;
  }
 
+ normalize { arg newmax=1;
+ server.listSendMsg(["/b_gen",bufnum,"normalize",newmax]);
+ }
+ normalizeMsg { arg newmax=1;
+ ^["/b_gen",bufnum,"normalize",newmax];
+ }
+
  gen { arg genCommand, genArgs, normalize=true,asWavetable=true,clearFirst=true;
  server.listSendMsg(["/b_gen",bufnum,genCommand,
  normalize.binaryValue
Index: Source/plugins/OscUGens.cpp
===================================================================
--- Source/plugins/OscUGens.cpp (revision 7684)
+++ Source/plugins/OscUGens.cpp (working copy)
@@ -4090,12 +4090,12 @@
 
 void normalize_samples(int size, float* data, float peak)
 {
- float maxamp = 0.0;
+ float maxamp = 0.f;
  for (int i=0; i<size; ++i) {
  float absamp = fabs(data[i]);
  if (absamp > maxamp) maxamp = absamp;
  }
- if (maxamp > 0.0) {
+ if (maxamp != 0.f && maxamp != peak) {
  float ampfac = peak / maxamp;
  for (int i=0; i<size; ++i) {
  data[i] *= ampfac;
@@ -4105,12 +4105,12 @@
 
 void normalize_wsamples(int size, float* data, float peak)
 {
- float maxamp = 0.0;
+ float maxamp = 0.f;
  for (int i=0; i<size; i+=2) {
  float absamp = fabs(data[i] + data[i+1]);
  if (absamp > maxamp) maxamp = absamp;
  }
- if (maxamp > 0.0) {
+ if (maxamp != 0.f && maxamp != peak) {
  float ampfac = peak / maxamp;
  for (int i=0; i<size; ++i) {
  data[i] *= ampfac;
@@ -4310,17 +4310,29 @@
 }
 
 void NormalizeBuf(World *world, struct SndBuf *buf, struct sc_msg_iter *msg)
-{
+{
+ float newmax;
+ if(msg->remain() != 0){
+ newmax = msg->getf();
+ }else{
+ newmax = 1.f;
+ }
  float *data = buf->data;
  int size = buf->samples;
- normalize_samples(size, data, 1.);
+ normalize_samples(size, data, newmax);
 }
 
 void NormalizeWaveBuf(World *world, struct SndBuf *buf, struct sc_msg_iter *msg)
 {
+ float newmax;
+ if(msg->remain() != 0){
+ newmax = msg->getf();
+ }else{
+ newmax = 1.f;
+ }
  float *data = buf->data;
  int size = buf->samples;
- normalize_wsamples(size, data, 1.);
+ normalize_wsamples(size, data, newmax);
 }
 
 void CopyBuf(World *world, struct SndBuf *buf, struct sc_msg_iter *msg)

Re: [ supercollider-Feature Requests-2020781 ] Buffer:normalize

by Josh Parmenter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

looks good!

Josh

On Jul 17, 2008, at 1:31 PM, Dan Stowell wrote:

> Strangely, scsynth already has dedicated /b_gen commands for this:
> "normalize" and also "wnormalize" for wavetable-style buffers. Anyone
> recognise them? :) They seem to work fine, although sclang/SChelp know
> nothing about them!
>
> The attached patch exposes the command as Buffer:normalize to the
> language, as well as allowing the user to specify their preferred new
> peak value, and slightly optimising the code. Patch look OK? If so
> will commit. (Oh and I suppose I should add them to the helpfile too)
>
> Dan
>
>
>
> Index: build/SCClassLibrary/Common/Control/Buffer.sc
> ===================================================================
> --- build/SCClassLibrary/Common/Control/Buffer.sc (revision 7684)
> +++ build/SCClassLibrary/Common/Control/Buffer.sc (working copy)
> @@ -402,6 +402,13 @@
> ++ more;
> }
>
> + normalize { arg newmax=1;
> + server.listSendMsg(["/b_gen",bufnum,"normalize",newmax]);
> + }
> + normalizeMsg { arg newmax=1;
> + ^["/b_gen",bufnum,"normalize",newmax];
> + }
> +
> gen { arg genCommand, genArgs,
> normalize=true,asWavetable=true,clearFirst=true;
> server.listSendMsg(["/b_gen",bufnum,genCommand,
> normalize.binaryValue
> Index: Source/plugins/OscUGens.cpp
> ===================================================================
> --- Source/plugins/OscUGens.cpp (revision 7684)
> +++ Source/plugins/OscUGens.cpp (working copy)
> @@ -4090,12 +4090,12 @@
>
> void normalize_samples(int size, float* data, float peak)
> {
> - float maxamp = 0.0;
> + float maxamp = 0.f;
> for (int i=0; i<size; ++i) {
> float absamp = fabs(data[i]);
> if (absamp > maxamp) maxamp = absamp;
> }
> - if (maxamp > 0.0) {
> + if (maxamp != 0.f && maxamp != peak) {
> float ampfac = peak / maxamp;
> for (int i=0; i<size; ++i) {
> data[i] *= ampfac;
> @@ -4105,12 +4105,12 @@
>
> void normalize_wsamples(int size, float* data, float peak)
> {
> - float maxamp = 0.0;
> + float maxamp = 0.f;
> for (int i=0; i<size; i+=2) {
> float absamp = fabs(data[i] + data[i+1]);
> if (absamp > maxamp) maxamp = absamp;
> }
> - if (maxamp > 0.0) {
> + if (maxamp != 0.f && maxamp != peak) {
> float ampfac = peak / maxamp;
> for (int i=0; i<size; ++i) {
> data[i] *= ampfac;
> @@ -4310,17 +4310,29 @@
> }
>
> void NormalizeBuf(World *world, struct SndBuf *buf, struct  
> sc_msg_iter *msg)
> -{
> +{
> + float newmax;
> + if(msg->remain() != 0){
> + newmax = msg->getf();
> + }else{
> + newmax = 1.f;
> + }
> float *data = buf->data;
> int size = buf->samples;
> - normalize_samples(size, data, 1.);
> + normalize_samples(size, data, newmax);
> }
>
> void NormalizeWaveBuf(World *world, struct SndBuf *buf, struct
> sc_msg_iter *msg)
> {
> + float newmax;
> + if(msg->remain() != 0){
> + newmax = msg->getf();
> + }else{
> + newmax = 1.f;
> + }
> float *data = buf->data;
> int size = buf->samples;
> - normalize_wsamples(size, data, 1.);
> + normalize_wsamples(size, data, newmax);
> }
>
> void CopyBuf(World *world, struct SndBuf *buf, struct sc_msg_iter  
> *msg)
>
>
>
>
>
> 2008/7/17 SourceForge.net <noreply@...>:
>> Feature Requests item #2020781, was opened at 2008-07-17 16:42
>> Summary: Buffer:normalize
>>
>> Initial Comment:
>> Add a command to normalise a buffer on the server
>>
>> (from Eric Lyon)
>>
>> ----------------------------------------------------------------------
>>
>> You can respond by visiting:
>> https://sourceforge.net/tracker/?func=detail&atid=474251&aid=2020781&group_id=54622
> <BufferNormalize.patch.txt>

******************************************
/* Joshua D. Parmenter
http://www.realizedsound.net/josh/

“Every composer – at all times and in all cases – gives his own  
interpretation of how modern society is structured: whether actively  
or passively, consciously or unconsciously, he makes choices in this  
regard. He may be conservative or he may subject himself to continual  
renewal; or he may strive for a revolutionary, historical or social  
palingenesis." - Luigi Nono
*/


_______________________________________________
sc-dev mailing list

info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/
LightInTheBox - Buy quality products at wholesale price