Example #1
0
        private void UploadTeensy_simple()
        {
            chapro.CHA_WDRC gha = new chapro.CHA_WDRC();
            gha.attack  = 1;
            gha.release = 50;
            gha.fs      = 24000;
            gha.maxdB   = 119;
            gha.tkgain  = 0;
            gha.tk      = 105;
            gha.cr      = 10;
            gha.bolt    = 105;

            string[] lines = new string[30];

            lines = GHA_Constants_base();

            // Populate DSL struct
            int    k;
            string str0;

            // attack time
            k        = 5;
            lines[k] = "  " + dsl.attack + ",  " + Modify_Line(lines[k]);

            // release time
            k        = 6;
            lines[k] = "  " + dsl.release + ",  " + Modify_Line(lines[k]);

            // TKgain
            k    = 13;
            str0 = "  {";
            for (int i = 0; i < 7; i++)
            {
                str0 = str0 + String.Format("{0:N1}f,  ", dsl.tkgain[i]);
            }
            str0     = str0 + String.Format("{0:N1}f", dsl.tkgain[7]) + "},   ";
            lines[k] = str0 + Modify_Line(lines[k]);

            // CR
            k    = 14;
            str0 = "  {";
            for (int i = 0; i < 7; i++)
            {
                str0 = str0 + String.Format("{0:N1}f,  ", dsl.cr[i]);
            }
            str0     = str0 + String.Format("{0:N1}f", dsl.cr[7]) + "},   ";
            lines[k] = str0 + Modify_Line(lines[k]);

            // TK
            k    = 15;
            str0 = "  {";
            for (int i = 0; i < 7; i++)
            {
                str0 = str0 + String.Format("{0:N1}f,  ", dsl.tk[i]);
            }
            str0     = str0 + String.Format("{0:N1}f", dsl.tk[7]) + "},   ";
            lines[k] = str0 + Modify_Line(lines[k]);

            // BOLT
            k    = 16;
            str0 = "  {";
            for (int i = 0; i < 7; i++)
            {
                str0 = str0 + String.Format("{0:N1}f,  ", dsl.bolt[i]);
            }
            str0     = str0 + String.Format("{0:N1}f", dsl.bolt[7]) + "},   ";
            lines[k] = str0 + Modify_Line(lines[k]);


            // Populate GHA struct
            // attack time
            k        = 21;
            lines[k] = String.Format("  {0:N1}f,  {1}", gha.attack, Modify_Line(lines[k]));

            // relase time
            k        = 22;
            lines[k] = String.Format("  {0:N1}f,  {1}", gha.release, Modify_Line(lines[k]));

            // fs
            //k = 23;
            //lines[k] = String.Format("  {0:N1}f,  {1}", gha.fs, Modify_Line(lines[k])).Replace(",","");

            // max dB
            k        = 24;
            lines[k] = String.Format("  {0:N1}f,  {1}", gha.maxdB, Modify_Line(lines[k]));



            // AFC Parameters
            // afc on/off
            k        = 35;
            lines[k] = String.Format("  {0},  {1}", afc, Modify_Line(lines[k]));

            // AFCFilterLength
            k        = 36;
            lines[k] = String.Format("  {0},  {1}", AFCFilterLength, Modify_Line(lines[k]));

            // esp
            k        = 37;
            lines[k] = String.Format("  {0},  {1}", eps, Modify_Line(lines[k]));

            // mu
            k        = 38;
            lines[k] = String.Format("  {0},  {1}", mu, Modify_Line(lines[k]));

            // rho
            k        = 39;
            lines[k] = String.Format("  {0},  {1}", rho, Modify_Line(lines[k]));

            // generate C code from prepared data
            string fn = WorkingDirectory + @"\GHA_Constants.h";

            try
            {
                System.IO.File.WriteAllLines(fn, lines);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            toolStripStatusLabel1.Text = "Wrote header file " + fn;
        }
Example #2
0
        public unsafe void UploadTeensy()
        {
            IntPtr[] cpi;
            cpi = new IntPtr[chapro.NPTR];

            int    nc = dsl.nchannel;
            double fs = 24000;
            //double atk = dsl.attack;
            //double rel = dsl.release;
            double atk, rel;

            float[] alfa_beta;
            int     nw = 128;
            int     wt = 0;

            //int cs = 128;


            chapro.CHA_WDRC gha = new chapro.CHA_WDRC();
            gha.attack  = 1;
            gha.release = 50;
            gha.fs      = 24000;
            gha.maxdB   = 119;
            gha.tkgain  = 0;
            gha.tk      = 105;
            gha.cr      = 10;
            gha.bolt    = 105;

            atk = gha.attack;
            rel = gha.release;

            alfa_beta = new float[2];
            alfa_beta = chapro.time_const(atk, rel, fs);


            chapro.CHA_IVAR[chapro._cs] = cs;
            chapro.CHA_IVAR[chapro._nw] = nw;
            chapro.CHA_IVAR[chapro._nc] = nc;

            /*
             * chapro.CHA_DVAR[chapro._alfa] = alfa_beta[0];
             * chapro.CHA_DVAR[chapro._beta] = alfa_beta[1];
             * chapro.CHA_DVAR[chapro._fs] = gha.fs;
             * chapro.CHA_DVAR[chapro._mxdb] = gha.maxdB;
             * chapro.CHA_DVAR[chapro._tkgn] = gha.tkgain;
             * chapro.CHA_DVAR[chapro._cr] = gha.cr;
             * chapro.CHA_DVAR[chapro._tk] = gha.tk;
             * chapro.CHA_DVAR[chapro._bolt] = gha.bolt;
             * chapro.CHA_DVAR[chapro._gcalfa] = alfa_beta[0];
             * chapro.CHA_DVAR[chapro._gcbeta] = alfa_beta[1];
             */

            double[] cf = dsl.cross_freq;

            try
            {
                fixed(void *cp = &cpi[0])
                {
                    // prepare FIRFB
                    chapro.cha_firfb_prepare(cp, cf, nc, fs, nw, wt, cs);

                    // prepare chunk buffers
                    chapro.cha_allocate(cp, nc * cs * 2, sizeof(float), 3);

                    // Initialize unmanged memory to hold the struct
                    //IntPtr dsl_pnt = Marshal.AllocHGlobal(Marshal.SizeOf(dsl));

                    // Copy dsl struct to unmanaged memory.
                    //Marshal.StructureToPtr(dsl, dsl_pnt, true);

                    // prepare AGC
                    //chapro.cha_agc_prepare(cp, ref dsl_pnt, ref gha);

                    //chapro.cha_allocate(cp, nc, sizeof(float), 8);
                    //chapro.cha_allocate(cp, nc, sizeof(float), 9);
                    //chapro.cha_allocate(cp, nc, sizeof(float), 10);
                    //chapro.cha_allocate(cp, nc, sizeof(float), 11);
                    //chapro.cha_allocate(cp, nc, sizeof(float), 12);

                    // generate C code from prepared data
                    //chapro.cha_data_gen(cp, "cha_ff_data_c.h");

                    // Free the unmanaged memory
                    //Marshal.FreeHGlobal(dsl_pnt);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // Initialize unmanged memory to hold the struct
            //IntPtr dsl_pnt = Marshal.AllocHGlobal(Marshal.SizeOf(dsl));

            // Copy dsl struct to unmanaged memory.
            //Marshal.StructureToPtr(dsl, dsl_pnt, true);

            // prepare AGC
            chapro.cha_agc_prepare(cpi, dsl, gha);

            // Free the unmanaged memory
            //Marshal.FreeHGlobal(dsl_pnt);


            // generate C code from prepared data
            string fn = @"C:\GenericHearingAid\cha_ff_data128.h";

            chapro.cha_data_gen(cpi, fn);

            // copy file to working directory for Arduino
            // string dst = @"C:\GenericHearingAid\" + fn;
            // File.Copy(fn,dst,true);

            Console.WriteLine("Inside UploadTeensy:");

            int *cpsiz;

            for (int i = 0; i < 15; i++)
            {
                cpsiz = (int *)cpi[0];
                System.Console.WriteLine("i = " + i + " : size = " + cpsiz[i]);
            }

            toolStripStatusLabel1.Text = "Wrote header file " + fn;
        }