Playback of 'recorded' sounds

174 views Asked by At

I'm building a fairly simple sampler in C#. I've got the basic sound structure down (sounds pitched, stopping sounds mid play, etc). But my problem arises when I try to record and play the sounds the user inputs. When recording, I save the sound into a dictionary with the starting time as the key (Class 'time' starts from 0), along with the length of the sound. When playing back the recorded sound, I'm currently using a timer to simulate time in the system. I set the timer interval to the time difference between the current sound and the next sounds every time I play a sound. It mostly starts out fine, but the sound usually goes completely out of sync, sounds are cut short or start too late, etc etc, I assume the problem is with my use of a timer, but I have no idea of another way of doing it. I'm using Bass.Net for the sounds.

1

There are 1 answers

0
Asik On

What timers are you using? Most timers in .NET would be too inaccurate for this task, you should look into P/Invoking Multimedia Timers (see this for example) or building your own using Stopwatch.