Ejemplo n.º 1
0
 public unsafe void OnAudioStreamPacket(cef_browser_t *browser, [Immutable] float **data, int frames, long pts)
 {
     fixed(cef_audio_handler_t *self = &this)
     {
         ((delegate * unmanaged[Stdcall] < cef_audio_handler_t *, cef_browser_t *, float **, int, long, void >)on_audio_stream_packet)(self, browser, data, frames, pts);
     }
 }
 public unsafe static extern bool CalcModelPrediction(
     [In] IntPtr modelHandle,
     uint docCount,
     [In] float **floatFeatures, uint floatFeaturesSize,
     [In] IntPtr catFeatures, uint catFeaturesSize,
     [Out] double[] result, uint resultSize
     );
Ejemplo n.º 3
0
 public unsafe void process(double[] left, double[] right, int length)
 {
     if (left == null || right == null)
     {
         return;
     }
     //int length = Math.Min( left.Length, right.Length );
     try {
         initBuffer();
         int     remain     = length;
         int     offset     = 0;
         float * left_ch    = (float *)bufferLeft.ToPointer();
         float * right_ch   = (float *)bufferRight.ToPointer();
         float **out_buffer = (float **)buffers.ToPointer();
         out_buffer[0] = left_ch;
         out_buffer[1] = right_ch;
         while (remain > 0)
         {
             int proc = (remain > BUFLEN) ? BUFLEN : remain;
             aEffect.ProcessReplacing(IntPtr.Zero, new IntPtr(out_buffer), proc);
             for (int i = 0; i < proc; i++)
             {
                 left[i + offset]  = left_ch[i];
                 right[i + offset] = right_ch[i];
             }
             remain -= proc;
             offset += proc;
         }
     } catch (Exception ex) {
         serr.println("vstidrv#process; ex=" + ex);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 ///  Integrates the given external buffers for seamless use alongside any internal buffers.
 /// </summary>
 public int Attach(float *[] attachedBase, int sampleDelta)
 {
     if (channelCount < (channelCount = attachedBase.Length))              // if # of channels change, we need to recreate the array thats stores the references to their buffers
     {
         Marshal.FreeHGlobal((IntPtr)this.attachedBase);
         this.internalBase = (float *)Marshal.ReAllocHGlobal((IntPtr)this.internalBase, (IntPtr)(sizeof(float) * channelCount << capacityExponent));
         this.attachedBase = (float **)Marshal.AllocHGlobal(sizeof(float *) * channelCount);
     }
     for (int i = 0; i < channelCount; ++i)
     {
         this.attachedBase[i] = attachedBase[i];          // copies only the references to each channel's external buffer
     }
     if (sampleDelta >= 0 && sampleDelta < internalCount) // if the host wants to jump forwards in time to a point where samples are still in the queue
     {
         internalCount -= sampleDelta;                    // previous samples are 'forgotten'
         internalStart += sampleDelta;                    // & the queue advances forward
         if (internalStart >> capacityExponent != 0)
         {
             internalStart -= 1 << capacityExponent;
         }
     }
     else
     {
         internalStart = 0;
         internalCount = 0;
     }
     return(internalCount);
 }
Ejemplo n.º 5
0
        protected override void OnAudioStreamPacket(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr data, int noOfFrames, long pts)
        {
            /*
             * NOTE: data is an array representing the raw PCM data as a floating point type, i.e. 4-byte value(s)
             * Based on noOfFrames and the channels value passed to IAudioHandler.OnAudioStreamStarted
             * you can calculate the size of the data array in bytes.
             *
             * Audio data (PCM, 32-bit, float) will be save to rawAudioFile stream.
             */

            unsafe
            {
                float **channelData = (float **)data.ToPointer();
                int     size        = channelCount * noOfFrames * 4;
                byte[]  samples     = new byte[size];
                fixed(byte *pDestByte = samples)
                {
                    float *pDest = (float *)pDestByte;

                    for (int i = 0; i < noOfFrames; i++)
                    {
                        for (int c = 0; c < channelCount; c++)
                        {
                            *pDest++ = channelData[c][i];
                        }
                    }
                }

                rawAudioFile.Write(samples, 0, size);
            }
        }
Ejemplo n.º 6
0
        protected override void WriteOverride(float[,] data, int offset, int size)
        {
            unsafe
            {
                // data to encode
                // expose the buffer to submit data

                float **buffer = (float **)xm.vorbis_analysis_buffer(ref lls->vd, size);

                // uninterleave samples
                for (int channel = 0; channel < Channels; channel++)
                {
                    for (int i = 0; i < size; i++)
                    {
                        buffer[channel][i] = data[channel, i];
                    }
                }


                // tell the library how much we actually submitted
                xm.vorbis_analysis_wrote(ref lls->vd, size);

                /* vorbis does some data preanalysis, then divvies up blocks for
                 * more involved (potentially parallel) processing.  Get a single
                 * block for encoding now */
                while (xm.vorbis_analysis_blockout(ref lls->vd, ref lls->vb) == 1)
                {
                    /* analysis, assume we want to use bitrate management */
                    xm.vorbis_analysis(ref lls->vb, ref *(ogg_packet *)null);
                    xm.vorbis_bitrate_addblock(ref lls->vb);

                    while (xm.vorbis_bitrate_flushpacket(ref lls->vd, ref lls->op) != 0)
                    {
                        /* weld the packet into the bitstream */
                        xm.ogg_stream_packetin(ref lls->os, ref lls->op);

                        /* write out pages (if any) */
                        bool eos = false;
                        while (!eos)
                        {
                            int result = xm.ogg_stream_pageout(ref lls->os, ref lls->og);
                            if (result == 0)
                            {
                                break;
                            }
                            WritePage(ref lls->og, Stream);

                            /* this could be set above, but for illustrative purposes, I do
                             * it here (to show that vorbis does know where the stream ends) */

                            if (xm.ogg_page_eos(ref lls->og) != 0)
                            {
                                eos = true;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public unsafe void Process(int length, int nFx, float **fx, int nOut, float ** @out)
 {
     ThrowIfDisposed();
     if (LibFluidsynth.fluid_synth_process(Handle, length, nFx, fx, nOut, @out) != 0)
     {
         OnError("float sample write operation failed");
     }
 }
Ejemplo n.º 8
0
 private int PcmOut(ref float **pcm)
 {
     return(Vorbis.vorbis_synthesis_pcmout
            (
                ref vorbisDspState,
                ref pcm
            ));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Single**で初期化
        /// </summary>
        /// <param name="ptr"></param>
#else
        /// <summary>
        /// Initializes from Single**
        /// </summary>
        /// <param name="ptr"></param>
#endif
        public PointerAccessor2D_Single(float **ptr)
        {
            if (ptr == IntPtr.Zero.ToPointer())
            {
                throw new ArgumentNullException("ptr");
            }
            this.ptr = ptr;
        }
Ejemplo n.º 10
0
        private float fiL2FloatDist(float **u0, float **u1, int i0, int j0, int i1, int j1, int radius, int channels, int width0, int width1)
        {
            var dif = 0.0f;

            for (var ii = 0; ii < channels; ii++)
            {
                dif += this.fiL2FloatDist(u0[ii], u1[ii], i0, j0, i1, j1, radius, width0, width1);
            }

            return(dif);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Find a maximal matching in a graph using one of several algorithms.
        /// </summary>
        public static int maxmatch(vtx_data **graph,    /* array of vtx data for graph */
                                   int nvtxs,           /* number of vertices in graph */
                                   int nedges,          /* number of edges in graph */
                                   int *mflag,          /* flag indicating vtx selected or not */
                                   bool useEdgeWeights, /* are edge weights being used? */
                                   int igeom,           /* geometric dimensionality */
                                   float **coords       /* coordinates for each vertex */
                                   )
        {
            int nmerged = 0; /* number of matching edges found */

            if (MATCH_TYPE == MatchingRoutine.maxmatch1 || (MATCH_TYPE == MatchingRoutine.maxmatch5_geometric && coords == null))
            {
                /* Dumb, fast routine. */
                nmerged = maxmatch1(graph, nvtxs, mflag, useEdgeWeights);
            }

            else if (MATCH_TYPE == MatchingRoutine.maxmatch2)
            {
                /* More random but somewhat slower. */
                nmerged = maxmatch2(graph, nvtxs, mflag, useEdgeWeights);
            }

            else if (MATCH_TYPE == MatchingRoutine.maxmatch3)
            {
                /* Much more random but slower still. */
                nmerged = maxmatch3(graph, nvtxs, mflag, useEdgeWeights);
            }

            else if (MATCH_TYPE == MatchingRoutine.maxmatch4_Luby)
            {
                /* Truly random but very slow. */
                nmerged = maxmatch4(graph, nvtxs, nedges, mflag, useEdgeWeights);
            }
            else if (MATCH_TYPE == MatchingRoutine.maxmatch5_geometric && coords != null)
            {
                /* Geometric nearness. */
                nmerged = maxmatch5(graph, nvtxs, mflag, igeom, coords);
            }

            else if (MATCH_TYPE == MatchingRoutine.maxmatch9_minimumVertexDegree)
            {
                /* Minimum degree of merged vertex */
                nmerged = maxmatch9(graph, nvtxs, mflag, useEdgeWeights);
            }

            if (DEBUG_COARSEN)
            {
                Trace.WriteLine($"Number of matching edges = {nmerged:D}");
            }

            return(nmerged);
        }
Ejemplo n.º 12
0
        public static void coarsen1(vtx_data **graph,    /* array of vtx data for graph */
                                    int nvtxs,           /* number of vertices in graph */
                                    int nedges,          /* number of edges in graph */
                                    vtx_data ***pcgraph, /* coarsened version of graph */
                                    int *pcnvtxs,        /* number of vtxs in coarsened graph */
                                    int *pcnedges,       /* number of edges in coarsened graph */
                                    int **pv2cv,         /* pointer to v2cv */
                                    int igeom,           /* dimension for geometric information */
                                    float **coords,      /* coordinates for vertices */
                                    float **ccoords,     /* coordinates for coarsened vertices */
                                    bool useEdgeWeights  /* are edge weights being used? */
                                    )
        {
            double time;    /* time routine is entered */
            int *  v2cv;    /* maps from vtxs to cvtxs */
            int *  mflag;   /* flag indicating vtx matched or not */
            int    cnvtxs;  /* number of vtxs in coarse graph */
            int    nmerged; /* number of edges contracted */

            time = seconds();

            /* Allocate and initialize space. */
            v2cv  = (int *)Marshal.AllocHGlobal((nvtxs + 1) * sizeof(int));
            mflag = (int *)Marshal.AllocHGlobal((nvtxs + 1) * sizeof(int));

            /* Find a maximal matching in the graph. */
            nmerged     = maxmatch(graph, nvtxs, nedges, mflag, useEdgeWeights, igeom, coords);
            match_time += seconds() - time;

            /* Now construct coarser graph by contracting along matching edges. */
            /* Pairs of values in mflag array indicate matched vertices. */
            /* A zero value indicates that vertex is unmatched. */

            /*
             *  makecgraph(graph, nvtxs, pcgraph, pcnvtxs, pcnedges, mflag, *pv2cv, nmerged, useEdgeWeights, igeom, coords, ccoords);
             *  makecgraph2(graph, nvtxs, nedges, pcgraph, pcnvtxs, pcnedges, mflag, *pv2cv, nmerged, useEdgeWeights, igeom, coords, ccoords);
             */

            makev2cv(mflag, nvtxs, v2cv);

            Marshal.FreeHGlobal((IntPtr)mflag);

            cnvtxs = nvtxs - nmerged;
            makefgraph(graph, nvtxs, nedges, pcgraph, cnvtxs, pcnedges, v2cv, useEdgeWeights, igeom, coords,
                       ccoords);

            *pcnvtxs = cnvtxs;
            *pv2cv   = v2cv;
            coarsen_time += seconds() - time;
        }
Ejemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public float[,] GetFlSamples()
 {
     unsafe
     {
         int rows = SamplesNum, cols = DP;
         float[,] dst = new float[rows, cols];
         float **src = ((WCvConDensation *)ptr)->flSamples;
         using (var dstPtr = new ArrayAddress1 <float>(dst))
         {
             Util.CopyMemory(dstPtr, new IntPtr(src), rows * cols);
         }
         return(dst);
     }
 }
Ejemplo n.º 14
0
 public void Free()
 {
     MarshalExtension.Free(Rasterization);
     Rasterization = null;
     MarshalExtension.Free(FragmentColor);
     FragmentColor = null;
     if (FragmentData != null)
     {
         for (int i = 0; i < PixelCount; i++)
         {
             MarshalExtension.Free(FragmentData[i]);
         }
         MarshalExtension.Free(FragmentData);
         FragmentData = null;
     }
 }
Ejemplo n.º 15
0
        public DynamicBuffer(int channelCount, uint initialCapacity = 1)
        {
            #region Set Capacity to Next Power of Two

            if (initialCapacity > 1)
            {
                --initialCapacity;
                capacityExponent = 1;
                if (initialCapacity >> 16 == 0)
                {
                    capacityExponent += 16; initialCapacity <<= 16;
                }
                if (initialCapacity >> 24 == 0)
                {
                    capacityExponent += 8; initialCapacity <<= 8;
                }
                if (initialCapacity >> 28 == 0)
                {
                    capacityExponent += 4; initialCapacity <<= 4;
                }
                if (initialCapacity >> 30 == 0)
                {
                    capacityExponent += 2; initialCapacity <<= 2;
                }
                capacityExponent = (int)(initialCapacity >> 31) - capacityExponent + 32;
                if (capacityExponent > 31)
                {
                    capacityExponent = 31;
                }
                // initialCapacity= 1u << capacityExponent;
            }
            else
            {
                // initialCapacity= 1;
                capacityExponent = 0;
            }

            #endregion

            internalBase       = (float *)Marshal.AllocHGlobal(sizeof(float) * channelCount << capacityExponent);
            attachedBase       = (float **)Marshal.AllocHGlobal(sizeof(float *) * channelCount);
            this.channelCount  = channelCount;
            currentSampleIndex = 0;
            internalPosition   = null;
            internalStart      = 0;
            internalCount      = 0;
        }
Ejemplo n.º 16
0
        private bool Interleave(float **pcm, int channels, int sampleSize, ref byte[] result)
        {
            // lpppsz_pcm_buffer is a multichannel float vector. In stereo, for example, pcm[0] is left
            // pcm[1] is right. Samples is the size of each channel. Convert the float values
            // ( -1.0 <= range <= 1.0 ) to whatever PCM format and write it out
            int    blockSize  = sizeof(short) * sampleSize * channels;
            short *result_ptr = stackalloc short [blockSize];

            // Convert floats to 16 bit signed ints (host order) and interleave
            for (int channel = 0; channel < channels; channel++)
            {
                short *first       = result_ptr + channel;
                short *current     = first;
                float *pcm_channel = pcm[channel];

                for (int position = 0; position < sampleSize; position++)
                {
                    int value = (int)(pcm_channel[position] * 32768.0f);

                    // might as well guard against clipping.
                    if (value > 32767)
                    {
                        value = 32767;
                    }
                    if (value < -32768)
                    {
                        value = -32768;
                    }

                    *current = (short)value;
                    current += this.vorbisInfo.channels;
                }
            }

            // Copy to managed result array.
            result = new byte[blockSize];

            Marshal.Copy
            (
                (IntPtr)result_ptr,
                result, 0,
                result.Length
            );

            return(true);
        }
Ejemplo n.º 17
0
        public unsafe float *GetUnsafeBuffer32(int channelIndex)
        {
            if (_sampleSize != SymbolicSampleSizes.Sample32)
            {
                throw new InvalidOperationException("32 bit sample size is not supported.");
            }
            Guard.ThrowIfOutOfRange("channel", channelIndex, 0, _audioBuffers.NumChannels);

            if (_audioBuffers.ChannelBuffers32 != IntPtr.Zero &&
                !IsChannelSilent(channelIndex))
            {
                float **ptr = (float **)_audioBuffers.ChannelBuffers32.ToPointer();

                return(ptr[channelIndex]);
            }

            return(null);
        }
Ejemplo n.º 18
0
        private void AssemblePrimitve <T>(Model model, Vector2 *screenCoords, int startIndex, T *result) where T : unmanaged, IPrimitive
        {
            int      vertexCount   = result->VertexCount;
            Vector2 *coords        = Alloc <Vector2>(vertexCount);
            float ** primitiveData = (float **)Alloc <IntPtr>(vertexCount);
            int      index;

            for (int i = 0; i < vertexCount; i++)
            {
                index            = model.Indices[startIndex + i];
                coords[i]        = screenCoords[index];
                primitiveData[i] = AllocBytes <float>(FragmentInvoker.ActiveInputMap.InstanceSize);
                FragmentInvoker.ActiveInputMap.MoveFields(model.ReadVerticesDataAsPattern(index), (byte *)primitiveData[i]);
            }
            result->CoordsPtr         = coords;
            result->VerticesDataPtr   = primitiveData;
            result->VerticesDataCount = FragmentInvoker.ActiveInputMap.SizeInFloatCount;
        }
Ejemplo n.º 19
0
        public unsafe override void glGeometry(MDagPath shapePath,
                                               int glPrim,
                                               uint writeMask,
                                               int indexCount,
                                               uint *indexArray,
                                               int vertexCount,
                                               int *vertexIDs,
                                               float *vertexArray,
                                               int normalCount,
                                               float **normalArrays,
                                               int colorCount,
                                               float **colorArrays,
                                               int texCoordCount,
                                               float **texCoordArrays)
        {
            // converting from SWIG_p_xxx to the format gl needed.
            //
            OpenGL.glVertexPointer(3, OpenGL.GL_FLOAT, 0, vertexArray);

            if (boundTexture && texCoordCount > 0 && (texCoordArrays)[0] != (void *)0)
            {
                OpenGL.glEnableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);
                OpenGL.glTexCoordPointer(2, OpenGL.GL_FLOAT, 0, texCoordArrays[0]);
            }
            else
            {
                OpenGL.glDisableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);
            }

            if (lightingOn > 0 && normalCount > 0 && normalArrays[0][0] > 0)
            {
                // Don't route normals if we don't need them
                OpenGL.glEnableClientState(OpenGL.GL_NORMAL_ARRAY);
                OpenGL.glNormalPointer(OpenGL.GL_FLOAT, 0, normalArrays[0]);
            }
            else
            {
                OpenGL.glDisableClientState(OpenGL.GL_NORMAL_ARRAY);
            }

            OpenGL.glDrawElements((uint)glPrim, indexCount, OpenGL.GL_UNSIGNED_INT, indexArray);
            return;
        }
Ejemplo n.º 20
0
        public void Write(float[,] data, int offset, int count)
        {
            if (data.GetLength(0) != VorbisInfo.Channels)
            {
                throw new ArgumentException("Dimension of data does not match the number of channels");
            }

            unsafe
            {
                float **buffer = (float **)NativeMethods.vorbis_analysis_buffer(ref InternalStruct, count);
                for (int channel = 0; channel < data.GetLength(0); channel++)
                {
                    for (int i = 0; i < count; i++)
                    {
                        buffer[channel][i] = data[channel, i + offset];
                    }
                }
            }
            NativeMethods.vorbis_analysis_wrote(ref InternalStruct, count);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        public void SetFlSamples(float[,] value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            int rows = SamplesNum, cols = DP;

            if (value.GetLength(0) != rows || value.GetLength(1) != cols)
            {
                throw new ArgumentException();
            }

            unsafe
            {
                float[,] dst = new float[rows, cols];
                float **src = ((WCvConDensation *)ptr)->flSamples;
                using (var dstPtr = new ArrayAddress1 <float>(dst))
                {
                    Util.CopyMemory(new IntPtr(src), dstPtr, rows * cols);
                }
            }
        }
Ejemplo n.º 22
0
        public static bool flatten(vtx_data **graph,    /* array of vtx data for graph */
                                   int nvtxs,           /* number of vertices in graph */
                                   int nedges,          /* number of edges in graph */
                                   vtx_data ***pcgraph, /* coarsened version of graph */
                                   int *pcnvtxs,        /* number of vtxs in coarsened graph */
                                   int *pcnedges,       /* number of edges in coarsened graph */
                                   int **pv2cv,         /* pointer to v2cv */
                                   bool useEdgeWeights, /* are edge weights being used? */
                                   int igeom,           /* dimensions of geometric data */
                                   float **coords,      /* coordinates for vertices */
                                   float **ccoords      /* coordinates for coarsened vertices */
                                   )
        {
            double Thresh; /* minimal acceptable size reduction */
            int *  v2cv;   /* map from vtxs to coarse vtxs */
            int    cnvtxs; /* number of vertices in flattened graph */

            Thresh = .9;

            v2cv = (int *)Marshal.AllocHGlobal((nvtxs + 1) * sizeof(int));

            find_flat(graph, nvtxs, &cnvtxs, v2cv);

            if (cnvtxs <= Thresh * nvtxs) /* Sufficient shrinkage? */
            {
                makefgraph(graph, nvtxs, nedges, pcgraph, cnvtxs, pcnedges, v2cv, useEdgeWeights, igeom, coords,
                           ccoords);

                *pcnvtxs = cnvtxs;
                *pv2cv   = v2cv;
                return(true);
            }

            /* Not worth bothering */
            Marshal.FreeHGlobal((IntPtr)v2cv);
            return(false);
        }
 private static extern void LearnAll(int totalNumInstances, int *instSizes, int **instIndices,
                                     float **instValues, float *labels, bool tuneLR, ref float lr, float l2Const, float piw, float *weightVector, ref float bias,
                                     int numFeatres, int numPasses, int numThreads, bool tuneNumLocIter, ref int numLocIter, float tolerance, bool needShuffle, bool shouldInitialize,
                                     State *state, ChannelCallBack info);
Ejemplo n.º 24
0
 unsafe public void GetMatrixPointer(out int *pLength, out float **ppData)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 25
0
 public int SetOrientation([NativeTypeName("const SpatialAudioHrtfOrientation *")] float **orientation)
 {
     return(((delegate * unmanaged <ISpatialAudioObjectForHrtf *, float **, int>)(lpVtbl[9]))((ISpatialAudioObjectForHrtf *)Unsafe.AsPointer(ref this), orientation));
 }
Ejemplo n.º 26
0
 static extern bool snGetOutputNode(void *net, IntPtr name, snLSize *wsz, float **wData);
Ejemplo n.º 27
0
 unsafe public void GetMatrixPointer(out float **ValueP)
 {
     //TODO: not implemented
     ValueP = (float **)0;
 }
Ejemplo n.º 28
0
 unsafe public void GetMatrixPointer(out int *sliceCount, out float **ValueP)
 {
     //TODO: not implemented
     sliceCount = (int *)0;
     ValueP     = (float **)0;
 }
Ejemplo n.º 29
0
        void append_cor(float **a_data, uint length, double amp_left, double amp_right, bool is_last_mode)
        {
#if DEBUG
            cadencii.debug.push_log("append_cor *************************************************************");
            cadencii.debug.push_log("    length=" + length);
            cadencii.debug.push_log("    s_hwave_out=0x" + Convert.ToString(s_hwave_out.ToInt32(), 16));
#endif
            s_playing = true;
            int    jmax      = (int)length;
            int    remain    = 0;
            IntPtr ptr_data  = IntPtr.Zero;
            IntPtr ptr_data0 = IntPtr.Zero;
            IntPtr ptr_data1 = IntPtr.Zero;
            ptr_data = Marshal.AllocHGlobal(sizeof(float *) * 2);
            float **data = (float **)ptr_data.ToPointer();// new float*[2];
            bool    cleaning_required = false;
            if (s_error_samples > 0)
            {
                if (s_error_samples >= length)
                {
                    s_error_samples -= (int)length;
                    return;
                }
                cleaning_required = true;
                int actual_length = (int)length - s_error_samples;
#if DEBUG
                cadencii.debug.push_log("    actual_length=" + actual_length);
#endif
                ptr_data0 = Marshal.AllocHGlobal(sizeof(float) * actual_length);
                ptr_data1 = Marshal.AllocHGlobal(sizeof(float) * actual_length);
                data[0]   = (float *)ptr_data0.ToPointer();
                data[1]   = (float *)ptr_data1.ToPointer();
                for (int i = 0; i < actual_length; i++)
                {
                    data[0][i] = a_data[0][i + s_error_samples];
                    data[1][i] = a_data[1][i + s_error_samples];
                }
                s_error_samples = 0;
                length          = (uint)actual_length;
                jmax            = (int)length;
            }
            else
            {
                data = a_data;
            }

            if (length + s_buffer_loc >= s_block_size)
            {
                jmax   = s_block_size - s_buffer_loc;
                remain = (int)length - (int)jmax;
            }
            float aright = (float)amp_right;
            float aleft  = (float)amp_left;

            for (int j = 0; j < jmax; j++)
            {
                s_wave_buffer_l[j + s_buffer_loc] = data[1][j];
                s_wave_buffer_r[j + s_buffer_loc] = data[0][j];
            }
            s_buffer_loc += jmax;

            if (s_buffer_loc >= s_block_size)
            {
                // バッファー充填完了.バッファーを転送し、waveOutWriteが書き込めるタイミングまで待機
#if DEBUG
                cadencii.debug.push_log("append_cor; waiting(1) " + s_current_buffer + "...");
#endif
                while (true)
                {
                    if (s_abort_required)
                    {
                        s_abort_required = false;
                        goto clean_and_exit;
                    }
                    if (s_done[s_current_buffer])
                    {
                        break;
                    }
                }
#if DEBUG
                cadencii.debug.push_log("append_cor; ...exit");
#endif

                s_processed_count++;
                mix((int)s_processed_count, aleft, aright);

                if (s_processed_count == _NUM_BUF)
                {
                    s_done[0] = false;
#if DEBUG
                    cadencii.debug.push_log("calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString(s_hwave_out.ToInt32(), 16));
#endif
                    uint ret = win32.waveOutWrite(s_hwave_out, ref s_wave_header[0], (uint)sizeof(WAVEHDR));
#if DEBUG
                    cadencii.debug.push_log("...done; ret=" + ret);
#endif
#if DEBUG
                    cadencii.debug.push_log("(s_first_buffer_wirtten_callback==null)=" + (s_first_buffer_written_callback == null));
#endif
                    if (s_first_buffer_written_callback != null)
                    {
#if DEBUG
                        cadencii.debug.push_log("append_cor; calling s_first_buffer_written_callback");
#endif
                        s_first_buffer_written_callback();
                    }
                    for (int buffer_index = 1; buffer_index < _NUM_BUF; buffer_index++)
                    {
                        s_done[buffer_index] = false;
#if DEBUG
                        cadencii.debug.push_log("calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString(s_hwave_out.ToInt32(), 16));
#endif
                        uint ret2 = win32.waveOutWrite(s_hwave_out, ref s_wave_header[buffer_index], (uint)sizeof(WAVEHDR));
#if DEBUG
                        cadencii.debug.push_log("...done; ret2=" + ret2);
#endif
                    }
                    s_current_buffer = _NUM_BUF - 1;
                }
                else if (s_processed_count > _NUM_BUF)
                {
                    s_done[s_current_buffer] = false;
#if DEBUG
                    cadencii.debug.push_log("calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString(s_hwave_out.ToInt32(), 16));
#endif
                    uint ret3 = win32.waveOutWrite(s_hwave_out, ref s_wave_header[s_current_buffer], (uint)sizeof(WAVEHDR));
#if DEBUG
                    cadencii.debug.push_log("...done; ret3=" + ret3);
#endif
                }
                s_current_buffer++;
                if (s_current_buffer >= _NUM_BUF)
                {
                    s_current_buffer = 0;
                }

                s_buffer_loc = 0;
            }

            if (remain > 0)
            {
                for (int j = jmax; j < length; j++)
                {
                    s_wave_buffer_l[j - jmax] = data[1][j];
                    s_wave_buffer_r[j - jmax] = data[0][j];
                }
                if (is_last_mode)
                {
                    for (int j = (int)length - jmax; j < s_block_size; j++)
                    {
                        s_wave_buffer_l[j] = 0.0f;
                        s_wave_buffer_r[j] = 0.0f;
                    }
                }
                s_buffer_loc = remain;
            }

            if (is_last_mode)
            {
                if (s_processed_count < _NUM_BUF)
                {
                    // _NUM_BUFブロック分のデータを未だ全て受信していない場合。バッファが未だひとつも書き込まれていないので
                    // 0番のブロックから順に書き込む
                    s_processed_count++;
                    mix((int)s_processed_count, aleft, aright);
                    s_done[0] = false;
#if DEBUG
                    cadencii.debug.push_log("calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString(s_hwave_out.ToInt32(), 16));
#endif
                    uint ret35 = win32.waveOutWrite(s_hwave_out, ref s_wave_header[0], (uint)sizeof(WAVEHDR));
#if DEBUG
                    cadencii.debug.push_log("...done; ret35=" + ret35);
                    cadencii.debug.push_log("(s_first_buffer_written_callback==null)=" + (s_first_buffer_written_callback == null));
#endif
                    if (s_first_buffer_written_callback != null)
                    {
#if DEBUG
                        cadencii.debug.push_log("append_cor; calling s_first_buffer_written_callback");
#endif
                        s_first_buffer_written_callback();
                    }
                    for (int i = 1; i < _NUM_BUF - 1; i++)
                    {
                        s_processed_count++;
                        mix((int)s_processed_count, aleft, aright);
                        s_done[i] = false;
#if DEBUG
                        cadencii.debug.push_log("calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString(s_hwave_out.ToInt32(), 16));
#endif
                        uint ret36 = win32.waveOutWrite(s_hwave_out, ref s_wave_header[i], (uint)sizeof(WAVEHDR));
#if DEBUG
                        cadencii.debug.push_log("...done; ret36=" + ret36);
#endif
                    }
                }
                ulong zero = MAKELONG(0, 0);
                for (int j = s_buffer_loc; j < s_block_size; j++)
                {
                    s_wave_buffer_l[j] = 0.0f;
                    s_wave_buffer_r[j] = 0.0f;
                }
#if DEBUG
                cadencii.debug.push_log("append_cor; waiting(3) " + s_current_buffer + "...");
#endif
                while (!s_done[s_current_buffer])
                {
                    if (s_abort_required)
                    {
                        s_abort_required = false;
                        goto clean_and_exit;
                    }
                }
#if DEBUG
                cadencii.debug.push_log("append_cor; ...exit");
#endif
                s_processed_count++;
                mix((int)s_processed_count, aleft, aright);
                s_done[s_current_buffer] = false;
#if DEBUG
                cadencii.debug.push_log("calling waveOutWrite...; s_hawve_out=0x" + Convert.ToString(s_hwave_out.ToInt32(), 16));
#endif
                uint ret4 = win32.waveOutWrite(s_hwave_out, ref s_wave_header[s_current_buffer], (uint)sizeof(WAVEHDR));
#if DEBUG
                cadencii.debug.push_log("...done; ret4=" + ret4);
#endif
            }
clean_and_exit:
            if (is_last_mode)
            {
                s_last_buffer = s_current_buffer;
            }
            if (cleaning_required)
            {
                Marshal.FreeHGlobal(ptr_data0);  //delete [] data[0];
                Marshal.FreeHGlobal(ptr_data1);  //delete [] data[1];
                Marshal.FreeHGlobal(ptr_data);   //delete [] data;
            }
        }
Ejemplo n.º 30
0
 /// 波形データをバッファに追加する。バッファが再生中などの理由で即座に書き込めない場合、バッファが書き込み可能となるまで待機させられる
 public void append(float **data, uint length, double amp_left, double amp_right)
 {
     append_cor(data, length, amp_left, amp_right, false);
 }