sox-users@lists.sourceforge.net unofficial mirror
 help / color / Atom feed
* Updating synth.c with a Gaussian white noise effect?
@ 2018-10-06 15:44 James Trammell
  0 siblings, 0 replies; only message in thread
From: James Trammell @ 2018-10-06 15:44 UTC (permalink / raw)
  To: sox-users

[-- Attachment #1.1: Type: text/plain, Size: 1274 bytes --]

Hi,

I have tried to write my own SoX effect to generate Gaussian white noise as
an alternative to the uniform white noise that it generates currently. Even
though I have a copy of "Numerical Recipes in C", a fair amount of C
experience, and the internet at my disposal, I'm still stuck.

Would anyone mind looking at the code I have come up with so far, and
hopefully tell me where I am screwing up?

A patch file for synth.c is attached; patch your v14.4.2 synth.c file with
my changes using:

cd sox-14.4.2/src
patch -p1 <synth.diff

(If you would like me to send you my modified synth.c itself, let me know.)

I tried a number of ways to accomplish this; that is why there are so many
commented out blocks. The last block of code is where I left off.

The new effect is invoked like this:

sox -V -b 24 -r 96000 -n gaussianwhite.wav synth 60 gaussianwhitenoise
gaussianwhitenoise gain -12


Thanks,
James

case synth_gaussianwhitenoise: {
static double V1, V2, S;
static int phase = 0;
double X;
do {
if(phase == 0) {
do {
V1 = DRANQD1;
V2 = DRANQD1;
S = V1 * V1 + V2 * V2;
} while (S >= 1 || S == 0);
X = V1 * sqrt(-2 * log(S) / S);
} else {
X = V2 * sqrt(-2 * log(S) / S);
}
phase = 1 - phase;
} while (X < -1 || X > 1);
synth_out = X;
//printf("%lf\n", synth_out);
}

[-- Attachment #1.2: Type: text/html, Size: 3106 bytes --]

<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi,<br></div><div><br></div><div>I have tried to write my own SoX effect to generate Gaussian white noise as an alternative to the uniform white noise that it generates currently. Even though I have a copy of &quot;Numerical Recipes in C&quot;, a fair amount of C experience, and the internet at my disposal, I&#39;m still stuck.</div><div><br></div><div>Would anyone mind looking at the code I have come up with so far, and hopefully tell me where I am screwing up?</div><div><br></div><div>A patch file for synth.c is attached; patch your v14.4.2 synth.c file with my changes using:</div><div><br></div><div>cd sox-14.4.2/src</div><div>patch -p1 &lt;synth.diff</div><div><br></div><div>(If you would like me to send you my modified synth.c itself, let me know.)</div><div><br></div><div>I tried a number of ways to accomplish this; that is why there are so many commented out blocks. The last block of code is where I left off.</div><div><br></div><div>The new effect is invoked like this:</div><div><br></div><div>sox -V -b 24 -r 96000 -n gaussianwhite.wav synth 60 gaussianwhitenoise gaussianwhitenoise gain -12</div><div><br></div><div><br></div><div>Thanks,</div><div>James</div><div><br></div><div><div>case synth_gaussianwhitenoise: {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">	</span>static double V1, V2, S;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">	</span>static int phase = 0;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">	</span>double X;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">	</span>do {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">		</span>if(phase == 0) {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">			</span>do {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">				</span>V1 = DRANQD1;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">				</span>V2 = DRANQD1;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">				</span>S = V1 * V1 + V2 * V2;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">			</span>} while (S &gt;= 1 || S == 0);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">			</span>X = V1 * sqrt(-2 * log(S) / S);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">		</span>} else {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">			</span>X = V2 * sqrt(-2 * log(S) / S);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">		</span>}</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">		</span>phase = 1 - phase;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">	</span>} while (X &lt; -1 || X &gt; 1);</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">	</span>synth_out = X;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">	</span>//printf(&quot;%lf\n&quot;, synth_out);</div><div>}</div></div><div><br></div></div></div></div>

[-- Attachment #2: synth.diff --]
[-- Type: application/octet-stream, Size: 11320 bytes --]

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
Sox-users mailing list
Sox-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-06 15:44 Updating synth.c with a Gaussian white noise effect? James Trammell

sox-users@lists.sourceforge.net unofficial mirror

Archives are clonable: git clone --mirror https://public-inbox.org/sox-users

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.audio.sox
	nntp://ou63pmih66umazou.onion/inbox.comp.audio.sox
	nntp://news.gmane.org/gmane.comp.audio.sox

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox