# Strange Fragments in Sine Synth

**URL:** <https://forum.juce.com/t/strange-fragments-in-sine-synth/32256>\
**Category:** Audio Plugins\
**Created:** [March 13, 2019, 5:42pm UTC](https://forum.juce.com/t/strange-fragments-in-sine-synth/32256 "2019-03-13T17:42:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stenh](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@stenh](https://forum.juce.com/u/stenh)\
**Post date:** [March 13, 2019, 5:42pm UTC](https://forum.juce.com/t/strange-fragments-in-sine-synth/32256/1 "2019-03-13T17:42:37Z")

</div>

Hey there!  
I just started programming with Juce and tried to create a simple sine synth as a AU. But i keep getting these strange fragments. [Link to a Audio Example](https://www.file-upload.net/download-13535690/tester.mp3.html) First i thought it might be some kind of imprecisely casting or something but i cant find a solution.  
Here is the algorithm in the processBlock:

```
auto* channelData = buffer.getWritePointer (0);
auto* channelData2 = buffer.getWritePointer (1);
for(int i = 0; i < buffer.getNumSamples(); i++) {
    auto currentSample = (float) std::sin(phase);
    phase += (synthPitch / getSampleRate()) * 2.0f * float_Pi;
    channelData[i] = (float) currentSample * synthVol;
    channelData2[i] = (float) currentSample * synthVol;
}
```

---

<div class="post-metadata">

**Author:** ![danielrudrich](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danielrudrich/32/3735_2.png) [@danielrudrich](https://forum.juce.com/u/danielrudrich)\
**Post date:** [March 13, 2019, 5:50pm UTC](https://forum.juce.com/t/strange-fragments-in-sine-synth/32256/2 "2019-03-13T17:50:27Z")

</div>

Take a look at the waveform of your audio-file. The phase is reseted every 1024 samples, which I guess was your buffersize. The phase of a synth is part of its internal state, which has to be persistent over all `processBlock` calls. Simply create a member variable called `phase` and you should be fine 🙂

---

<div class="post-metadata">

**Author:** ![stenh](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@stenh](https://forum.juce.com/u/stenh)\
**Post date:** [March 13, 2019, 8:09pm UTC](https://forum.juce.com/t/strange-fragments-in-sine-synth/32256/3 "2019-03-13T20:09:45Z")

</div>

Thank you for the quick answer! It worked like a charm.
