Exemplo n.º 1
0
 public WaveLineValues(WaveLine wl)
 {
     waveWidth     = wl.waveWidth;
     waveAmplitude = wl.waveAmplitude;
     waveFrequency = wl.waveFrequency;
     waveCount     = wl.waveCount;
 }
Exemplo n.º 2
0
 public void CopyToComponent(WaveLine wl)
 {
     wl.waveWidth     = waveWidth;
     wl.waveAmplitude = waveAmplitude;
     wl.waveFrequency = waveFrequency;
     wl.waveCount     = waveCount;
 }
    public void Generate()
    {
        // Number of samples = sample rate * channels * bytes per sample
        uint numSamples = format.dwSamplesPerSec * format.wChannels * 10;

        // Initialize the 16-bit array
        data.floatArray = new short[numSamples];

        //double t = (Math.PI * 2 * freq) / (format.dwSamplesPerSec * format.wChannels);
        int      lineIndex      = 0;
        WaveLine currentLine    = shape.lines[0];
        uint     nextLineSample = 0;
        uint     thisCycleStart = 0;

        for (uint i = 0; i < numSamples - 1; i += 2)
        {
            float  progress = (float)(i - thisCycleStart - currentLine.startSample) / (float)currentLine.sampleLength;
            Vector position = currentLine.startPoint + (currentLine.endPoint - currentLine.startPoint) * progress;
            //write position data to left and right channels
            data.floatArray[i]     = Convert.ToInt16(position.x * 50);
            data.floatArray[i + 1] = Convert.ToInt16(position.y * 50);

            if (i >= nextLineSample)
            {
                currentLine = shape.lines[lineIndex];
                if (lineIndex == 0)
                {
                    thisCycleStart = i;
                }
                lineIndex++;
                if (lineIndex == shape.lines.Length)
                {
                    lineIndex = 0;
                }

                nextLineSample = i + currentLine.sampleLength;
            }
        }

        // Calculate data chunk size in bytes
        data.dwChunkSize = (uint)(data.floatArray.Length * (format.wBitsPerSample / 8));
    }
    public void init()
    {
        float perimeter = 0;

        lines = new WaveLine[vertices.Length];

        Vector lastVertex;
        Vector nextVertex;

        for (int i = 0; i < vertices.Length; i++)
        {
            nextVertex = vertices[(i + 1) % (vertices.Length)];
            lastVertex = vertices[i];

            Console.WriteLine("measuring ({0}, {1}) to ({2}, {3})", lastVertex.x, lastVertex.y, nextVertex.x, nextVertex.y);

            WaveLine segment = new WaveLine(lastVertex, nextVertex);
            lines[i] = segment;

            perimeter += segment.realLength;
        }
        uint currentSample = 0;

        Console.WriteLine(samplesPerCycle);
        foreach (WaveLine segment in lines)
        {
            segment.relativeLength = segment.realLength / perimeter;
            Console.WriteLine("Relative Length: " + segment.relativeLength);
            segment.sampleLength = (uint)Math.Floor(segment.relativeLength * samplesPerCycle);
            segment.startSample  = currentSample;
            Console.WriteLine(segment.sampleLength + " starting from " + segment.startSample);
            segment.setUnitMovement();
            Console.WriteLine("line {0} unit movement is ({1}, {2})", 0, segment.unitMovement.x, segment.unitMovement.y);
            currentSample += segment.sampleLength;
        }
    }