Hello,
I'm working on a sort of synthesizer project that combines four separate waves of given frequencies. Most of the audio work is done by borrowed code, and I'm not very clear on the methods used (beyond the raw math in the code). I've gotten it semi-working (it will play a tune), but the problems stem from the fact that I have no idea how to change the frequencies played dynamically. Basically, there is this big audio function I borrowed from a project called "AudioIOUnitOutput" that I found on the web somewhere. I've attached the relevant .h and .m files here. Now, I think the problem is this. As you can see at the beginning of Singer.m, I defined "fr1" as 500. The reason I'm doing this is because if I did not, the compiler would give me an error about fr1 not being declared (this makes sense, I suppose, given that if I didn't assign it a value it would be empty). However, even though this technically works (ie 500 hertz tones are played), I still get some warnings ("Data definition has no type or storage class", "Type defaults to 'int' in declaration of 'fr1'") and I still have no way to change the frequency before OR while the sound is played. This is because after the Singer instance is declared, it will never again re-check the value of "fr1". So theoretically, I could just release and then re-declare the Singer instance, but again this won't work because A)there's no way to declare fr1 before declaring the Singer instance and B)the way my code is set up, fr1 doesn't even exist outside of a Singer instance and I'n not even sure if the compiler will let me define it externally. However, even if that did work, I wouldn't do it because it takes WAY too long to declare an instance, which brings me to my next problem. For my purposes, I need the frequency to change seamlessly without a gap in the sound, many times a second. The frequency and volume will eventually be tied to some sliders in the main window.
So I'm sorry if my explanation was long-winded and confusing (which I think it was), but basically I just need a way to update the frequency, volume, etc without pausing the sound. I'd rather keep the existing basic method, as it does exactly what I want (combines multiple waves mathematically).
Also, in case it helps, here is my current method of activating the sound:
(to declare the Singer instance)
and then to update the sound,
Of course, as I said this doesn't work because
A)singer1 doesn't re-check the value of fr1 when you pause it
B)the stop and start functions cause a noticeable skip.
Any ideas on how to smoothly and dynamically change sound?
Thanks a ton,
Will
I'm working on a sort of synthesizer project that combines four separate waves of given frequencies. Most of the audio work is done by borrowed code, and I'm not very clear on the methods used (beyond the raw math in the code). I've gotten it semi-working (it will play a tune), but the problems stem from the fact that I have no idea how to change the frequencies played dynamically. Basically, there is this big audio function I borrowed from a project called "AudioIOUnitOutput" that I found on the web somewhere. I've attached the relevant .h and .m files here. Now, I think the problem is this. As you can see at the beginning of Singer.m, I defined "fr1" as 500. The reason I'm doing this is because if I did not, the compiler would give me an error about fr1 not being declared (this makes sense, I suppose, given that if I didn't assign it a value it would be empty). However, even though this technically works (ie 500 hertz tones are played), I still get some warnings ("Data definition has no type or storage class", "Type defaults to 'int' in declaration of 'fr1'") and I still have no way to change the frequency before OR while the sound is played. This is because after the Singer instance is declared, it will never again re-check the value of "fr1". So theoretically, I could just release and then re-declare the Singer instance, but again this won't work because A)there's no way to declare fr1 before declaring the Singer instance and B)the way my code is set up, fr1 doesn't even exist outside of a Singer instance and I'n not even sure if the compiler will let me define it externally. However, even if that did work, I wouldn't do it because it takes WAY too long to declare an instance, which brings me to my next problem. For my purposes, I need the frequency to change seamlessly without a gap in the sound, many times a second. The frequency and volume will eventually be tied to some sliders in the main window.
So I'm sorry if my explanation was long-winded and confusing (which I think it was), but basically I just need a way to update the frequency, volume, etc without pausing the sound. I'd rather keep the existing basic method, as it does exactly what I want (combines multiple waves mathematically).
Also, in case it helps, here is my current method of activating the sound:
Code:
- (void)viewDidLoad {
[super viewDidLoad];
singer1= [[Singer alloc] init];
[singer1 start];
}
and then to update the sound,
Code:
[singer1 stop];
singer1.fr1=value;//an int containing a value from around 0-400
LB1.text=[NSString stringWithFormat:@"%f", singer1.fr1];//to check frequency
[singer1 start];
A)singer1 doesn't re-check the value of fr1 when you pause it
B)the stop and start functions cause a noticeable skip.
Any ideas on how to smoothly and dynamically change sound?
Thanks a ton,
Will