Problem s Microsoft.DirectX.DirectSound v C#

Programovacie jazyky, rady, poradňa...
harrison314
Hardcore addict
Hardcore addict
Používateľov profilový obrázok
Príspevky: 8224
Registrovaný: 27 máj 2009, 20:42
Bydlisko: Bratislava
Kontaktovať používateľa:

Problem s Microsoft.DirectX.DirectSound v C#

Príspevok od používateľa harrison314 »

Chcem spracovavat signal z mikrofonu, nasiel som si na to DLL kniznice DirectX.dll a DirectX.DirectSound.dll,

potom som si k nim spravil triedu

Kód: Vybrať všetko

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.DirectX.DirectSound;

namespace zvuk
{
    class CaptureCis
    {
        protected static CaptureCis instancia = null;

        public static CaptureCis GetInstance() // vzor Singlton
        {
            if (instancia == null) instancia = new CaptureCis();
            return instancia;
        }

        const int Samples = 8;

        WaveFormat wfr;
        Capture cap;
        CaptureBufferDescription desc;
        CaptureBuffer buff;

        private CaptureCis()
        {
            this.wfr = new Microsoft.DirectX.DirectSound.WaveFormat();
            this.wfr.SamplesPerSecond = 95000;
            this.wfr.BitsPerSample = 16;
            this.wfr.Channels = 2;
            this.wfr.FormatTag = WaveFormatTag.Pcm;

            // toto je vzdy
            const int NUM_BUFERS=2;
            this.wfr.BlockAlign=(short) (this.wfr.Channels* (this.wfr.BitsPerSample/8));
            this.wfr.AverageBytesPerSecond = this.wfr.SamplesPerSecond * this.wfr.BlockAlign;

            // ale
            var CDC = new CaptureDevicesCollection();
            this.cap = new Capture(CDC[0].DriverGuid);
            this.desc = new Microsoft.DirectX.DirectSound.CaptureBufferDescription();
            this.desc.Format = this.wfr;
            this.desc.BufferBytes = Samples * this.wfr.BlockAlign;

            this.buff = new CaptureBuffer(this.desc, this.cap);
            this.buff.Start(true);
            
        }
        public void Stop()
        {
            if (this.buff.Capturing)
            {
                this.buff.Stop();
                this.buff.Dispose();
                this.buff = null;
            }
        }
        public int getValue()
        {
            int[] SAMPLE_FORMAT_ARRAY = { Samples, 2, 1 };
            Array pole =  this.buff.Read(0, typeof(Int16), LockFlag.FromWriteCursor, SAMPLE_FORMAT_ARRAY);
            int vzorkaL = 0;
            int vzorkaP = 0;
            for (int i = 0; i < Samples; i++)
            {
                vzorkaL += (Int16)pole.GetValue(i, 0, 0);
                vzorkaP += (Int16)pole.GetValue(i, 1, 0);
            }

            return (vzorkaL + vzorkaP) / (2*Samples);
        }

    }
}

chcem pomocou metody GetValue() ziskat aktualnu hodnotu na vstupe, ale vzdy ked sa ju pokusim spustit vyhodi mi vynimku

Kód: Vybrať všetko

DLL 'C:\Documents and Settings\-\My Documents\Visual Studio 2008\Projects\_WinSSH\zvuk\zvuk\bin\Debug\Microsoft.DirectX.DirectSound.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
Som s toho uz zufali, pozeral som nejake podobne veci na Codeproject.com aj na inych strankach ale neviem si stým rady.
bart11
Medium Expert
Medium Expert
Používateľov profilový obrázok
Príspevky: 91
Registrovaný: 13 okt 2006, 20:11
Kontaktovať používateľa:

Re: Problem s Microsoft.DirectX.DirectSound v C#

Príspevok od používateľa bart11 »

Vyskúšal som tvoj kód, ale "žiaľ" (kde sú chyby keď ich človek potrebuje?) mi štúdio nevyhodilo žiadnu hlášku. Hľadal som na nete a najviac som sa stretol s riešením, pri ktorom tú hlášku "vypínali":
Ponuka Debug->Exceptions (Ctrl+D,E)
stromová štruktúra Managed Debugging Assistants -> položka LoaderLock (nesmie byť zaškrtnuté!)
Teda ak si to už nespravil...

http://rtslink.blogspot.com/2009/03/att ... de-os.html
alebo
http://social.msdn.microsoft.com/forums ... 8291e6bf7/
proste celú hlášku hodiť do gúglu
dll is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang. c# a hľadaj.
harrison314
Hardcore addict
Hardcore addict
Používateľov profilový obrázok
Príspevky: 8224
Registrovaný: 27 máj 2009, 20:42
Bydlisko: Bratislava
Kontaktovať používateľa:

Re: Problem s Microsoft.DirectX.DirectSound v C#

Príspevok od používateľa harrison314 »

Diki uz to ako tak ide
Napísať odpoveď