The application I’m developing communicates with an digital audio device, which is capable of sending 24 different voice streams at the same time.
The device is connected via USB, using FTDI device (serial port emulator) and D2XX Drivers (basic COM driver is to slow to handle transfer of 4.5Mbit).
Basically the application consist of 3 threads:
The reason why I used file buffer is that I wanted to be sure that I won’t loose any samples. The application doesn’t use recording all the time, so I’ve chosen this solution because it was safe.
The application works fine, except that buffered wave file generator is pretty slow. For 24 parallel records of 1 minute, it takes about 4 minutes to complete the recording. I’m pretty sure that eliminating the use of hard drive in this process will increase the speed much.
The second problem is that the file buffer is really heavy for long records and I can’t clean this up
until the end of data processing (it would slow down the process even more).
For RAM buffer I need at lest 1GB to make it work properly.
What is the best way to allocate such a big amount of memory in .NET? I’m going to use this memory in 2 threads so a fast synchronization mechanism needed. I’m thinking about a cycle buffer: one big array, the Bus Reader saves the data, the Data Interpreter reads it. What do you think about it?
[edit]
Now for buffering I’m using classes BinaryReader and BinaryWriter based on a file.
You should be able to put together a wrapper class that manages a single byte[] buffer and parcels out temporary locks for data ranges using fixed-size memory streams. Essentially, you define your buffer once, and anytime you want to work with it, you request a lock object from the ConcurrentBuffer class. The lock contains a MemoryStream which is guaranteed to have exclusive access to the index ranges you specified when you requested the lock until you release it.
I’ve thrown together a simple example that should provide you with a good starting point: