# 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

    def __init__(self, mfpclock, chipimplclock, timer, fixedreg):
        super().__init__(BufType.signal)
        self.mfpclock = mfpclock
        self.chipimplclock = chipimplclock
        self.timer = timer
        self.fixedreg = fixedreg

    def callimpl(self):
        effect = self.timer.effect.value
        if effect is not self.effect:
            # Simulate running interrupt routine synchronously now (start of frame) and subsequently by interrupt:
            self.maincounter = 0
            self.precounterxmfp = None
            self.repeat, self.index = 0, -1 # Reset index in shape.
            self.effect = effect
        self.shape = effect.getshape(self.fixedreg)
        prescalerornone = self.timer.prescalerornone.value
        if prescalerornone is None:
            self.blockbuf.fill_same(self.shape.buf[self.index])
            self.precounterxmfp = None
        else:
            if self.precounterxmfp is None:
                self.precounterxmfp = prescalerornone * self.chipimplclock
            self.repeat, self.index, self.maincounter, self.precounterxmfp = self.rtoneimpl(prescalerornone, self.timer.effectivedata.value)
        self.timer.repeat.value = self.repeat

    @turbo(
        self = dict(
            oscnodepyrbotype,

# 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


    def __init__(self, mfpclock, chipimplclock, timer, fixedreg):
        super().__init__(BufType.signal)
        self.mfpclock = mfpclock
        self.chipimplclock = chipimplclock
        self.timer = timer
        self.fixedreg = fixedreg

    def callimpl(self):
        effect = self.timer.effect.value
        if effect is not self.effect:
            # Simulate running interrupt routine synchronously now (start of frame) and subsequently by interrupt:
            self.maincounter = 0
            self.precounterxmfp = None
            self.repeat, self.index = 0, -1 # Reset index in shape.
            self.effect = effect
        self.shape = effect.getshape(self.fixedreg)
        prescalerornone = self.timer.prescalerornone.value
        if prescalerornone is None:
            self.blockbuf.fill_same(self.shape.buf[self.index])
            self.precounterxmfp = None
        else:
            if self.precounterxmfp is None:
                self.precounterxmfp = prescalerornone * self.chipimplclock
            self.repeat, self.index, self.maincounter, self.precounterxmfp = self.rtoneimpl(prescalerornone, self.timer.effectivedata.value)
        self.timer.repeat.value = self.repeat

    @turbo(
        self = dict(
            oscnodepyrbotype,

            mfpclock = i8, # Signed so j doesn't blow up.