Toon posts:

[C#] DirectSound

Pagina: 1
Acties:

Verwijderd

Topicstarter
Dag mensen, ik ben bezig om een programma te maken die geluid opneemt van de microphone ingang. Dit moet dan opgeslagen in wav / wma.

Wat ik op dit moment heb is het volgende, maar het gaat mis zodra ik gebruik maak van de DriverGuid.

Terwijl is wel de ingang in collDevices heb zitten.

C#:
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
public partial class frmAudioRecord : Form 
{ 
 
// ### Variables. 
private Device objDevice; 
private WaveFormat objWaveFormat; 
private Buffer objBuffer; 
private BufferDescription objBufferDescription; 
private Capture objCapture; 
private CaptureBuffer objCaptureBuffer; 
private CaptureBufferDescription objCaptureBufferDescription; 
private MemoryStream objMemoryStream; 
private byte[] objStreamBuffer; 
private Guid objGuidID; 
 
// ### Constructor. 
public frmAudioRecord() 
{ 
// ### Initialize component. 
InitializeComponent(); 
 
CaptureDevicesCollection collDevices = new CaptureDevicesCollection(); 
 
for (int i = 0; i < collDevices.Count; i++) 
{ 
if (collDevices[i].DriverGuid.ToString() != "") 
{ 
this.objGuidID = collDevices[i].DriverGuid; 
} 
} 
 
// ### Create a new device. 
try 
{ 
this.objDevice = new Device(collDevices[1].DriverGuid); 
} 
catch (DirectXException ex) 
{ 
MessageBox.Show(ex.ToString()); 
} 
 
// ### Wave format. 
this.objWaveFormat = new WaveFormat(); 
this.objWaveFormat.BitsPerSample = 8; 
this.objWaveFormat.BlockAlign = 1; 
this.objWaveFormat.Channels = 1; 
this.objWaveFormat.AverageBytesPerSecond = 20500; 
this.objWaveFormat.SamplesPerSecond = 20500; 
this.objWaveFormat.FormatTag = WaveFormatTag.Pcm; 
 
// ### Buffer description. 
this.objBufferDescription = new BufferDescription(); 
this.objBufferDescription.Format = this.objWaveFormat; 
this.objBufferDescription.BufferBytes = 100000; 
this.objBufferDescription.ControlPositionNotify = true; 
this.objBufferDescription.ControlFrequency = true; 
this.objBufferDescription.ControlPan = true; 
this.objBufferDescription.ControlVolume = true; 
 
// ### Create a new buffer. 
this.objBuffer = new Buffer(this.objBufferDescription, this.objDevice); 
 
// ### Set cooperative level. 
this.objDevice.SetCooperativeLevel(this, CooperativeLevel.Priority); 
 
// ### Create a new capture. 
this.objCapture = new Capture(); 
 
// ### Capture buffer description. 
this.objCaptureBufferDescription = new CaptureBufferDescription(); 
this.objCaptureBufferDescription.BufferBytes = 100000; 
this.objCaptureBufferDescription.Format = this.objWaveFormat; 
 
// ### Create capture buffer. 
this.objCaptureBuffer = new CaptureBuffer(this.objCaptureBufferDescription, this.objCapture); 
 
// ### Memory stream buffer. 
this.objStreamBuffer = new byte[100000]; 
for (int i = 0; i < 100000; i++) 
{ 
this.objStreamBuffer[i] = 0; 
} 
 
// ### Create memory stream. 
this.objMemoryStream = new MemoryStream(this.objStreamBuffer); 
} 
 
private void btnOpnemen_Click(object sender, EventArgs e) 
{ 
this.objCaptureBuffer.Start(true); 
} 
 
private void btnBeluisteren_Click(object sender, EventArgs e) 
{ 
this.objCaptureBuffer.Read(0, this.objMemoryStream, 100000, LockFlag.None); 
this.objBuffer.Write(0, this.objMemoryStream, (int)this.objMemoryStream.Length, LockFlag.EntireBuffer); 
this.objBuffer.Play(0, BufferPlayFlags.Looping); 
 
} 
 
private void Stoppen_Click(object sender, EventArgs e) 
{ 
this.objCaptureBuffer.Stop(); 
} 
}


Wat ik geprobeerd heb is eigenlijk dat ik dit script van het internet gehaald heb. Ik heb wel gespeeld met ide Guid maar krijg de volgende fout melding:

Afbeeldingslocatie: http://www.lucasheezen.nl/dump.gif

[ Voor 7% gewijzigd door Verwijderd op 23-04-2006 12:52 ]


  • Gerco
  • Registratie: Mei 2000
  • Laatst online: 20-02 03:31

Gerco

Professional Newbie

Allereerst, welkom op GoT :)

- Post je code tussen [norml]
C#:
1
[/] tags, dat is veel leesbaarder.
- Wat gaat er precies mis? Krijg je een foutmelding? Welke?
- Wat heb je al geprobeerd? Het heeft weinig zin als wij hier oplossingen gaan herhalen die je al geprobeerd hebt.

[ Voor 12% gewijzigd door Gerco op 23-04-2006 12:34 ]

- "Als ik zou willen dat je het begreep, legde ik het wel beter uit!" | All number systems are base 10!


  • H!GHGuY
  • Registratie: December 2002
  • Niet online

H!GHGuY

Try and take over the world...

waarom zoek je eerst een device op om dan toch een ander device te maken ?

ASSUME makes an ASS out of U and ME


  • st0p
  • Registratie: April 2004
  • Laatst online: 19-07-2024
als je niet meer dan één geluidskaart in je systeem hebt zitten, moet het dan niet

this.objDevice = new Device(collDevices[0].DriverGuid);

zijn? en ik sluit me aan by highguy, in het stuk ervoor ga je alle devices langs om vervolgens klakkeloos een device te pakken. op het eerste gezicht lijkt me dat weinig zinvol, dan kun je beter een dialog fixen dat de gevonden devices weergeeft zodat je er een kan kiezen.

Verwijderd

Topicstarter
Bedankt mensen,

Maar hoe geef ik dan aan dat ik het device van het systeem wil gebruiken?

  • H!GHGuY
  • Registratie: December 2002
  • Niet online

H!GHGuY

Try and take over the world...

DX heeft meestal een default device wat op index 0 terug te vinden is.

ASSUME makes an ASS out of U and ME

Pagina: 1