Hi, i've been trying to combine a number of sine waves together for the past few days without any luck. No processes i've found on the internet seem to work for me.
I have code which creates different sine waves at different frequencies, but it always only plays the final frequency, so any pointers on what I should do with this code would be appreciated. -
for(int i = 0; i < file.getNumSamples(); i++)
-
{
-
wave = sin(PIX2 * i * (f/SR));
-
buffer[a] = wave * gain;
-
output = (buffer[a] + output)/2;
-
-
file.setSample(output, i);
-
}
9 2429
From what I know about signals and modulation from my amateur radio books when your sine waves have an additive effect on each other all you will have at the end is one complete wave form that modulates at (what seems like) random intervals but still retains the same amplitude. Were you expecting something different?
From what I know about signals and modulation from my amateur radio books when your sine waves have an additive effect on each other all you will have at the end is one complete wave form that modulates at (what seems like) random intervals but still retains the same amplitude. Were you expecting something different?
I did expect that to happen but i'm not getting that, all I would get at the end is a sine wave at say 320Hz.
The problem is that the sine waves don't seem to combine
-
for(int i = 0; i < file.getNumSamples(); i++)
-
{
-
wave = sin(PIX2 * i * (f/SR));
-
buffer[a] = wave * gain;
-
output = (buffer[a] + output)/2;
-
-
file.setSample(output, i);
-
}
I don't understand this piece of code: in the body of your loop you only calculate
several samples of one sine, i.e. care to elaborate on what 'a' is and what that
buffer is supposed to do there?
kind regards,
Jos
I don't understand this piece of code: in the body of your loop you only calculate
several samples of one sine, i.e. care to elaborate on what 'a' is and what that
buffer is supposed to do there?
kind regards,
Jos
'a' refers to an integer, which is declared previously as part of another while loop to allow the program to run through the above piece of code for each instance of a sine wave. The buffer is merely there to hold the samples before it is then added to 'output'.
Hope that helps
'a' refers to an integer, which is declared previously as part of another while loop to allow the program to run through the above piece of code for each instance of a sine wave. The buffer is merely there to hold the samples before it is then added to 'output'.
Hope that helps
'buffer[a]' is completely invariant to that loop, i.e. 'a' doesn't change in that
loop so you could've used a single variable 'buffer' (or whatever) for the purpose.
Also the entire loop body only depends on 'i' as I can see it; I think you have
to supply that outer loop too; from just this snippet I can't tell you any more.
kind regards,
Jos
'buffer[a]' is completely invariant to that loop, i.e. 'a' doesn't change in that
loop so you could've used a single variable 'buffer' (or whatever) for the purpose.
Also the entire loop body only depends on 'i' as I can see it; I think you have
to supply that outer loop too; from just this snippet I can't tell you any more.
kind regards,
Jos
Heres the whole part of the code, including both loops. -
int main()
-
{
-
//Create ne wav file
-
CWavFile file;
-
file.newWav(SR, 16, 1000, 1);
-
float f = 10; //frequency
-
float PIX2 = PI*2;
-
float wave;
-
float gain;
-
int g = 0;
-
float buffer[34]; //no. voices
-
-
for(int a = 0; a < 34; a++)
-
{
-
gain = 1;
-
-
for(int i = 0; i < file.getNumSamples(); i++)
-
{
-
wave = sin(PIX2 * i * (f/SR));
-
buffer[a] = wave * gain;
-
output = (buffer[a] + output)/2;
-
-
file.setSample(output, i);
-
}
-
-
g++;
-
gain = gain/g;
-
f = f + 10;
-
}
I hope that you can help
-
file.setSample(output, i);
Doesn't that line simply set sample # i with the value of 'output'? If so, the
behaviour can be exaplained: you set thousand values 34 times. The last
thousand values (samples) end up in the file if 'setSample' is defined the
way I just guessed.
Maybe you should define 34*1000 = 34000 samples and write sample
numbers 1000*a+i.
kind regards,
Jos
Doesn't that line simply set sample # i with the value of 'output'? If so, the
behaviour can be exaplained: you set thousand values 34 times. The last
thousand values (samples) end up in the file if 'setSample' is defined the
way I just guessed.
That is correct, although I thought that having the following line would keep adding the current value of the sine wave 'a' into output and it would build up until all 34 waves are together as one sound. - output = (buffer[a] + output)/2;
Maybe you should define 34*1000 = 34000 samples and write sample
numbers 1000*a+i.
kind regards,
Jos
This part I don't quite understand, the number of samples is 44100 a second, and at the moment it is a 10 second sine wave, and this can change.
That is correct, although I thought that having the following line would keep adding the current value of the sine wave 'a' into output and it would build up until all 34 waves are together as one sound. - output = (buffer[a] + output)/2;
No it doesn't work that way because the line above the line you just showed
you assigned the variable 'buffer[a]' a new value. More important is that you
haven't initialized the variable 'output' as far as I can see.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve |
last post by:
Is there a way to make style classes that are additive without the use
of additional elements?
..Header {
font-weight:bold;
}
..SubEntry {
padding-left:10px;
)
|
by: clemenr |
last post by:
Hi. Are there any python bindings for the Synthesis Toolkit?
http://ccrma.stanford.edu/software/stk/
I've done a quick search on the web but found nothing.
Cheers,
Ross-c
|
by: mark |
last post by:
Hello-
i am trying to make the function addbitwise more efficient. the code
below takes an array of binary numbers (of size 5) and performs
bitwise addition. it looks ugly and it is not elegant...
|
by: Xiangliang Meng |
last post by:
Hi, all.
As far as I know, the speical arithmetic operator on void pointer is an
externsion in GNU CC. However, I could not find the relative topics in C99.
Would someone like to help me find...
|
by: Nemok |
last post by:
Hi,
I am trying to write an additive encryption algorithm in C++ that will
encrypt a text by adding a random numer to each character in a string.
The code looks similar to this:
for(int...
|
by: paultawk |
last post by:
I have to write a c++ program for sound synthesis and rather complicated,i don't really know from where to start:
My program is to be used in robotics. It should read an input from an mp3 file. It...
|
by: Mangabasi |
last post by:
Howdy,
I would like to use the Synthesis Toolkit for a demo. I downloaded
the STK from http://ccrma.stanford.edu/software/stk/index.html. It
seems very powerful and user friendly. There are...
|
by: rsaharia |
last post by:
Hello All,
I need help with this particular .pl file I picked up from http://www.veritools-usa.com/xnf2vhdl.htm
What it's supposed to do is really convert an xnf file to a vhdl file. I need it for...
|
by: Joris van Lier |
last post by:
I'm looking to add Additive Styles to a CssStyleCollection, however the
Add(HtmlTextWriteStyle, String) method seems to replace styles (see example
below).
void Style(CssStyleCollection styles)
{...
|
by: Mesvak |
last post by:
Hi
Does anyone know the algorithm or have a source code for applying
Additive white gaussian noise?
thanx very much
-M-
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |