# Path: pym2149/buf.py
# class BufType:
# 
#     def __init__(self, _, dtype):
#         self.dtype = dtype
# 
#     def __call__(self):
#         return MasterBuf(self.dtype)
# 
# Path: pym2149/const.py

# 
# Path: pym2149/nod.py
# class BufNode(Node):
# 
#     def __init__(self, buftype, channels = 1):
#         super().__init__()
#         self.masterbuf = buftype()
#         self.channels = channels
#         self.realcallimpl = self.callimpl
#         self.callimpl = self.makeresult
# 
#     def makeresult(self):
#         self.blockbuf = self.masterbuf.ensureandcrop(self.block.framecount * self.channels)
#         resultornone = self.realcallimpl()
#         if resultornone is not None:
#             return resultornone
#         return self.blockbuf
# 
# Path: pym2149/shapes.py
# def level5toamp(level):
# def _amptolevel4(amp):
# def level4to5(level4):
#     def level4to5(cls, data4, introlen = defaultintrolen):
#     def __init__(self, g, introlen = defaultintrolen):
#     def wavelength(self):
# def _meansin(x1, x2):
# def _sinsliceamp(i, n, skew):
# def _sinuslevel4(steps, maxlevel4, skew):
# def makesample5shape(data, signed, is4bit):
# class Shape:


from .buf import BufType
from .const import i4, i8, u1, u4, u8
from .nod import BufNode
from .shapes import Shape, signaldtype, toneshape
from pyrbo import LOCAL, turbo
import itertools, numpy as np
        while True:
            numerator = nextstepxmfp + self_mfpclock - 1
            if numerator >= 0:
                j = min(numerator // self_mfpclock, self_block_framecount)
                val = self_shape_buf[self_index]
                while i < j:
                    self_blockbuf_buf[i] = val
                    i += 1
                if j == self_block_framecount:
                    break
            nextstepxmfp += stepsizexmfp
            self_index += 1
            if self_index == self_shape_size:
                self_repeat += 1
                self_index = self_shape_introlen
        nextstepxmfp -= self_mfpclock * self_block_framecount
        self_maincounter = 1
        while nextstepxmfp < 0:
            nextstepxmfp += chunksizexmfp
            self_maincounter -= 1
        self_maincounter += nextstepxmfp // chunksizexmfp
        return self_repeat, self_index, self_maincounter, nextstepxmfp % chunksizexmfp

class ToneOsc(ShapeOsc):

    eager = True

    def __init__(self, scale, periodreg):
        scaleofstep = scale * 2 // 2 # Normally half of 16.
        super().__init__(scaleofstep, periodreg)

# Path: pym2149/buf.py
# class BufType:
# 
#     def __init__(self, _, dtype):
#         self.dtype = dtype
# 
#     def __call__(self):
#         return MasterBuf(self.dtype)
# 
# Path: pym2149/const.py

# 
# Path: pym2149/nod.py
# class BufNode(Node):
# 
#     def __init__(self, buftype, channels = 1):
#         super().__init__()
#         self.masterbuf = buftype()
#         self.channels = channels
#         self.realcallimpl = self.callimpl
#         self.callimpl = self.makeresult
# 
#     def makeresult(self):
#         self.blockbuf = self.masterbuf.ensureandcrop(self.block.framecount * self.channels)
#         resultornone = self.realcallimpl()
#         if resultornone is not None:
#             return resultornone
#         return self.blockbuf
# 
# Path: pym2149/shapes.py
# def level5toamp(level):
# def _amptolevel4(amp):
# def level4to5(level4):
#     def level4to5(cls, data4, introlen = defaultintrolen):
#     def __init__(self, g, introlen = defaultintrolen):
#     def wavelength(self):
# def _meansin(x1, x2):
# def _sinsliceamp(i, n, skew):
# def _sinuslevel4(steps, maxlevel4, skew):
# def makesample5shape(data, signed, is4bit):
# class Shape:


# Path: pym2149/osc2.py
from .buf import BufType
from .const import i4, i8, u1, u4, u8
from .nod import BufNode
from .shapes import Shape, signaldtype, toneshape
from pyrbo import LOCAL, turbo
import itertools, numpy as np

        while True:
            numerator = nextstepxmfp + self_mfpclock - 1
            if numerator >= 0:
                j = min(numerator // self_mfpclock, self_block_framecount)
                val = self_shape_buf[self_index]
                while i < j:
                    self_blockbuf_buf[i] = val
                    i += 1
                if j == self_block_framecount:
                    break
            nextstepxmfp += stepsizexmfp
            self_index += 1
            if self_index == self_shape_size:
                self_repeat += 1
                self_index = self_shape_introlen
        nextstepxmfp -= self_mfpclock * self_block_framecount
        self_maincounter = 1
        while nextstepxmfp < 0:
            nextstepxmfp += chunksizexmfp
            self_maincounter -= 1
        self_maincounter += nextstepxmfp // chunksizexmfp
        return self_repeat, self_index, self_maincounter, nextstepxmfp % chunksizexmfp

class ToneOsc(ShapeOsc):

    eager = True

    def __init__(self, scale, periodreg):
        scaleofstep = scale * 2 // 2 # Normally half of 16.
        super().__init__(scaleofstep, periodreg)

        self.reset(toneshape)