Autor Beitrag
VampireSilence
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109
Erhaltene Danke: 5


C# (VS 2008 Express), PHP/MySQL, Windows XP
BeitragVerfasst: Sa 26.11.11 15:16 
Hallo Zusammen,

ich sitze gerade an einem DirectSound-Problem und zwar versuche ich mit folgendem Code einen Ton zu erzeugen:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
            // create device
            
            Microsoft.DirectX.DirectSound.Device m_device = new Microsoft.DirectX.DirectSound.Device();
            m_device.SetCooperativeLevel(this, DXS.CooperativeLevel.Priority);
            
            // create sample
            
            int SampleRate = 32;
            short BlockAlign = 32;
            int duration = 100;
            int frequency = 1500;
            
            int length = (int)(SampleRate * BlockAlign * duration);
        byte[] buffer = new byte[length];

        double A = frequency * 2 * Math.PI / (double)SampleRate;
        for (int i = 0; i < length; i++)
        {
             buffer[i] = (byte)(Math.Sin(i*A));
        }
        
        byte[] sample = buffer;

            // setup format

            DXS.WaveFormat format = new DXS.WaveFormat();
            format.BitsPerSample = 32000;
            format.Channels = 1;
            format.BlockAlign = 32;
            format.FormatTag = DXS.WaveFormatTag.Pcm;
            format.SamplesPerSecond = 32;
            format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;

            DXS.BufferDescription desc = new DXS.BufferDescription(format);
            desc.DeferLocation = true;
            desc.BufferBytes = sample.Length; 
            
            // secondary buffer
            
            DXS.SecondaryBuffer CurrentBuffer = new DXS.SecondaryBuffer(desc, m_device); // error
      CurrentBuffer.Write(0, sample, DXS.LockFlag.EntireBuffer);
      CurrentBuffer.Play(0, DXS.BufferPlayFlags.Default);

Aber bei // error bricht der Code ab, mit der Fehlermeldung
Zitat:
Der Wert liegt außerhalb des erwarteten Bereichs.
Es wird nur überhaupt nicht darauf eingegangen, welcher Wert denn nun erwartet wird. Könnt ihr mir da helfen ?

mfg
- VampireSilence
ujr
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 102
Erhaltene Danke: 12



BeitragVerfasst: Di 29.11.11 11:42 
Hallo,

32000 bits/sample?
32 samples/sek?

Hmmmm.